-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vendor all dependencies (crates) for Cargo
Add logic to resolve each Cargo package by vendoring its dependencies (crates) into the output directory using Cargo CLI. The important option here is `--locked` that disabled any changes to Cargo.lock file. To use vendored sources, `.cargo/config.toml` must contain the following lines. See [1] for more details. Replace hardcoded directory path with a placeholder for output directory specified by the users when running `cachi2 inject-files ...` ``` [source.crates-io] replace-with = "vendored-sources" [source.vendored-sources] directory = "${path-to-vendored-sources}" ``` --- [1]: https://crates.io/crates/cargo-vendor Signed-off-by: Michal Šoltis <msoltis@redhat.com>
- Loading branch information
1 parent
29216bf
commit adefbb4
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import tomlkit | ||
|
||
from cachi2.core.package_managers.cargo.main import _use_vendored_sources | ||
from cachi2.core.rooted_path import RootedPath | ||
|
||
|
||
def test_use_vendored_sources_creates_config_file(rooted_tmp_path: RootedPath) -> None: | ||
config_path = rooted_tmp_path.join_within_root(".cargo/config.toml") | ||
config_path.path.parent.mkdir(parents=True) | ||
|
||
project_file = _use_vendored_sources(rooted_tmp_path) | ||
|
||
assert config_path.path.exists() | ||
assert project_file.abspath == config_path.path | ||
|
||
config_content = tomlkit.parse(config_path.path.read_text()) | ||
|
||
assert config_content.get("source") == { | ||
"crates-io": {"replace-with": "vendored-sources"}, | ||
"vendored-sources": {"directory": "${output_dir}/deps/cargo"}, | ||
} | ||
|
||
|
||
def test_use_vendored_sources_preserves_existing_config(rooted_tmp_path: RootedPath) -> None: | ||
config_path = rooted_tmp_path.join_within_root(".cargo/config.toml") | ||
config_path.path.parent.mkdir(parents=True) | ||
|
||
some_toml = """ | ||
[build] | ||
rustflags = ["-C", "target-cpu=native"] | ||
""" | ||
config_path.path.write_text(some_toml) | ||
|
||
_use_vendored_sources(rooted_tmp_path) | ||
|
||
config_content = tomlkit.parse(config_path.path.read_text()) | ||
|
||
assert config_content.get("build") == {"rustflags": ["-C", "target-cpu=native"]} | ||
assert config_content.get("source") == { | ||
"crates-io": {"replace-with": "vendored-sources"}, | ||
"vendored-sources": {"directory": "${output_dir}/deps/cargo"}, | ||
} |