From 230fcd70788cfd7406fb033b1b07a703baf2b03f Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 12 Feb 2022 12:49:53 +0100 Subject: [PATCH 1/2] feat(config): add offline args --- config/README.md | 1 + config/src/lib.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/config/README.md b/config/README.md index d07770977206..cbbcc53101c6 100644 --- a/config/README.md +++ b/config/README.md @@ -74,6 +74,7 @@ gas_reports = ['*'] ## Sets the concrete solc version to use, this overrides the `auto_detect_solc` value # solc_version = '0.8.10' auto_detect_solc = true +offline = false optimizer = true optimizer_runs = 200 verbosity = 0 diff --git a/config/src/lib.rs b/config/src/lib.rs index 72e42277778c..162194c57b24 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -101,6 +101,13 @@ pub struct Config { pub solc_version: Option, /// whether to autodetect the solc compiler version to use pub auto_detect_solc: bool, + /// Offline mode, if set, network access (downloading solc) is disallowed. + /// + /// Relationship with `auto_detect_solc`: + /// - if `auto_detect_solc = true` and `offline = true`, the required solc version(s) will + /// be auto detected but if the solc version is not installed, it will _not_ try to + /// install it + pub offline: bool, /// Whether to activate optimizer pub optimizer: bool, /// Sets the optimizer runs @@ -357,6 +364,7 @@ impl Config { .solc_config(SolcConfig::builder().settings(self.solc_settings()?).build()) .ignore_error_codes(self.ignored_error_codes.clone()) .set_auto_detect(self.auto_detect_solc) + .set_offline(self.offline) .set_cached(cached) .set_no_artifacts(no_artifacts) .build()?; @@ -704,6 +712,7 @@ impl Default for Config { gas_reports: vec!["*".to_string()], solc_version: None, auto_detect_solc: true, + offline: false, optimizer: true, optimizer_runs: 200, optimizer_details: None, From 89231c1cc219d6b678a20b2e03f2d4d38aa12ff1 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 12 Feb 2022 12:58:12 +0100 Subject: [PATCH 2/2] feat(forge): add --offline flag --- cli/src/cmd/build.rs | 11 +++++++++++ cli/src/cmd/flatten.rs | 1 + 2 files changed, 12 insertions(+) diff --git a/cli/src/cmd/build.rs b/cli/src/cmd/build.rs index 214a2051db07..d143992f2f87 100644 --- a/cli/src/cmd/build.rs +++ b/cli/src/cmd/build.rs @@ -124,6 +124,13 @@ pub struct BuildArgs { #[serde(skip)] pub no_auto_detect: bool, + #[clap( + help = "if set to true, runs without accessing the network (missing solc versions will not be installed)", + long + )] + #[serde(skip)] + pub offline: bool, + #[clap( help = "force recompilation of the project, deletes the cache and artifacts folders", long @@ -201,6 +208,10 @@ impl Provider for BuildArgs { dict.insert("auto_detect_solc".to_string(), false.into()); } + if self.offline { + dict.insert("offline".to_string(), true.into()); + } + if self.force { dict.insert("force".to_string(), self.force.into()); } diff --git a/cli/src/cmd/flatten.rs b/cli/src/cmd/flatten.rs index b586be332bbd..2b4afb8e3baf 100644 --- a/cli/src/cmd/flatten.rs +++ b/cli/src/cmd/flatten.rs @@ -75,6 +75,7 @@ impl Cmd for FlattenArgs { compiler: Default::default(), ignored_error_codes: vec![], no_auto_detect: false, + offline: false, force: false, hardhat, libraries: vec![],