-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
move: build writes toolchain version to Move.lock #15166
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,12 +145,23 @@ impl BuildConfig { | |
let print_diags_to_stderr = self.print_diags_to_stderr; | ||
let run_bytecode_verifier = self.run_bytecode_verifier; | ||
let resolution_graph = self.resolution_graph(&path)?; | ||
build_from_resolution_graph( | ||
path, | ||
let result = build_from_resolution_graph( | ||
path.clone(), | ||
resolution_graph, | ||
run_bytecode_verifier, | ||
print_diags_to_stderr, | ||
) | ||
); | ||
if let Ok(ref compiled) = result { | ||
compiled | ||
.package | ||
.compiled_package_info | ||
.build_flags | ||
.update_lock_file_toolchain_version(&path, env!("CARGO_PKG_VERSION").into()) | ||
.map_err(|e| SuiError::ModuleBuildFailure { | ||
error: format!("Failed to update Move.lock toolchain version: {e}"), | ||
})?; | ||
} | ||
Comment on lines
+154
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Main change. This is the best place to write lock file logic right now. It is the top level function for source verification and should have all the context we care about before building. I say "right now" because I'd love to flatten things and have these build steps happen in the external-crates move-package, in one place, which we can do at a later stage. |
||
result | ||
} | ||
|
||
pub fn resolution_graph(mut self, path: &Path) -> SuiResult<ResolvedGraph> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,7 @@ impl BuildConfig { | |
let lock_string = std::fs::read_to_string(path.join(SourcePackageLayout::Lock.path())).ok(); | ||
let _mutx = PackageLock::lock(); // held until function returns | ||
|
||
let install_dir_set = self.install_dir.is_some(); | ||
let install_dir = self.install_dir.as_ref().unwrap_or(&path).to_owned(); | ||
|
||
let mut dep_graph_builder = DependencyGraphBuilder::new( | ||
|
@@ -190,7 +191,9 @@ impl BuildConfig { | |
lock_string, | ||
)?; | ||
|
||
if modified { | ||
if modified || install_dir_set { | ||
// (1) Write the Move.lock file if the existing one is `modified`, or | ||
// (2) `install_dir` is set explicitly, which may be a different directory, and where a Move.lock does not exist yet. | ||
Comment on lines
+194
to
+196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This addresses what I consider a bug: this block writes We should be writing to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reasonable! We should arguably be also looking in the install dir for the lock file that |
||
let lock = dependency_graph.write_to_lock(install_dir)?; | ||
if let Some(lock_path) = &self.lock_file { | ||
lock.commit(lock_path)?; | ||
|
@@ -222,14 +225,15 @@ impl BuildConfig { | |
.set_silence_warnings(self.silence_warnings) | ||
} | ||
|
||
pub fn update_lock_file_toolchain_version(&self, compiler_version: String) -> Result<()> { | ||
pub fn update_lock_file_toolchain_version( | ||
&self, | ||
path: &PathBuf, | ||
compiler_version: String, | ||
) -> Result<()> { | ||
let Some(lock_file) = self.lock_file.as_ref() else { | ||
return Ok(()); | ||
}; | ||
let install_dir = self | ||
.install_dir | ||
.clone() | ||
.unwrap_or_else(|| PathBuf::from(".")); | ||
let install_dir = self.install_dir.as_ref().unwrap_or(path).to_owned(); | ||
let mut lock = LockFile::from(install_dir, lock_file)?; | ||
lock.seek(SeekFrom::Start(0))?; | ||
update_compiler_toolchain( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
//! [move] table). This module does not support serialization because of limitations in the `toml` | ||
//! crate related to serializing types as inline tables. | ||
|
||
use std::io::{Read, Seek, SeekFrom, Write}; | ||
use std::io::{Read, Seek, Write}; | ||
|
||
use anyhow::{bail, Context, Result}; | ||
use serde::{Deserialize, Serialize}; | ||
|
@@ -182,7 +182,6 @@ pub fn update_compiler_toolchain( | |
) -> Result<()> { | ||
let mut toml_string = String::new(); | ||
file.read_to_string(&mut toml_string)?; | ||
file.seek(SeekFrom::Start(0))?; | ||
let mut toml = toml_string.parse::<toml_edit::Document>()?; | ||
let move_table = toml["move"].as_table_mut().ok_or(std::fmt::Error)?; | ||
let toolchain_version = toml::Value::try_from(ToolchainVersion { | ||
|
@@ -191,6 +190,8 @@ pub fn update_compiler_toolchain( | |
flavor, | ||
})?; | ||
move_table["toolchain-version"] = to_toml_edit_value(&toolchain_version); | ||
file.set_len(0)?; | ||
file.rewind()?; | ||
Comment on lines
+193
to
+194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small fix: we need to truncate the file to erase all previous content when updating these values, now covered by test. |
||
write!(file, "{}", toml)?; | ||
file.flush()?; | ||
Ok(()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposes the binary / root crate version in
env!("CARGO_PKG_VERSION")