(
prefix: Prefix,
version: str,
additional_dependencies: Sequence[str],
)
| 36 | |
| 37 | |
| 38 | def install_environment( |
| 39 | prefix: Prefix, |
| 40 | version: str, |
| 41 | additional_dependencies: Sequence[str], |
| 42 | ) -> None: |
| 43 | lang_base.assert_version_default('dart', version) |
| 44 | |
| 45 | envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version) |
| 46 | bin_dir = os.path.join(envdir, 'bin') |
| 47 | |
| 48 | def _install_dir(prefix_p: Prefix, pub_cache: str) -> None: |
| 49 | dart_env = {**os.environ, 'PUB_CACHE': pub_cache} |
| 50 | |
| 51 | with open(prefix_p.path('pubspec.yaml')) as f: |
| 52 | pubspec_contents = yaml_load(f) |
| 53 | |
| 54 | lang_base.setup_cmd(prefix_p, ('dart', 'pub', 'get'), env=dart_env) |
| 55 | |
| 56 | for executable in pubspec_contents['executables']: |
| 57 | lang_base.setup_cmd( |
| 58 | prefix_p, |
| 59 | ( |
| 60 | 'dart', 'compile', 'exe', |
| 61 | '--output', os.path.join(bin_dir, win_exe(executable)), |
| 62 | prefix_p.path('bin', f'{executable}.dart'), |
| 63 | ), |
| 64 | env=dart_env, |
| 65 | ) |
| 66 | |
| 67 | os.makedirs(bin_dir) |
| 68 | |
| 69 | with tempfile.TemporaryDirectory() as tmp: |
| 70 | _install_dir(prefix, tmp) |
| 71 | |
| 72 | for dep_s in additional_dependencies: |
| 73 | with tempfile.TemporaryDirectory() as dep_tmp: |
| 74 | dep, _, version = dep_s.partition(':') |
| 75 | if version: |
| 76 | dep_cmd: tuple[str, ...] = (dep, '--version', version) |
| 77 | else: |
| 78 | dep_cmd = (dep,) |
| 79 | |
| 80 | lang_base.setup_cmd( |
| 81 | prefix, |
| 82 | ('dart', 'pub', 'cache', 'add', *dep_cmd), |
| 83 | env={**os.environ, 'PUB_CACHE': dep_tmp}, |
| 84 | ) |
| 85 | |
| 86 | # try and find the 'pubspec.yaml' that just got added |
| 87 | for root, _, filenames in os.walk(dep_tmp): |
| 88 | if 'pubspec.yaml' in filenames: |
| 89 | with tempfile.TemporaryDirectory() as copied: |
| 90 | pkg = os.path.join(copied, 'pkg') |
| 91 | shutil.copytree(root, pkg) |
| 92 | _install_dir(Prefix(pkg), dep_tmp) |
| 93 | break |
| 94 | else: |
| 95 | raise AssertionError( |
nothing calls this directly
no test coverage detected