projects/aports·blob master · refs

103 lines · 4.1 KiB

1Patch-Source: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/12610
2--
3From eea465641340ad6d493093f68ffaebb22e000ded Mon Sep 17 00:00:00 2001
4From: PHO <[email protected]>
5Date: Sat, 11 May 2024 23:43:52 +0900
6Subject: [PATCH] hadrian/bootstrap/bootstrap.py: Add an option --jobs=N for
7 parallel compilation
8
9This makes bootstrapping hadrian a lot faster.
10---
11 hadrian/bootstrap/bootstrap.py | 26 +++++++++++++++++---------
12 1 file changed, 17 insertions(+), 9 deletions(-)
13
14--- a/hadrian/bootstrap/bootstrap.py
15+++ b/hadrian/bootstrap/bootstrap.py
16@@ -186,24 +186,24 @@ def resolve_dep(dep : BootstrapDep) -> Path:
17 return sdist_dir
18
19
20-def install_dep(dep: BootstrapDep, ghc: Compiler) -> None:
21+def install_dep(dep: BootstrapDep, ghc: Compiler, jobs: int|None) -> None:
22 dist_dir = (DISTDIR / f'{dep.package}-{dep.version}').resolve()
23
24 sdist_dir = resolve_dep(dep)
25
26- install_sdist(dist_dir, sdist_dir, ghc, dep.flags, dep.component)
27+ install_sdist(dist_dir, sdist_dir, ghc, dep.flags, dep.component, jobs)
28
29-def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[str], component):
30+def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[str], component, jobs: int|None):
31 prefix = PSEUDOSTORE.resolve()
32 flags_option = ' '.join(flags)
33 setup_dist_dir = dist_dir / 'setup'
34 setup = setup_dist_dir / 'Setup'
35
36- build_args = [
37+ common_args = [
38 f'--builddir={dist_dir}',
39 ]
40
41- configure_args = build_args + [
42+ configure_args = common_args + [
43 f'--package-db={PKG_DB.resolve()}',
44 f'--prefix={prefix}',
45 f'--bindir={BINDIR.resolve()}',
46@@ -215,6 +215,12 @@ def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[st
47 f'{component or ""}'
48 ]
49
50+ build_args = common_args.copy()
51+ if jobs is not None:
52+ build_args.append(f'--jobs={jobs}')
53+
54+ install_args = common_args.copy()
55+
56 def check_call(args: List[str]) -> None:
57 subprocess_run(args, cwd=sdist_dir, check=True)
58
59@@ -231,7 +237,7 @@ def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[st
60 check_call([str(ghc.ghc_path), '--make', '-package-env=-', '-i', f'-odir={setup_dist_dir}', f'-hidir={setup_dist_dir}', '-o', setup, 'Setup'])
61 check_call([setup, 'configure'] + configure_args)
62 check_call([setup, 'build'] + build_args)
63- check_call([setup, 'install'] + build_args)
64+ check_call([setup, 'install'] + install_args)
65
66 def hash_file(h, f: BinaryIO) -> SHA256Hash:
67 while True:
68@@ -246,7 +252,7 @@ def hash_file(h, f: BinaryIO) -> SHA256Hash:
69 UnitId = NewType('UnitId', str)
70 PlanUnit = NewType('PlanUnit', dict)
71
72-def bootstrap(info: BootstrapInfo, ghc: Compiler) -> None:
73+def bootstrap(info: BootstrapInfo, ghc: Compiler, jobs: int|None) -> None:
74 if not PKG_DB.exists():
75 print(f'Creating package database {PKG_DB}')
76 PKG_DB.parent.mkdir(parents=True, exist_ok=True)
77@@ -256,7 +262,7 @@ def bootstrap(info: BootstrapInfo, ghc: Compiler) -> None:
78 check_builtin(dep, ghc)
79
80 for dep in info.dependencies:
81- install_dep(dep, ghc)
82+ install_dep(dep, ghc, jobs)
83
84 # Steps
85 #######################################################################
86@@ -382,6 +388,8 @@ def main() -> None:
87 help='produce a Hadrian distribution archive (default)')
88 parser.add_argument('--no-archive', dest='want_archive', action='store_false',
89 help='do not produce a Hadrian distribution archive')
90+ parser.add_argument('-j', '--jobs', type=int,
91+ help='the number of jobs to run simultaneously')
92 parser.set_defaults(want_archive=True)
93
94 subparsers = parser.add_subparsers(dest="command")
95@@ -488,7 +496,7 @@ Alternatively, you could use `bootstrap.py -w {ghc.ghc_path} -d {args.deps} fetc
96 plan = gen_fetch_plan(info)
97 fetch_from_plan(plan, TARBALLS)
98
99- bootstrap(info, ghc)
100+ bootstrap(info, ghc, args.jobs)
101 hadrian_path = (BINDIR / 'hadrian').resolve()
102
103 print(dedent(f'''