Skip to content

Commit 2d5edf6

Browse files
sahithiacnbors-diem
authored andcommitted
Rename --only-deps to --fetch-deps-only, make it only populate MOVE_HOME
Closes: #475
1 parent bcf4df6 commit 2d5edf6

File tree

35 files changed

+91
-67
lines changed

35 files changed

+91
-67
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ pub struct Build;
1414
impl Build {
1515
pub fn execute(self, path: Option<PathBuf>, config: BuildConfig) -> anyhow::Result<()> {
1616
let rerooted_path = reroot_path(path)?;
17+
if config.fetch_deps_only {
18+
let mut config = config;
19+
if config.test_mode {
20+
config.dev_mode = true;
21+
}
22+
config.download_deps_for_package(&rerooted_path)?;
23+
return Ok(());
24+
}
1725
let architecture = config.architecture.unwrap_or(Architecture::Move);
1826

1927
match architecture {

language/tools/move-cli/tests/build_tests/only_deps/Move.toml

Lines changed: 0 additions & 10 deletions
This file was deleted.

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

Lines changed: 0 additions & 7 deletions
This file was deleted.

language/tools/move-cli/tests/build_tests/only_deps/args.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

language/tools/move-cli/tests/build_tests/only_deps/sources/A.move

Lines changed: 0 additions & 2 deletions
This file was deleted.

language/tools/move-package/src/compilation/compiled_package.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -533,14 +533,9 @@ impl CompiledPackage {
533533
Flags::empty()
534534
};
535535
// invoke the compiler
536-
let paths = {
537-
let mut v = deps_package_paths.clone();
538-
// Skip project files in the compilation process. Used in external IDE integrations.
539-
if !resolution_graph.build_options.only_deps {
540-
v.push(sources_package_paths.clone());
541-
}
542-
v
543-
};
536+
let mut paths = deps_package_paths.clone();
537+
paths.push(sources_package_paths.clone());
538+
544539
let compiler = Compiler::from_package_paths(paths, vec![]).set_flags(flags);
545540
let (file_map, all_compiled_units) = compiler_driver(compiler)?;
546541
let mut root_compiled_units = vec![];

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::{
2626
},
2727
package_lock::PackageLock,
2828
resolution::resolution_graph::{ResolutionGraph, ResolvedGraph},
29-
source_package::{layout, manifest_parser},
29+
source_package::manifest_parser,
3030
};
3131

3232
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
@@ -125,9 +125,9 @@ pub struct BuildConfig {
125125
#[clap(long = "arch", global = true, parse(try_from_str = Architecture::try_parse_from_str))]
126126
pub architecture: Option<Architecture>,
127127

128-
/// Only compile dependencies
129-
#[clap(long = "only-deps", global = true)]
130-
pub only_deps: bool,
128+
/// Only fetch dependency repos to MOVE_HOME
129+
#[clap(long = "fetch-deps-only", global = true)]
130+
pub fetch_deps_only: bool,
131131
}
132132

133133
impl Default for BuildConfig {
@@ -141,7 +141,7 @@ impl Default for BuildConfig {
141141
force_recompilation: false,
142142
additional_named_addresses: BTreeMap::new(),
143143
architecture: None,
144-
only_deps: false,
144+
fetch_deps_only: false,
145145
}
146146
}
147147
}
@@ -206,14 +206,26 @@ impl BuildConfig {
206206
ret
207207
}
208208

209+
pub fn download_deps_for_package(&self, path: &Path) -> Result<()> {
210+
let path = SourcePackageLayout::try_find_root(path)?;
211+
let toml_manifest =
212+
self.parse_toml_manifest(path.join(SourcePackageLayout::Manifest.path()))?;
213+
let mutx = PackageLock::lock();
214+
// This should be locked as it inspects the environment for `MOVE_HOME` which could
215+
// possibly be set by a different process in parallel.
216+
let manifest = manifest_parser::parse_source_manifest(toml_manifest)?;
217+
ResolutionGraph::download_dependency_repos(&manifest, self, &path)?;
218+
mutx.unlock();
219+
Ok(())
220+
}
221+
209222
pub fn resolution_graph_for_package(mut self, path: &Path) -> Result<ResolvedGraph> {
210223
if self.test_mode {
211224
self.dev_mode = true;
212225
}
213226
let path = SourcePackageLayout::try_find_root(path)?;
214-
let manifest_string =
215-
std::fs::read_to_string(path.join(layout::SourcePackageLayout::Manifest.path()))?;
216-
let toml_manifest = manifest_parser::parse_move_manifest_string(manifest_string)?;
227+
let toml_manifest =
228+
self.parse_toml_manifest(path.join(SourcePackageLayout::Manifest.path()))?;
217229
let mutx = PackageLock::lock();
218230
// This should be locked as it inspects the environment for `MOVE_HOME` which could
219231
// possibly be set by a different process in parallel.
@@ -223,4 +235,9 @@ impl BuildConfig {
223235
mutx.unlock();
224236
ret
225237
}
238+
239+
fn parse_toml_manifest(&self, path: PathBuf) -> Result<toml::Value> {
240+
let manifest_string = std::fs::read_to_string(path)?;
241+
manifest_parser::parse_move_manifest_string(manifest_string)
242+
}
226243
}

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
layout::SourcePackageLayout,
88
manifest_parser::{parse_move_manifest_string, parse_source_manifest},
99
parsed_manifest::{
10-
Dependency, FileName, NamedAddress, PackageDigest, PackageName, SourceManifest,
11-
SubstOrRename,
10+
Dependencies, Dependency, FileName, NamedAddress, PackageDigest, PackageName,
11+
SourceManifest, SubstOrRename,
1212
},
1313
},
1414
BuildConfig,
@@ -514,6 +514,32 @@ impl ResolvingGraph {
514514
}
515515
}
516516

