소스 검색

Merge pull request #959 from seanyoung/cli

Make --generate-debug-info hidden
Sean Young 3 년 전
부모
커밋
a205f6d979
4개의 변경된 파일73개의 추가작업 그리고 55개의 파일을 삭제
  1. 21 35
      src/bin/solang.rs
  2. 2 0
      src/lib.rs
  3. 1 20
      src/sema/diagnostics.rs
  4. 49 0
      src/standard_json.rs

+ 21 - 35
src/bin/solang.rs

@@ -6,13 +6,13 @@ use clap::{
 };
 use itertools::Itertools;
 use num_traits::cast::ToPrimitive;
-use serde::Serialize;
 use solang::{
     abi,
     codegen::{codegen, OptimizationLevel, Options},
     emit::Generate,
     file_resolver::FileResolver,
-    sema::{ast::Namespace, diagnostics},
+    sema::ast::Namespace,
+    standard_json::{EwasmContract, JsonContract, JsonResult},
     Target,
 };
 use std::{
@@ -26,29 +26,6 @@ use std::{
 mod doc;
 mod languageserver;
 
-#[derive(Serialize)]
-pub struct EwasmContract {
-    pub wasm: String,
-}
-
-#[derive(Serialize)]
-pub struct JsonContract {
-    abi: Vec<abi::ethereum::ABI>,
-    #[serde(skip_serializing_if = "Option::is_none")]
-    ewasm: Option<EwasmContract>,
-    #[serde(skip_serializing_if = "Option::is_none")]
-    minimum_space: Option<u32>,
-}
-
-#[derive(Serialize)]
-pub struct JsonResult {
-    pub errors: Vec<diagnostics::OutputJson>,
-    pub target: String,
-    #[serde(skip_serializing_if = "String::is_empty")]
-    pub program: String,
-    pub contracts: HashMap<String, HashMap<String, JsonContract>>,
-}
-
 fn main() {
     let matches = Command::new("solang")
         .version(&*format!("version {}", env!("SOLANG_VERSION")))
@@ -138,6 +115,7 @@ fn main() {
                         .short('m')
                         .long("importmap")
                         .takes_value(true)
+                        .value_parser(ValueParser::new(parse_import_map))
                         .action(ArgAction::Append),
                 )
                 .arg(
@@ -186,7 +164,7 @@ fn main() {
                         .help("Enable generating debug information for LLVM IR")
                         .short('g')
                         .long("generate-debug-info")
-                        .display_order(5),
+                        .hidden(true),
                 ),
         )
         .subcommand(
@@ -238,6 +216,7 @@ fn main() {
                         .short('m')
                         .long("importmap")
                         .takes_value(true)
+                        .value_parser(ValueParser::new(parse_import_map))
                         .action(ArgAction::Append),
                 ),
         )
@@ -283,6 +262,7 @@ fn main() {
                         .short('m')
                         .long("importmap")
                         .takes_value(true)
+                        .value_parser(ValueParser::new(parse_import_map))
                         .action(ArgAction::Append),
                 ),
         )
@@ -878,15 +858,10 @@ fn imports_arg(matches: &ArgMatches) -> FileResolver {
         }
     }
 
-    if let Some(maps) = matches.get_many::<String>("IMPORTMAP") {
-        for p in maps {
-            if let Some((map, path)) = p.split_once('=') {
-                if let Err(e) = resolver.add_import_map(OsString::from(map), PathBuf::from(path)) {
-                    eprintln!("error: import path '{}': {}", path, e);
-                    std::process::exit(1);
-                }
-            } else {
-                eprintln!("error: import map '{}': contains no '='", p);
+    if let Some(maps) = matches.get_many::<(String, PathBuf)>("IMPORTMAP") {
+        for (map, path) in maps {
+            if let Err(e) = resolver.add_import_map(OsString::from(map), path.clone()) {
+                eprintln!("error: import path '{}': {}", path.display(), e);
                 std::process::exit(1);
             }
         }
@@ -894,3 +869,14 @@ fn imports_arg(matches: &ArgMatches) -> FileResolver {
 
     resolver
 }
+
+// Parse the import map argument. This takes the form
+/// --import-map openzeppelin=/opt/openzeppelin-contracts/contract,
+/// and returns the name of the map and the path.
+fn parse_import_map(map: &str) -> Result<(String, PathBuf), String> {
+    if let Some((var, value)) = map.split_once('=') {
+        Ok((var.to_owned(), PathBuf::from(value)))
+    } else {
+        Err("contains no '='".to_owned())
+    }
+}

+ 2 - 0
src/lib.rs

@@ -9,6 +9,8 @@ pub mod emit;
 pub mod file_resolver;
 #[cfg(feature = "llvm")]
 mod linker;
+pub mod standard_json;
+
 // In Sema, we use result unit for returning early
 // when code-misparses. The error will be added to the namespace diagnostics, no need to have anything but unit
 // as error.

+ 1 - 20
src/sema/diagnostics.rs

@@ -2,9 +2,9 @@
 
 use super::ast::{Diagnostic, ErrorType, Level, Namespace};
 use crate::file_resolver::FileResolver;
+use crate::standard_json::{LocJson, OutputJson};
 use codespan_reporting::{diagnostic, files, term};
 use itertools::Itertools;
-use serde::Serialize;
 use solang_parser::pt::Loc;
 use std::{
     collections::HashMap,
@@ -280,25 +280,6 @@ impl Namespace {
     }
 }
 
-#[derive(Serialize)]
-pub struct LocJson {
-    pub file: String,
-    pub start: usize,
-    pub end: usize,
-}
-
-#[derive(Serialize)]
-#[allow(non_snake_case)]
-pub struct OutputJson {
-    pub sourceLocation: Option<LocJson>,
-    #[serde(rename = "type")]
-    pub ty: String,
-    pub component: String,
-    pub severity: String,
-    pub message: String,
-    pub formattedMessage: String,
-}
-
 pub struct RawBuffer {
     buf: Vec<u8>,
 }

+ 49 - 0
src/standard_json.rs

@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: Apache-2.0
+
+//! This module defines the json format for `solang compile --standard-json`.
+
+use crate::abi::ethereum::ABI;
+use serde::Serialize;
+use std::collections::HashMap;
+
+#[derive(Serialize)]
+pub struct EwasmContract {
+    pub wasm: String,
+}
+
+#[derive(Serialize)]
+pub struct JsonContract {
+    pub abi: Vec<ABI>,
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub ewasm: Option<EwasmContract>,
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub minimum_space: Option<u32>,
+}
+
+#[derive(Serialize)]
+pub struct JsonResult {
+    pub errors: Vec<OutputJson>,
+    pub target: String,
+    #[serde(skip_serializing_if = "String::is_empty")]
+    pub program: String,
+    pub contracts: HashMap<String, HashMap<String, JsonContract>>,
+}
+
+#[derive(Serialize)]
+pub struct LocJson {
+    pub file: String,
+    pub start: usize,
+    pub end: usize,
+}
+
+#[derive(Serialize)]
+#[allow(non_snake_case)]
+pub struct OutputJson {
+    pub sourceLocation: Option<LocJson>,
+    #[serde(rename = "type")]
+    pub ty: String,
+    pub component: String,
+    pub severity: String,
+    pub message: String,
+    pub formattedMessage: String,
+}