1616
1717
1818def clone_repo_to (dest : Path ):
19- """Clone this repo somewhere else."""
20- print ("Making a copy of repo" )
21- sp .run (("git" , "clone" , REPO_ROOT , dest ), check = True , capture_output = True )
19+ """Make a bare clone of this repo somewhere else."""
20+ print (f"Making a copy of repo in { dest } " )
21+ sp .run (("git" , "clone" , "--bare" , REPO_ROOT , dest ), check = True , capture_output = True )
22+
23+
24+ def add_worktree_for_release (repo_path : Path , release : str ) -> Path :
25+ """Add a worktree for the current release.
26+
27+ Also tries to symlink to the cargo cache dir to speed up build times, if possible.
28+ """
29+ # Add new worktree
30+ release_path = repo_path .parent / release
31+ sp .run (
32+ (
33+ "git" ,
34+ "-C" ,
35+ str (repo_path ),
36+ "worktree" ,
37+ "add" ,
38+ release_path ,
39+ release ,
40+ ),
41+ check = True ,
42+ capture_output = True ,
43+ )
2244
2345 # Add a symlink to cargo cache dir
2446 try :
25- os .symlink (REPO_ROOT / "target" , dest / "target" )
47+ os .symlink (
48+ REPO_ROOT / "target" , release_path / "target" , target_is_directory = True
49+ )
2650 except (NotImplementedError , OSError ):
2751 # Only newer versions of Windows support symlinks and these require the user to have
2852 # additional privileges (or to be in developer mode)
2953 print (
3054 "WARN: Could not create symlink to cache directory; cache will not be stored"
3155 )
3256
57+ return release_path
58+
3359
3460def apply_patches_for_release (release : str , repo_path : Path ) -> None :
3561 """Apply patches (if any) for the given release."""
@@ -41,30 +67,24 @@ def apply_patches_for_release(release: str, repo_path: Path) -> None:
4167def build_docs_for_release (release : str , repo_path : Path , outdir : Path ) -> None :
4268 """Build documentation for a given release."""
4369 print (f"Building docs for { release } " )
44-
45- # Check out release
46- sp .run (
47- ("git" , "-C" , str (repo_path ), "checkout" , release ),
48- check = True ,
49- capture_output = True ,
50- )
70+ release_path = add_worktree_for_release (repo_path , release )
5171
5272 # Apply patches, if any
53- apply_patches_for_release (release , repo_path )
73+ apply_patches_for_release (release , release_path )
5474
5575 # Build docs
56- sp .run (("just" , f"{ repo_path !s} /build-docs" ), check = True )
76+ sp .run (("just" , f"{ release_path !s} /build-docs" ), check = True )
5777
5878 # Patch versions.html to redirect to main versions page
59- with (repo_path / "book" / "versions.html" ).open ("w" , encoding = "utf-8" ) as f :
79+ with (release_path / "book" / "versions.html" ).open ("w" , encoding = "utf-8" ) as f :
6080 f .write (f"""<head>
6181 <meta http-equiv="Refresh" content="0; URL={ DOCS_SITE_ROOT } /versions.html" />
6282</head>""" )
6383
6484 # Move to output directory
6585 release_outdir = outdir / release
6686 print (f"Copying to { release_outdir } " )
67- shutil .move ((repo_path / "book" ), release_outdir )
87+ shutil .move ((release_path / "book" ), release_outdir )
6888
6989
7090def build_old_docs () -> None :
@@ -74,7 +94,7 @@ def build_old_docs() -> None:
7494
7595 # Clone this repo to a temporary directory
7696 with TemporaryDirectory () as tmpdir :
77- repo_path = Path (tmpdir )
97+ repo_path = Path (tmpdir ) / "MUSE2.git"
7898 clone_repo_to (repo_path )
7999
80100 # Generate documentation for each previous release
0 commit comments