Преглед изворни кода

Require --target to be specified

It does not make sense to default to substrate, this would confuse
solana or ewasm users.

Signed-off-by: Sean Young <sean@mess.org>
Sean Young пре 4 година
родитељ
комит
df8b08d935

+ 1 - 0
CHANGELOG.md

@@ -11,6 +11,7 @@ will be documented here.
 ### Changed
 - On Solana, the return data is now provided in the program log. As a result,
   RPCs are now are now supported.
+- On the solang command line, the target must be specified.
 
 ### Removed
 - The Sawtooth Sabre target has been removed.

+ 2 - 2
docs/running.rst

@@ -29,8 +29,8 @@ Options:
   will be silent if there are no errors or warnings.
 
 \\-\\-target *target*
-  This takes one argument, which can either be ``solana``, ``substrate``, or ``ewasm``.
-  The default is substrate.
+  This takes one argument, which can either be ``solana``, ``substrate``, or ``ewasm``. The target
+  must be specified.
 
 \\-\\-doc
   Generate documentation for the given Solidity files as a single html page. This uses the

+ 9 - 9
src/bin/solang.rs

@@ -66,7 +66,7 @@ fn main() {
                 .long("target")
                 .takes_value(true)
                 .possible_values(&["solana", "substrate", "ewasm"])
-                .default_value("substrate"),
+                .required(true),
         )
         .arg(
             Arg::with_name("STD-JSON")
@@ -170,15 +170,15 @@ fn main() {
 
     let math_overflow_check = matches.is_present("MATHOVERFLOW");
 
-    let mut cache = FileResolver::new();
+    let mut resolver = FileResolver::new();
 
     for filename in matches.values_of("INPUT").unwrap() {
         if let Ok(path) = PathBuf::from(filename).canonicalize() {
-            let _ = cache.add_import_path(path.parent().unwrap().to_path_buf());
+            let _ = resolver.add_import_path(path.parent().unwrap().to_path_buf());
         }
     }
 
-    if let Err(e) = cache.add_import_path(PathBuf::from(".")) {
+    if let Err(e) = resolver.add_import_path(PathBuf::from(".")) {
         eprintln!(
             "error: cannot add current directory to import path: {}",
             e.to_string()
@@ -188,7 +188,7 @@ fn main() {
 
     if let Some(paths) = matches.values_of("IMPORTPATH") {
         for path in paths {
-            if let Err(e) = cache.add_import_path(PathBuf::from(path)) {
+            if let Err(e) = resolver.add_import_path(PathBuf::from(path)) {
                 eprintln!("error: import path ‘{}’: {}", path, e.to_string());
                 std::process::exit(1);
             }
@@ -198,7 +198,7 @@ fn main() {
     if let Some(maps) = matches.values_of("IMPORTMAP") {
         for p in maps {
             if let Some((map, path)) = p.split_once('=') {
-                if let Err(e) = cache.add_import_map(OsString::from(map), PathBuf::from(path)) {
+                if let Err(e) = resolver.add_import_map(OsString::from(map), PathBuf::from(path)) {
                     eprintln!("error: import path ‘{}’: {}", path, e.to_string());
                     std::process::exit(1);
                 }
@@ -215,9 +215,9 @@ fn main() {
         let mut files = Vec::new();
 
         for filename in matches.values_of("INPUT").unwrap() {
-            let ns = solang::parse_and_resolve(filename, &mut cache, target);
+            let ns = solang::parse_and_resolve(filename, &mut resolver, target);
 
-            diagnostics::print_messages(&cache, &ns, verbose);
+            diagnostics::print_messages(&resolver, &ns, verbose);
 
             if ns.contracts.is_empty() {
                 eprintln!("{}: error: no contracts found", filename);
@@ -256,7 +256,7 @@ fn main() {
         let mut errors = false;
 
         for filename in matches.values_of("INPUT").unwrap() {
-            match process_filename(filename, &mut cache, target, &matches, &mut json, &opt) {
+            match process_filename(filename, &mut resolver, target, &matches, &mut json, &opt) {
                 Ok(ns) => namespaces.push(ns),
                 Err(_) => {
                     errors = true;

+ 1 - 1
tests/codegen_testcases/const.sol

@@ -1,4 +1,4 @@
-// RUN: --emit cfg
+// RUN: --target substrate --emit cfg
 contract c {
 // BEGIN-CHECK: c::function::test
 	function test() public pure returns (int32) {

+ 1 - 1
tests/codegen_testcases/const_fail.sol

@@ -1,4 +1,4 @@
-// RUN: --emit cfg
+// RUN: --target substrate --emit cfg
 contract c {
 	function divide_zero() public pure returns (uint32) {
 		uint32 x = 2;

+ 1 - 1
tests/codegen_testcases/dead_storage.sol

@@ -1,4 +1,4 @@
-// RUN: --emit cfg
+// RUN: --target substrate --emit cfg
 contract deadstorage {
     int a;
 

+ 1 - 1
tests/codegen_testcases/dead_storage_off.sol

@@ -1,4 +1,4 @@
-// RUN: --no-dead-storage --emit cfg
+// RUN: --no-dead-storage --emit cfg --target substrate
 contract nodeadstorage {
     int a;
 

+ 1 - 1
tests/codegen_testcases/multiple.sol

@@ -1,4 +1,4 @@
-// RUN: --emit cfg
+// RUN: --target substrate --emit cfg
 contract c {
     event f(bool);
 

+ 1 - 1
tests/codegen_testcases/slice1.sol

@@ -1,4 +1,4 @@
-// RUN: --emit cfg
+// RUN: --target substrate --emit cfg
 contract c {
 // BEGIN-CHECK: c::function::test1
 	function test1() public pure{

+ 1 - 1
tests/codegen_testcases/strength_reduce.sol

@@ -1,4 +1,4 @@
-// RUN: --emit cfg
+// RUN: --target substrate --emit cfg
 contract test {
 /******************/
 /* Multiply tests */

+ 1 - 1
tests/codegen_testcases/temp1.sol

@@ -1,4 +1,4 @@
-// RUN: --emit cfg
+// RUN: --target substrate --emit cfg
 contract c {
 	function test() public pure returns (int32) {
 		int32 x = 104;

+ 1 - 1
tests/codegen_testcases/temp2.sol

@@ -1,4 +1,4 @@
-// RUN: --emit cfg
+// RUN: --target substrate --emit cfg
 contract c {
     event f(bool);
 

+ 8 - 8
tests/codegen_testcases/unused_variable_elimination.sol

@@ -1,4 +1,4 @@
-// RUN: --emit cfg
+// RUN: --target substrate --emit cfg
 
 contract c2 {
     int public cd;
@@ -10,7 +10,7 @@ contract c2 {
         cd=2;
 // CHECK: store storage slot(uint256 0) ty:int256 =
         return (1, 2);
-    } 
+    }
 }
 
 contract c {
@@ -114,8 +114,8 @@ return 3;
         it2 = 1;
 
         return 2;
-// CHECK: store storage slot((%t2 + uint256 0)) ty:int256 = 
-// CHECK: store storage slot(uint256 2) ty:int256 = 
+// CHECK: store storage slot((%t2 + uint256 0)) ty:int256 =
+// CHECK: store storage slot(uint256 2) ty:int256 =
 // NOT-CHECK: ty:struct c1.testStruct %t3 = struct { int256 1, int256 2 }
 // NOT-CHECK: alloc int256[] len uint32 5
 // NOT-CHECK: store storage slot(uint256 3) ty:int256
@@ -145,7 +145,7 @@ return 3;
         c2 ct = new c2();
         (int a, int b) = ct.doSomething();
 // CHECK: ty:int256 %b =
-// NOT-CHECK: ty:int256 %a = 
+// NOT-CHECK: ty:int256 %a =
         return b;
     }
 
@@ -156,7 +156,7 @@ return 3;
         int b = 2;
         (a, b) = ct.doSomething();
         // CHECK: ty:int256 %a =
-        // NOT-CHECK: ty:int256 %b = 
+        // NOT-CHECK: ty:int256 %b =
         return a;
     }
 
@@ -175,7 +175,7 @@ return 3;
 // BEGIN-CHECK: c3::function::test14
     function test14() public returns (int) {
         int[] storage ptrArr = testArr;
-        
+
 // CHECK: store storage slot(%temp.69) ty:int256 storage = int256 3
         ptrArr.push(3);
 
@@ -204,7 +204,7 @@ return 3;
         x = 5*vec.pop();
         return 0;
 // CHECK: pop array ty:int256[]
-    }  
+    }
 // BEGIN-CHECK: c3::function::test18
     function test18(address payable addr) public returns (bool) {
         bool p;

+ 20 - 4
tests/imports.rs

@@ -5,6 +5,8 @@ fn import_map_dup() {
     let mut cmd = Command::cargo_bin("solang").unwrap();
     let dup = cmd
         .args(&[
+            "--target",
+            "solana",
             "--importmap",
             "foo=tests",
             "--importmap",
@@ -29,7 +31,13 @@ fn import_map_dup() {
 fn import_map_badpath() {
     let mut cmd = Command::cargo_bin("solang").unwrap();
     let badpath = cmd
-        .args(&["--importmap", "foo=/does/not/exist", "bar.sol"])
+        .args(&[
+            "--target",
+            "solana",
+            "--importmap",
+            "foo=/does/not/exist",
+            "bar.sol",
+        ])
         .env("exit", "1")
         .assert();
 
@@ -45,7 +53,13 @@ fn import_map_badpath() {
 fn import_map() {
     let mut cmd = Command::cargo_bin("solang").unwrap();
     let assert = cmd
-        .args(&["--importmap", "foo=imports/", "import_map.sol"])
+        .args(&[
+            "--target",
+            "solana",
+            "--importmap",
+            "foo=imports/",
+            "import_map.sol",
+        ])
         .current_dir("tests/imports_testcases")
         .assert();
 
@@ -55,7 +69,7 @@ fn import_map() {
 
     let mut cmd = Command::cargo_bin("solang").unwrap();
     let badpath = cmd
-        .args(&["import_map.sol"])
+        .args(&["import_map.sol", "--target", "solana"])
         .current_dir("tests/imports_testcases")
         .assert();
 
@@ -72,6 +86,8 @@ fn import() {
     let mut cmd = Command::cargo_bin("solang").unwrap();
     let assert = cmd
         .args(&[
+            "--target",
+            "solana",
             "--importpath",
             "./imports_testcases/imports",
             "imports_testcases/import.sol",
@@ -85,7 +101,7 @@ fn import() {
 
     let mut cmd = Command::cargo_bin("solang").unwrap();
     let badpath = cmd
-        .args(&["import.sol"])
+        .args(&["--target", "solana", "import.sol"])
         .current_dir("tests/imports_testcases")
         .assert();
 

+ 1 - 1
vscode/package.json

@@ -29,7 +29,7 @@
 						"substrate",
 						"ewasm"
 					],
-					"default": "substrate",
+					"default": "solana",
 					"description": "Chain to build for. The Solidity language changes in subtle ways depending on the target."
 				},
 				"solang.updates.askBeforeDownload": {