~garritfra/antimony

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH antimony] Detect target from output filename

Details
Message ID
<20210226171557.9475-1-yyp@disroot.org>
DKIM signature
pass
Download raw message
Patch: +31 -4
When omitting -t option, sb will try to detect the target from output
filename, if it can't be detected, it will print a friendly message
asking to set it.

For backwards compatibility reasons, default target for run is always
JS.
---
 src/generator/mod.rs | 15 +++++++++++++++
 src/main.rs          | 20 ++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/generator/mod.rs b/src/generator/mod.rs
index 4cb22c4..dbcb7b5 100644
--- a/src/generator/mod.rs
+++ b/src/generator/mod.rs
@@ -14,6 +14,7 @@
 * limitations under the License.
 */
use crate::ast::*;
use std::path;
use std::str::FromStr;

pub mod c;
@@ -31,6 +32,20 @@ pub enum Target {
    LLVM,
}

impl Target {
    /// Constructs target based on provided output filename, returns
    /// None if target can't be detected
    pub fn from_extension(file: &path::Path) -> Option<Self> {
        let ext = file.extension()?;

        match &*ext.to_string_lossy() {
            "c" => Some(Self::C),
            "js" => Some(Self::JS),
            _ => None,
        }
    }
}

impl FromStr for Target {
    type Err = String;

diff --git a/src/main.rs b/src/main.rs
index 0f4fa22..70aad07 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,6 +21,7 @@ extern crate tempfile;

use generator::Target;
use std::path::PathBuf;
use std::process;
use structopt::StructOpt;

mod ast;
@@ -60,8 +61,8 @@ struct Opt {
    command: Command,

    /// Target language. Options: c, js, llvm
    #[structopt(long, short, default_value = "js", parse(try_from_str))]
    target: Target,
    #[structopt(long, short, parse(try_from_str))]
    target: Option<Target>,
}

fn main() -> Result<(), String> {
@@ -69,9 +70,20 @@ fn main() -> Result<(), String> {

    match opts.command {
        Command::Build { in_file, out_file } => {
            command::build::build(opts.target, &in_file, &out_file)?
            let target = match opts.target {
                Some(t) => t,
                None => Target::from_extension(&out_file).unwrap_or_else(|| {
                    println!(
                        "Cannot detect target from output file {}, use --target option to set it explicitly",
                        &out_file.to_string_lossy(),
                    );
                    process::exit(1);
                }),
            };

            command::build::build(target, &in_file, &out_file)?
        }
        Command::Run { in_file } => command::run::run(opts.target, in_file)?,
        Command::Run { in_file } => command::run::run(opts.target.unwrap_or(Target::JS), in_file)?,
    };

    Ok(())
-- 
2.30.1

[antimony/patches/ci.yml] build failed

builds.sr.ht
Details
Message ID
<C9JMTIC3QERB.XDF8L3XMV0PI@cirno2>
In-Reply-To
<20210226171557.9475-1-yyp@disroot.org> (view parent)
DKIM signature
missing
Download raw message
antimony/patches/ci.yml: FAILED in 28s

[Detect target from output filename][0] from [Alexey Yerin][1]

[0]: https://lists.sr.ht/~garritfra/antimony/patches/20619
[1]: mailto:yyp@disroot.org

✗ #440878 FAILED antimony/patches/ci.yml https://builds.sr.ht/~garritfra/job/440878
Reply to thread Export thread (mbox)