pw_docgen: Create hard links instead of copying
Change-Id: Ied4dccf757065d47baad63f7a3532b6aeeb77e8b
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/37563
Commit-Queue: Prashanth Swaminathan <prashanthsw@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
diff --git a/pw_docgen/py/pw_docgen/docgen.py b/pw_docgen/py/pw_docgen/docgen.py
index 8be124c..e130931 100644
--- a/pw_docgen/py/pw_docgen/docgen.py
+++ b/pw_docgen/py/pw_docgen/docgen.py
@@ -24,6 +24,7 @@
import subprocess
import sys
+from pathlib import Path
from typing import Dict, List, Tuple
SCRIPT_HEADER: str = '''
@@ -83,12 +84,6 @@
os.makedirs(dirname, exist_ok=exist_ok)
-def copy(src: str, dst: str) -> None:
- """Wrapper around shutil.copy that prints the operation."""
- print(f'COPY {src} -> {dst}')
- shutil.copy(src, dst)
-
-
def copy_doc_tree(args: argparse.Namespace) -> None:
"""Copies doc source and input files into a build tree."""
def build_path(path):
@@ -105,8 +100,9 @@
mkdir(args.sphinx_build_dir)
for source_path in args.sources:
- copy(source_path, f'{args.sphinx_build_dir}/')
- copy(args.conf, f'{args.sphinx_build_dir}/conf.py')
+ os.link(source_path,
+ f'{args.sphinx_build_dir}/{Path(source_path).name}')
+ os.link(args.conf, f'{args.sphinx_build_dir}/conf.py')
# Map of directory path to list of source and destination file paths.
dirs: Dict[str, List[Tuple[str, str]]] = collections.defaultdict(list)
@@ -118,7 +114,7 @@
for directory, file_pairs in dirs.items():
mkdir(directory, exist_ok=True)
for src, dst in file_pairs:
- copy(src, dst)
+ os.link(src, dst)
def main() -> int: