Skip to content

Commit

Permalink
fix: absolute path with vyper <0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 committed Jul 22, 2024
1 parent d3e9217 commit 29cd1ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::path::PathBuf;

use crate::vyper::combined_json::CombinedJson;
use crate::vyper::selection::Selection as VyperSelection;
use crate::vyper::Compiler as VyperCompiler;

use self::contract::Contract;

Expand Down Expand Up @@ -68,7 +69,28 @@ impl Build {
let contracts = self
.contracts
.into_iter()
.map(|(path, contract)| (path, contract.into_combined_json()))
.map(|(mut path, contract)| {
if version < Some(&VyperCompiler::FIRST_VERSION_ABSOLUTE_PATHS) {
let contract_path = PathBuf::from(path.as_str());
let current_directory = std::env::current_dir()
.map_err(|error| anyhow::anyhow!(error))
.and_then(|path| crate::path_to_posix(path.as_path()))
.and_then(|path| {
contract_path
.strip_prefix(path)
.map_err(|error| anyhow::anyhow!(error))
});

path = match current_directory {
Ok(path) => path,
Err(_error) => contract_path.as_path(),
}
.to_string_lossy()
.to_string();
}

(path, contract.into_combined_json())
})
.collect();

CombinedJson::new(contracts, version, zkvyper_version)
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![allow(non_camel_case_types)]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::assigning_clones)]

pub(crate) mod build;
pub(crate) mod r#const;
Expand Down
3 changes: 3 additions & 0 deletions src/vyper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ impl Compiler {
pub const FIRST_VERSION_ENABLE_DECIMALS_SUPPORT: semver::Version =
semver::Version::new(0, 4, 0);

/// The first version returning absolute paths.
pub const FIRST_VERSION_ABSOLUTE_PATHS: semver::Version = semver::Version::new(0, 4, 0);

///
/// A shortcut constructor.
///
Expand Down

0 comments on commit 29cd1ec

Please sign in to comment.