(
prefix: Prefix,
version: str,
additional_dependencies: Sequence[str],
)
| 111 | |
| 112 | |
| 113 | def install_environment( |
| 114 | prefix: Prefix, |
| 115 | version: str, |
| 116 | additional_dependencies: Sequence[str], |
| 117 | ) -> None: |
| 118 | envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version) |
| 119 | |
| 120 | # There are two cases where we might want to specify more dependencies: |
| 121 | # as dependencies for the library being built, and as binary packages |
| 122 | # to be `cargo install`'d. |
| 123 | # |
| 124 | # Unlike e.g. Python, if we just `cargo install` a library, it won't be |
| 125 | # used for compilation. And if we add a crate providing a binary to the |
| 126 | # `Cargo.toml`, the binary won't be built. |
| 127 | # |
| 128 | # Because of this, we allow specifying "cli" dependencies by prefixing |
| 129 | # with 'cli:'. |
| 130 | cli_deps = { |
| 131 | dep for dep in additional_dependencies if dep.startswith('cli:') |
| 132 | } |
| 133 | lib_deps = set(additional_dependencies) - cli_deps |
| 134 | |
| 135 | packages_to_install: set[tuple[str, ...]] = {('--path', '.')} |
| 136 | for cli_dep in cli_deps: |
| 137 | cli_dep = cli_dep.removeprefix('cli:') |
| 138 | package, _, crate_version = cli_dep.partition(':') |
| 139 | if crate_version != '': |
| 140 | packages_to_install.add((package, '--version', crate_version)) |
| 141 | else: |
| 142 | packages_to_install.add((package,)) |
| 143 | |
| 144 | with contextlib.ExitStack() as ctx: |
| 145 | ctx.enter_context(in_env(prefix, version)) |
| 146 | |
| 147 | if version != 'system': |
| 148 | install_rust_with_toolchain(_rust_toolchain(version), envdir) |
| 149 | |
| 150 | tmpdir = ctx.enter_context(tempfile.TemporaryDirectory()) |
| 151 | ctx.enter_context(envcontext((('RUSTUP_HOME', tmpdir),))) |
| 152 | |
| 153 | if len(lib_deps) > 0: |
| 154 | _add_dependencies(prefix, lib_deps) |
| 155 | |
| 156 | for args in packages_to_install: |
| 157 | cmd_output_b( |
| 158 | 'cargo', 'install', '--bins', '--root', envdir, *args, |
| 159 | cwd=prefix.prefix_dir, |
| 160 | ) |
nothing calls this directly
no test coverage detected