Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] [Package System] Add option to override standard library version #13318

Merged
merged 12 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aptos-move/framework/src/aptos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl ReleaseTarget {
with_source_maps: false,
with_error_map: true,
named_addresses: Default::default(),
override_std: None,
install_dir: None,
with_docs: true,
docgen_options: Some(DocgenOptions {
Expand Down
11 changes: 10 additions & 1 deletion aptos-move/framework/src/built_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ use move_model::{
};
use move_package::{
compilation::{compiled_package::CompiledPackage, package_layout::CompiledPackageLayout},
source_package::manifest_parser::{parse_move_manifest_string, parse_source_manifest},
source_package::{
manifest_parser::{parse_move_manifest_string, parse_source_manifest},
std_lib::StdVersion,
},
BuildConfig, CompilerConfig, ModelConfig,
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -73,6 +76,9 @@ pub struct BuildOptions {
pub install_dir: Option<PathBuf>,
#[clap(skip)] // TODO: have a parser for this; there is one in the CLI buts its downstream
pub named_addresses: BTreeMap<String, AccountAddress>,
/// Whether to override the standard library with the given version.
#[clap(long, value_parser)]
pub override_std: Option<StdVersion>,
#[clap(skip)]
pub docgen_options: Option<DocgenOptions>,
#[clap(long)]
Expand Down Expand Up @@ -104,6 +110,7 @@ impl Default for BuildOptions {
with_docs: false,
install_dir: None,
named_addresses: Default::default(),
override_std: None,
docgen_options: None,
// This is false by default, because it could accidentally pull new dependencies
// while in a test (and cause some havoc)
Expand Down Expand Up @@ -147,6 +154,7 @@ pub fn build_model(
full_model_generation: false,
install_dir: None,
test_mode: false,
override_std: None,
force_recompilation: false,
fetch_deps_only: false,
skip_fetch_latest_git_deps: true,
Expand Down Expand Up @@ -190,6 +198,7 @@ impl BuiltPackage {
full_model_generation: options.check_test_code,
install_dir: options.install_dir.clone(),
test_mode: false,
override_std: options.override_std.clone(),
force_recompilation: false,
fetch_deps_only: false,
skip_fetch_latest_git_deps: options.skip_fetch_latest_git_deps,
Expand Down
6 changes: 6 additions & 0 deletions crates/aptos/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use move_core_types::{
account_address::AccountAddress, language_storage::TypeTag, vm_status::VMStatus,
};
use move_model::metadata::{CompilerVersion, LanguageVersion};
use move_package::source_package::std_lib::StdVersion;
use serde::{Deserialize, Serialize};
#[cfg(unix)]
use std::os::unix::fs::OpenOptionsExt;
Expand Down Expand Up @@ -1048,6 +1049,10 @@ pub struct MovePackageDir {
#[clap(long, value_parser = crate::common::utils::parse_map::<String, AccountAddressWrapper>, default_value = "")]
pub(crate) named_addresses: BTreeMap<String, AccountAddressWrapper>,

/// Override the standard library version by mainnet/testnet/devnet
#[clap(long, value_parser)]
pub override_std: Option<StdVersion>,

/// Skip pulling the latest git dependencies
///
/// If you don't have a network connection, the compiler may fail due
Expand Down Expand Up @@ -1088,6 +1093,7 @@ impl MovePackageDir {
package_dir: Some(package_dir),
output_dir: None,
named_addresses: Default::default(),
override_std: None,
skip_fetch_latest_git_deps: true,
bytecode_version: None,
compiler_version: None,
Expand Down
1 change: 1 addition & 0 deletions crates/aptos/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ impl CliCommand<()> for GenerateUpgradeProposal {
move_options.dev,
move_options.skip_fetch_latest_git_deps,
move_options.named_addresses(),
move_options.override_std,
move_options.bytecode_version,
move_options.compiler_version,
move_options.language_version,
Expand Down
17 changes: 16 additions & 1 deletion crates/aptos/src/move_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ use move_cli::{self, base::test::UnitTestResult};
use move_command_line_common::env::MOVE_HOME;
use move_core_types::{identifier::Identifier, language_storage::ModuleId, u256::U256};
use move_model::metadata::{CompilerVersion, LanguageVersion};
use move_package::{source_package::layout::SourcePackageLayout, BuildConfig, CompilerConfig};
use move_package::{
source_package::{layout::SourcePackageLayout, std_lib::StdVersion},
BuildConfig, CompilerConfig,
};
use move_unit_test::UnitTestingConfig;
pub use package_hooks::*;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -331,6 +334,7 @@ impl CliCommand<Vec<String>> for CompilePackage {
self.move_options.dev,
self.move_options.skip_fetch_latest_git_deps,
self.move_options.named_addresses(),
self.move_options.override_std.clone(),
self.move_options.bytecode_version,
self.move_options.compiler_version,
self.move_options.language_version,
Expand Down Expand Up @@ -394,6 +398,7 @@ impl CompileScript {
self.move_options.dev,
self.move_options.skip_fetch_latest_git_deps,
self.move_options.named_addresses(),
self.move_options.override_std.clone(),
self.move_options.bytecode_version,
self.move_options.compiler_version,
self.move_options.language_version,
Expand Down Expand Up @@ -611,6 +616,7 @@ impl CliCommand<&'static str> for DocumentPackage {
with_docs: true,
install_dir: None,
named_addresses: move_options.named_addresses(),
override_std: move_options.override_std.clone(),
docgen_options: Some(docgen_options),
skip_fetch_latest_git_deps: move_options.skip_fetch_latest_git_deps,
bytecode_version: move_options.bytecode_version,
Expand Down Expand Up @@ -682,6 +688,7 @@ impl TryInto<PackagePublicationData> for &PublishPackage {
self.move_options.dev,
self.move_options.skip_fetch_latest_git_deps,
self.move_options.named_addresses(),
self.move_options.override_std.clone(),
self.move_options.bytecode_version,
self.move_options.compiler_version,
self.move_options.language_version,
Expand Down Expand Up @@ -753,6 +760,7 @@ impl IncludedArtifacts {
dev: bool,
skip_fetch_latest_git_deps: bool,
named_addresses: BTreeMap<String, AccountAddress>,
override_std: Option<StdVersion>,
bytecode_version: Option<u32>,
compiler_version: Option<CompilerVersion>,
language_version: Option<LanguageVersion>,
Expand All @@ -769,6 +777,7 @@ impl IncludedArtifacts {
// Always enable error map bytecode injection
with_error_map: true,
named_addresses,
override_std,
skip_fetch_latest_git_deps,
bytecode_version,
compiler_version,
Expand All @@ -785,6 +794,7 @@ impl IncludedArtifacts {
with_source_maps: false,
with_error_map: true,
named_addresses,
override_std,
skip_fetch_latest_git_deps,
bytecode_version,
compiler_version,
Expand All @@ -801,6 +811,7 @@ impl IncludedArtifacts {
with_source_maps: true,
with_error_map: true,
named_addresses,
override_std,
skip_fetch_latest_git_deps,
bytecode_version,
compiler_version,
Expand Down Expand Up @@ -923,6 +934,7 @@ impl CliCommand<TransactionSummary> for CreateObjectAndPublishPackage {
self.move_options.dev,
self.move_options.skip_fetch_latest_git_deps,
self.move_options.named_addresses(),
self.move_options.override_std.clone(),
self.move_options.bytecode_version,
self.move_options.compiler_version,
self.move_options.language_version,
Expand Down Expand Up @@ -1000,6 +1012,7 @@ impl CliCommand<TransactionSummary> for UpgradeObjectPackage {
self.move_options.dev,
self.move_options.skip_fetch_latest_git_deps,
self.move_options.named_addresses(),
self.move_options.override_std.clone(),
self.move_options.bytecode_version,
self.move_options.compiler_version,
self.move_options.language_version,
Expand Down Expand Up @@ -1125,6 +1138,7 @@ impl CliCommand<TransactionSummary> for CreateResourceAccountAndPublishPackage {
move_options.dev,
move_options.skip_fetch_latest_git_deps,
move_options.named_addresses(),
move_options.override_std,
move_options.bytecode_version,
move_options.compiler_version,
move_options.language_version,
Expand Down Expand Up @@ -1277,6 +1291,7 @@ impl CliCommand<&'static str> for VerifyPackage {
self.move_options.dev,
self.move_options.skip_fetch_latest_git_deps,
self.move_options.named_addresses(),
self.move_options.override_std.clone(),
self.move_options.bytecode_version,
self.move_options.compiler_version,
self.move_options.language_version,
Expand Down
1 change: 1 addition & 0 deletions crates/aptos/src/move_tool/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl CliCommand<Vec<EntryABI>> for ShowAbi {
self.move_options.dev,
self.move_options.skip_fetch_latest_git_deps,
self.move_options.named_addresses(),
self.move_options.override_std.clone(),
self.move_options.bytecode_version,
self.move_options.compiler_version,
self.move_options.language_version,
Expand Down
1 change: 1 addition & 0 deletions crates/aptos/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,7 @@ impl CliTestFramework {
package_dir: Some(self.move_dir()),
output_dir: None,
named_addresses: Self::named_addresses(account_strs),
override_std: None,
skip_fetch_latest_git_deps: true,
bytecode_version: None,
compiler_version: None,
Expand Down
6 changes: 5 additions & 1 deletion third_party/move/tools/move-package/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use move_model::{
model,
};
use serde::{Deserialize, Serialize};
use source_package::layout::SourcePackageLayout;
use source_package::{layout::SourcePackageLayout, std_lib::StdVersion};
use std::{
collections::{BTreeMap, BTreeSet},
fmt,
Expand Down Expand Up @@ -109,6 +109,10 @@ pub struct BuildConfig {
#[clap(name = "test-mode", long = "test", global = true)]
pub test_mode: bool,

/// Whether to override the standard library with the given version.
#[clap(long = "override-std", global = true, value_parser)]
pub override_std: Option<StdVersion>,

/// Generate documentation for packages
#[clap(name = "generate-docs", long = "doc", global = true)]
pub generate_docs: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
Dependencies, Dependency, FileName, NamedAddress, PackageDigest, PackageName,
SourceManifest, SubstOrRename,
},
std_lib::{StdLib, StdVersion},
},
BuildConfig,
};
Expand Down Expand Up @@ -107,14 +108,22 @@ impl ResolvingGraph {
}
let mut resolution_graph = Self {
root_package_path: root_package_path.clone(),
build_options,
build_options: build_options.clone(),
root_package: root_package.clone(),
graph: DiGraphMap::new(),
package_table: BTreeMap::new(),
};

let override_std = &build_options.override_std;

resolution_graph
.build_resolution_graph(root_package.clone(), root_package_path, true, writer)
.build_resolution_graph(
root_package.clone(),
root_package_path,
true,
override_std,
writer,
)
.with_context(|| {
format!(
"Unable to resolve packages for package '{}'",
Expand Down Expand Up @@ -199,6 +208,7 @@ impl ResolvingGraph {
package: SourceManifest,
package_path: PathBuf,
is_root_package: bool,
override_std: &Option<StdVersion>,
writer: &mut W,
) -> Result<()> {
let package_name = package.package.name;
Expand Down Expand Up @@ -237,12 +247,17 @@ impl ResolvingGraph {
BTreeMap::new()
};

for (dep_name, dep) in package
for (dep_name, mut dep) in package
.dependencies
.clone()
.into_iter()
.chain(additional_deps.into_iter())
{
if let Some(std_version) = &override_std {
if let Some(std_lib) = StdLib::from_package_name(dep_name) {
dep = std_lib.dependency(std_version);
}
}
let dep_node_id = self.get_or_add_node(dep_name).with_context(|| {
format!(
"Cycle between packages {} and {} found",
Expand All @@ -252,7 +267,7 @@ impl ResolvingGraph {
self.graph.add_edge(package_node_id, dep_node_id, ());

let (dep_renaming, dep_resolution_table) = self
.process_dependency(dep_name, dep, package_path.clone(), writer)
.process_dependency(dep_name, dep, package_path.clone(), override_std, writer)
.with_context(|| {
format!(
"While resolving dependency '{}' in package '{}'",
Expand Down Expand Up @@ -393,6 +408,7 @@ impl ResolvingGraph {
dep_name_in_pkg: PackageName,
dep: Dependency,
root_path: PathBuf,
override_std: &Option<StdVersion>,
writer: &mut W,
) -> Result<(Renaming, ResolvingTable)> {
Self::download_and_update_if_remote(
Expand All @@ -404,10 +420,14 @@ impl ResolvingGraph {
let (dep_package, dep_package_dir) =
Self::parse_package_manifest(&dep, &dep_name_in_pkg, root_path)
.with_context(|| format!("While processing dependency '{}'", dep_name_in_pkg))?;
self.build_resolution_graph(dep_package.clone(), dep_package_dir, false, writer)
.with_context(|| {
format!("Unable to resolve package dependency '{}'", dep_name_in_pkg)
})?;
self.build_resolution_graph(
dep_package.clone(),
dep_package_dir,
false,
override_std,
writer,
)
.with_context(|| format!("Unable to resolve package dependency '{}'", dep_name_in_pkg))?;

if dep_name_in_pkg != dep_package.package.name {
bail!("Name of dependency declared in package '{}' does not match dependency's package name '{}'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ fn parse_dependency(dep_name: &str, tval: TV) -> Result<PM::Dependency> {
})
},
(None, Some(git), None) => {
let move_home = MOVE_HOME.clone();
let rev_name = match table.remove("rev") {
None => bail!("Git revision not supplied for dependency"),
Some(r) => Symbol::from(
Expand All @@ -367,11 +366,7 @@ fn parse_dependency(dep_name: &str, tval: TV) -> Result<PM::Dependency> {
let git_url = git
.as_str()
.ok_or_else(|| anyhow::anyhow!("Git URL not a string"))?;
let local_path = PathBuf::from(move_home).join(format!(
"{}_{}",
url_to_file_name(git_url),
rev_name.replace('/', "__")
));
let local_path = git_repo_cache_path(git_url, rev_name.as_str());
let subdir = PathBuf::from(match table.remove("subdir") {
None => "".to_string(),
Some(path) => path
Expand Down Expand Up @@ -571,3 +566,13 @@ fn check_for_required_field_names(

Ok(())
}

/// Gets the local path to download the package from a git repo
pub fn git_repo_cache_path(git_url: &str, rev_name: &str) -> PathBuf {
let move_home = MOVE_HOME.clone();
PathBuf::from(move_home).join(format!(
"{}_{}",
url_to_file_name(git_url),
rev_name.replace('/', "__")
))
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
pub mod layout;
pub mod manifest_parser;
pub mod parsed_manifest;
pub mod std_lib;
Loading
Loading