1# Copyright 2023 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""Run doxygen on all Pigweed modules.""" 15 16import argparse 17import os 18from pathlib import Path 19import shutil 20import subprocess 21import sys 22 23 24def _parse_args() -> argparse.Namespace: 25 parser = argparse.ArgumentParser(description=__doc__) 26 parser.add_argument( 27 '--gn-root', 28 type=Path, 29 required=True, 30 help='Root of the GN tree.', 31 ) 32 parser.add_argument( 33 '--pigweed-modules-file', 34 type=Path, 35 required=True, 36 help='Pigweed modules list file', 37 ) 38 parser.add_argument( 39 '--output-dir', 40 type=Path, 41 required=True, 42 help='Location to write output to', 43 ) 44 parser.add_argument( 45 '--doxygen-config', 46 type=Path, 47 required=True, 48 help='Location to write output to', 49 ) 50 parser.add_argument( 51 '--include-paths', 52 nargs='+', 53 type=Path, 54 ) 55 return parser.parse_args() 56 57 58def main( 59 gn_root: Path, 60 pigweed_modules_file: Path, 61 output_dir: Path, 62 doxygen_config: Path, 63 include_paths: list[Path], 64) -> None: 65 root_build_dir = Path.cwd() 66 67 # Pigweed top level module list. 68 pw_module_list = [ 69 str((gn_root / path).resolve()) 70 for path in pigweed_modules_file.read_text().splitlines() 71 ] 72 73 # Use selected modules only if provided 74 if include_paths: 75 pw_module_list = [ 76 str((root_build_dir / path).resolve()) for path in include_paths 77 ] 78 79 env = os.environ.copy() 80 env['PW_DOXYGEN_OUTPUT_DIRECTORY'] = str(output_dir.resolve()) 81 env['PW_DOXYGEN_INPUT'] = ' '.join(pw_module_list) 82 env['PW_DOXYGEN_PROJECT_NAME'] = 'Pigweed' 83 84 # Clean out old xmls 85 shutil.rmtree(output_dir, ignore_errors=True) 86 output_dir.mkdir(parents=True, exist_ok=True) 87 88 command = ['doxygen', str(doxygen_config.resolve())] 89 process = subprocess.run(command, env=env, check=True) 90 sys.exit(process.returncode) 91 92 93if __name__ == '__main__': 94 main(**vars(_parse_args())) 95