瀏覽代碼

Output should not always go to working directory

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 6 年之前
父節點
當前提交
694476716d
共有 3 個文件被更改,包括 20 次插入7 次删除
  1. 2 2
      Dockerfile
  2. 17 4
      src/main.rs
  3. 1 1
      test/if.sol

+ 2 - 2
Dockerfile

@@ -24,6 +24,6 @@ RUN cargo build --release
 # Something more minimal than Fedora would be nice. Alphine won't work
 # since we built solang with glibc, not musl.
 FROM ubuntu:18.04
-COPY --from=builder /src/target/release/solang /usr/local/bin/solang
+COPY --from=builder /src/target/release/solang /usr/bin/solang
 
-ENTRYPOINT ["/usr/local/bin/solang"]
+ENTRYPOINT ["/usr/bin/solang"]

+ 17 - 4
src/main.rs

@@ -28,6 +28,7 @@ use serde::Serialize;
 use std::collections::HashMap;
 use std::fs::File;
 use std::io::prelude::*;
+use std::path::{Path, PathBuf};
 
 #[derive(Serialize)]
 pub struct EwasmContract {
@@ -93,6 +94,13 @@ fn main() {
                 .short("v")
                 .long("verbose"),
         )
+        .arg(
+            Arg::with_name("OUTPUT")
+                .help("output directory")
+                .short("o")
+                .long("output")
+                .takes_value(true),
+        )
         .get_matches();
 
     let mut fatal = false;
@@ -101,6 +109,11 @@ fn main() {
         contracts: HashMap::new(),
     };
 
+    let output_file = |stem: &str, ext: &str| -> PathBuf {
+        Path::new(matches.value_of("OUTPUT").unwrap_or("."))
+            .join(format!("{}.{}", stem, ext))
+    };
+
     for filename in matches.values_of("INPUT").unwrap() {
         let mut f = File::open(&filename).expect("file not found");
 
@@ -161,7 +174,7 @@ fn main() {
 
             if matches.is_present("LLVM-BC") {
                 let bc = contract.bitcode();
-                let bc_filename = contract.name.to_string() + ".bc";
+                let bc_filename = output_file(&contract.name, "bc");
 
                 let mut file = File::create(bc_filename).unwrap();
                 file.write_all(&bc).unwrap();
@@ -177,7 +190,7 @@ fn main() {
             };
 
             if matches.is_present("OBJECT") {
-                let obj_filename = contract.name.to_string() + ".o";
+                let obj_filename = output_file(&contract.name, "o");
 
                 let mut file = File::create(obj_filename).unwrap();
                 file.write_all(&obj).unwrap();
@@ -197,12 +210,12 @@ fn main() {
                     },
                 );
             } else {
-                let wasm_filename = contract.name.to_string() + ".wasm";
+                let wasm_filename = output_file(&contract.name, "wasm");
 
                 let mut file = File::create(wasm_filename).unwrap();
                 file.write_all(&wasm).unwrap();
 
-                let abi_filename = contract.name.to_string() + ".abi";
+                let abi_filename = output_file(&contract.name, "abi");
 
                 file = File::create(abi_filename).unwrap();
                 file.write_all(serde_json::to_string(&abi).unwrap().as_bytes())

+ 1 - 1
test/if.sol

@@ -1,6 +1,6 @@
 
 contract test3 {
-	function foo(uint32 a) returns (uint32) {
+	function foo(uint32 a) public returns (uint32) {
 		uint32 b = 50 - a;
 		uint32 c;
 		c = 100 * b;