517+
pub fn download_dependency_repos(
518+
manifest: &SourceManifest,
519+
build_options: &BuildConfig,
520+
root_path: &Path,
521+
) -> Result<()> {
522+
// include dev dependencies if in dev mode
523+
let empty_deps;
524+
let additional_deps = if build_options.dev_mode {
525+
&manifest.dev_dependencies
526+
} else {
527+
empty_deps = Dependencies::new();
528+
&empty_deps
529+
};
530+
531+
for (dep_name, dep) in manifest.dependencies.iter().chain(additional_deps.iter()) {
532+
Self::download_and_update_if_repo(*dep_name, dep)?;
533+
534+
let (dep_manifest, _) =
535+
Self::parse_package_manifest(dep, dep_name, root_path.to_path_buf())
536+
.with_context(|| format!("While processing dependency '{}'", *dep_name))?;
537+
// download dependencies of dependencies
538+
Self::download_dependency_repos(&dep_manifest, &build_options, root_path)?;
539+
}
540+
Ok(())
541+
}
542+
517543
fn download_and_update_if_repo(dep_name: PackageName, dep: &Dependency) -> Result<()> {
518544
if let Some(git_info) = &dep.git_info {
519545
if !git_info.download_to.exists() {

language/tools/move-package/tests/test_sources/compilation/basic_no_deps/Move.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ CompiledPackageInfo {
1515
force_recompilation: false,
1616
additional_named_addresses: {},
1717
architecture: None,
18-
only_deps: false,
18+
fetch_deps_only: false,
1919
},
2020
}

language/tools/move-package/tests/test_sources/compilation/basic_no_deps_address_assigned/Move.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ CompiledPackageInfo {
1717
force_recompilation: false,
1818
additional_named_addresses: {},
1919
architecture: None,
20-
only_deps: false,
20+
fetch_deps_only: false,
2121
},
2222
}

0 commit comments

Comments
 (0)