Skip to content

Commit e2e1a41

Browse files
authored
[build] Added additional diagnostics for fetching deps (move-language#643)
* [build] Added additional diagnostics for fetching deps * Fixes to EVM code and tests * Addressed review comments
1 parent 9eedce5 commit e2e1a41

File tree

11 files changed

+65
-27
lines changed

11 files changed

+65
-27
lines changed

language/move-analyzer/src/symbols.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,10 @@ impl Symbolicator {
624624

625625
eprintln!("symbolicating {:?}", pkg_path);
626626

627-
let resolution_graph = build_config.resolution_graph_for_package(pkg_path)?;
627+
// resolution graph diagnostics are only needed for CLI commands so ignore them by passing a
628+
// vector as the writer
629+
let resolution_graph =
630+
build_config.resolution_graph_for_package(pkg_path, &mut Vec::new())?;
628631

629632
// get source files to be able to correlate positions (in terms of byte offsets) with actual
630633
// file locations (in terms of line/column numbers)

language/tools/move-cli/src/base/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ impl Build {
1919
if config.test_mode {
2020
config.dev_mode = true;
2121
}
22-
config.download_deps_for_package(&rerooted_path)?;
22+
config.download_deps_for_package(&rerooted_path, &mut std::io::stdout())?;
2323
return Ok(());
2424
}
2525
let architecture = config.architecture.unwrap_or(Architecture::Move);
2626

2727
match architecture {
2828
Architecture::Move | Architecture::AsyncMove => {
29-
config.compile_package(&rerooted_path, &mut std::io::stderr())?;
29+
config.compile_package(&rerooted_path, &mut std::io::stdout())?;
3030
}
3131

3232
Architecture::Ethereum => {

language/tools/move-cli/src/base/info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Info {
1515
pub fn execute(self, path: Option<PathBuf>, config: BuildConfig) -> anyhow::Result<()> {
1616
let rerooted_path = reroot_path(path)?;
1717
config
18-
.resolution_graph_for_package(&rerooted_path)?
18+
.resolution_graph_for_package(&rerooted_path, &mut std::io::stdout())?
1919
.print_info()
2020
}
2121
}

language/tools/move-cli/src/base/test.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ pub fn run_move_unit_tests<W: Write + Send>(
160160
build_config.test_mode = true;
161161
build_config.dev_mode = true;
162162

163-
// Build the resolution graph
164-
let resolution_graph = build_config.resolution_graph_for_package(pkg_path)?;
163+
// Build the resolution graph (resolution graph diagnostics are only needed for CLI commands so
164+
// ignore them by passing a vector as the writer)
165+
let resolution_graph = build_config.resolution_graph_for_package(pkg_path, &mut Vec::new())?;
165166

166167
// Note: unit_test_config.named_address_values is always set to vec![] (the default value) before
167168
// being passed in.

language/tools/move-cli/src/sandbox/commands/test.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,13 @@ fn pad_tmp_path(tmp_dir: &Path, pad_amount: usize) -> anyhow::Result<PathBuf> {
126126
// package manifest.
127127
fn copy_deps(tmp_dir: &Path, pkg_dir: &Path) -> anyhow::Result<PathBuf> {
128128
// Sometimes we run a test that isn't a package for metatests so if there isn't a package we
129-
// don't need to nest at all.
129+
// don't need to nest at all. Resolution graph diagnostics are only needed for CLI commands so
130+
// ignore them by passing a vector as the writer.
130131
let package_resolution = match (BuildConfig {
131132
dev_mode: true,
132133
..Default::default()
133134
})
134-
.resolution_graph_for_package(pkg_dir)
135+
.resolution_graph_for_package(pkg_dir, &mut Vec::new())
135136
{
136137
Ok(pkg) => pkg,
137138
Err(_) => return Ok(tmp_dir.to_path_buf()),

language/tools/move-cli/tests/build_tests/simple_build_with_docs/args.exp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Command `new --path . Foo`:
22
Command `build`:
3+
FETCHING GIT DEPENDENCY https://github.com/move-language/move.git
34
INCLUDING DEPENDENCY MoveStdlib
45
BUILDING Foo
56
Command `docgen --template template.md --exclude-impl --exclude-private-fun --exclude-specs --include-call-diagrams --include-dep-diagrams --independent-specs --no-collapsed-sections --output-directory doc --references-file template.md --section-level-start 3 --toc-depth 3`:

language/tools/move-package/src/lib.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl BuildConfig {
149149
/// Compile the package at `path` or the containing Move package. Exit process on warning or
150150
/// failure.
151151
pub fn compile_package<W: Write>(self, path: &Path, writer: &mut W) -> Result<CompiledPackage> {
152-
let resolved_graph = self.resolution_graph_for_package(path)?;
152+
let resolved_graph = self.resolution_graph_for_package(path, writer)?;
153153
let mutx = PackageLock::lock();
154154
let ret = BuildPlan::create(resolved_graph)?.compile(writer);
155155
mutx.unlock();
@@ -163,7 +163,7 @@ impl BuildConfig {
163163
path: &Path,
164164
writer: &mut W,
165165
) -> Result<CompiledPackage> {
166-
let resolved_graph = self.resolution_graph_for_package(path)?;
166+
let resolved_graph = self.resolution_graph_for_package(path, writer)?;
167167
let mutx = PackageLock::lock();
168168
let ret = BuildPlan::create(resolved_graph)?.compile_no_exit(writer);
169169
mutx.unlock();
@@ -172,7 +172,9 @@ impl BuildConfig {
172172

173173
#[cfg(feature = "evm-backend")]
174174
pub fn compile_package_evm<W: Write>(self, path: &Path, writer: &mut W) -> Result<()> {
175-
let resolved_graph = self.resolution_graph_for_package(path)?;
175+
// resolution graph diagnostics are only needed for CLI commands so ignore them by passing a
176+
// vector as the writer
177+
let resolved_graph = self.resolution_graph_for_package(path, &mut Vec::new())?;
176178
let mutx = PackageLock::lock();
177179
let ret = BuildPlan::create(resolved_graph)?.compile_evm(writer);
178180
mutx.unlock();
@@ -189,27 +191,33 @@ impl BuildConfig {
189191
path: &Path,
190192
model_config: ModelConfig,
191193
) -> Result<GlobalEnv> {
192-
let resolved_graph = self.resolution_graph_for_package(path)?;
194+
// resolution graph diagnostics are only needed for CLI commands so ignore them by passing a
195+
// vector as the writer
196+
let resolved_graph = self.resolution_graph_for_package(path, &mut Vec::new())?;
193197
let mutx = PackageLock::lock();
194198
let ret = ModelBuilder::create(resolved_graph, model_config).build_model();
195199
mutx.unlock();
196200
ret
197201
}
198202

199-
pub fn download_deps_for_package(&self, path: &Path) -> Result<()> {
203+
pub fn download_deps_for_package<W: Write>(&self, path: &Path, writer: &mut W) -> Result<()> {
200204
let path = SourcePackageLayout::try_find_root(path)?;
201205
let toml_manifest =
202206
self.parse_toml_manifest(path.join(SourcePackageLayout::Manifest.path()))?;
203207
let mutx = PackageLock::lock();
204208
// This should be locked as it inspects the environment for `MOVE_HOME` which could
205209
// possibly be set by a different process in parallel.
206210
let manifest = manifest_parser::parse_source_manifest(toml_manifest)?;
207-
ResolutionGraph::download_dependency_repos(&manifest, self, &path)?;
211+
ResolutionGraph::download_dependency_repos(&manifest, self, &path, writer)?;
208212
mutx.unlock();
209213
Ok(())
210214
}
211215

212-
pub fn resolution_graph_for_package(mut self, path: &Path) -> Result<ResolvedGraph> {
216+
pub fn resolution_graph_for_package<W: Write>(
217+
mut self,
218+
path: &Path,
219+
writer: &mut W,
220+
) -> Result<ResolvedGraph> {
213221
if self.test_mode {
214222
self.dev_mode = true;
215223
}
@@ -220,7 +228,7 @@ impl BuildConfig {
220228
// This should be locked as it inspects the environment for `MOVE_HOME` which could
221229
// possibly be set by a different process in parallel.
222230
let manifest = manifest_parser::parse_source_manifest(toml_manifest)?;
223-
let resolution_graph = ResolutionGraph::new(manifest, path, self)?;
231+
let resolution_graph = ResolutionGraph::new(manifest, path, self, writer)?;
224232
let ret = resolution_graph.resolve();
225233
mutx.unlock();
226234
ret

language/tools/move-package/src/resolution/resolution_graph.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::{
1616
BuildConfig,
1717
};
1818
use anyhow::{bail, Context, Result};
19+
use colored::Colorize;
1920
use move_command_line_common::files::{find_move_filenames, FileHash};
2021
use move_core_types::account_address::AccountAddress;
2122
use move_symbol_pool::Symbol;
@@ -25,6 +26,7 @@ use std::{
2526
cell::RefCell,
2627
collections::{BTreeMap, BTreeSet},
2728
fs,
29+
io::Write,
2830
path::{Path, PathBuf},
2931
process::{Command, Stdio},
3032
rc::Rc,
@@ -90,10 +92,11 @@ pub struct ResolutionPackage<T> {
9092
}
9193

9294
impl ResolvingGraph {
93-
pub fn new(
95+
pub fn new<W: Write>(
9496
root_package: SourceManifest,
9597
root_package_path: PathBuf,
9698
mut build_options: BuildConfig,
99+
writer: &mut W,
97100
) -> Result<ResolvingGraph> {
98101
if build_options.architecture.is_none() {
99102
if let Some(info) = &root_package.build {
@@ -109,7 +112,7 @@ impl ResolvingGraph {
109112
};
110113

111114
resolution_graph
112-
.build_resolution_graph(root_package.clone(), root_package_path, true)
115+
.build_resolution_graph(root_package.clone(), root_package_path, true, writer)
113116
.with_context(|| {
114117
format!(
115118
"Unable to resolve packages for package '{}'",
@@ -189,11 +192,12 @@ impl ResolvingGraph {
189192
})
190193
}
191194

192-
fn build_resolution_graph(
195+
fn build_resolution_graph<W: Write>(
193196
&mut self,
194197
package: SourceManifest,
195198
package_path: PathBuf,
196199
is_root_package: bool,
200+
writer: &mut W,
197201
) -> Result<()> {
198202
let package_name = package.package.name;
199203
let package_node_id = match self.package_table.get(&package_name) {
@@ -246,7 +250,7 @@ impl ResolvingGraph {
246250
self.graph.add_edge(package_node_id, dep_node_id, ());
247251

248252
let (dep_renaming, dep_resolution_table) = self
249-
.process_dependency(dep_name, dep, package_path.clone())
253+
.process_dependency(dep_name, dep, package_path.clone(), writer)
250254
.with_context(|| {
251255
format!(
252256
"While resolving dependency '{}' in package '{}'",
@@ -382,21 +386,23 @@ impl ResolvingGraph {
382386
// Process a dependency. `dep_name_in_pkg` is the name assigned to the dependent package `dep`
383387
// in the source manifest, and we check that this name matches the name of the dependency it is
384388
// assigned to.
385-
fn process_dependency(
389+
fn process_dependency<W: Write>(
386390
&mut self,
387391
dep_name_in_pkg: PackageName,
388392
dep: Dependency,
389393
root_path: PathBuf,
394+
writer: &mut W,
390395
) -> Result<(Renaming, ResolvingTable)> {
391396
Self::download_and_update_if_remote(
392397
dep_name_in_pkg,
393398
&dep,
394399
self.build_options.skip_fetch_latest_git_deps,
400+
writer,
395401
)?;
396402
let (dep_package, dep_package_dir) =
397403
Self::parse_package_manifest(&dep, &dep_name_in_pkg, root_path)
398404
.with_context(|| format!("While processing dependency '{}'", dep_name_in_pkg))?;
399-
self.build_resolution_graph(dep_package.clone(), dep_package_dir, false)
405+
self.build_resolution_graph(dep_package.clone(), dep_package_dir, false, writer)
400406
.with_context(|| {
401407
format!("Unable to resolve package dependency '{}'", dep_name_in_pkg)
402408
})?;
@@ -515,10 +521,11 @@ impl ResolvingGraph {
515521
}
516522
}
517523

518-
pub fn download_dependency_repos(
524+
pub fn download_dependency_repos<W: Write>(
519525
manifest: &SourceManifest,
520526
build_options: &BuildConfig,
521527
root_path: &Path,
528+
writer: &mut W,
522529
) -> Result<()> {
523530
// include dev dependencies if in dev mode
524531
let empty_deps;
@@ -534,24 +541,33 @@ impl ResolvingGraph {
534541
*dep_name,
535542
dep,
536543
build_options.skip_fetch_latest_git_deps,
544+
writer,
537545
)?;
538546

539547
let (dep_manifest, _) =
540548
Self::parse_package_manifest(dep, dep_name, root_path.to_path_buf())
541549
.with_context(|| format!("While processing dependency '{}'", *dep_name))?;
542550
// download dependencies of dependencies
543-
Self::download_dependency_repos(&dep_manifest, build_options, root_path)?;
551+
Self::download_dependency_repos(&dep_manifest, build_options, root_path, writer)?;
544552
}
545553
Ok(())
546554
}
547555

548-
fn download_and_update_if_remote(
556+
fn download_and_update_if_remote<W: Write>(
549557
dep_name: PackageName,
550558
dep: &Dependency,
551559
skip_fetch_latest_git_deps: bool,
560+
writer: &mut W,
552561
) -> Result<()> {
553562
if let Some(git_info) = &dep.git_info {
554563
if !git_info.download_to.exists() {
564+
writeln!(
565+
writer,
566+
"{} {}",
567+
"FETCHING GIT DEPENDENCY".bold().green(),
568+
git_info.git_url
569+
)?;
570+
555571
// If the cached folder does not exist, download and clone accordingly
556572
Command::new("git")
557573
.args([

language/tools/move-package/tests/package_hash_skips_non_move_files.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ use tempfile::tempdir;
1010
fn package_hash_skips_non_move_files() {
1111
let path = Path::new("tests/test_sources/resolution/dep_good_digest");
1212

13+
// resolution graph diagnostics are only needed for CLI commands so ignore them in both cases by
14+
// passing a vector as the writer
15+
1316
let pkg1 = BuildConfig {
1417
install_dir: Some(tempdir().unwrap().path().to_path_buf()),
1518
..Default::default()
1619
}
17-
.resolution_graph_for_package(path)
20+
.resolution_graph_for_package(path, &mut Vec::new())
1821
.unwrap();
1922

2023
let dummy_path = path.join("deps_only/other_dep/sources/dummy_text");
@@ -27,7 +30,7 @@ fn package_hash_skips_non_move_files() {
2730
install_dir: Some(tempdir().unwrap().path().to_path_buf()),
2831
..Default::default()
2932
}
30-
.resolution_graph_for_package(path)
33+
.resolution_graph_for_package(path, &mut Vec::new())
3134
.unwrap();
3235

3336
std::fs::remove_file(&dummy_path).unwrap();

language/tools/move-package/tests/test_additional_addresses.rs

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn test_additonal_addresses() {
3030
additional_named_addresses,
3131
..Default::default()
3232
},
33+
&mut Vec::new() /* empty writer as no diags needed */
3334
)
3435
.unwrap()
3536
.resolve()
@@ -42,6 +43,7 @@ fn test_additonal_addresses() {
4243
install_dir: Some(tempdir().unwrap().path().to_path_buf()),
4344
..Default::default()
4445
},
46+
&mut Vec::new() /* empty writer as no diags needed */
4547
)
4648
.unwrap()
4749
.resolve()
@@ -67,6 +69,7 @@ fn test_additonal_addresses_already_assigned_same_value() {
6769
additional_named_addresses,
6870
..Default::default()
6971
},
72+
&mut Vec::new() /* empty writer as no diags needed */
7073
)
7174
.unwrap()
7275
.resolve()
@@ -92,6 +95,7 @@ fn test_additonal_addresses_already_assigned_different_value() {
9295
additional_named_addresses,
9396
..Default::default()
9497
},
98+
&mut Vec::new() /* empty writer as no diags needed */
9599
)
96100
.is_err());
97101
}

language/tools/move-package/tests/test_runner.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub fn run_test(path: &Path) -> datatest_stable::Result<()> {
5959
force_recompilation: false,
6060
..Default::default()
6161
},
62+
&mut Vec::new(), /* empty writer as no diags needed */
6263
)
6364
})
6465
.and_then(|rg| rg.resolve())

0 commit comments

Comments
 (0)