1# Copyright 2021 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"""Generates a list of relevant files present in a stm32cube source package.""" 15 16 17import pathlib 18 19 20def gen_file_list(stm32cube_dir: pathlib.Path): 21 """Generates `files.txt` for stm32cube directories 22 23 The paths in `files.txt` are relative paths to the files in the 'posix' 24 path format. 25 26 Args: 27 stm32cube_dir: stm32cube directory containing 'hal_driver', 28 'cmsis_core' and 'cmsis_device 29 30 Raises 31 AssertionError if the provided directory is invalid 32 """ 33 34 assert (stm32cube_dir / 'hal_driver').is_dir(), 'hal_driver not found' 35 assert (stm32cube_dir / 'cmsis_core').is_dir(), 'cmsis_core not found' 36 assert (stm32cube_dir / 'cmsis_device').is_dir(), 'cmsis_device not found' 37 38 file_paths: list[pathlib.Path] = [] 39 file_paths.extend(stm32cube_dir.glob("**/*.h")) 40 file_paths.extend(stm32cube_dir.glob("**/*.c")) 41 file_paths.extend(stm32cube_dir.glob("**/*.s")) 42 file_paths.extend(stm32cube_dir.glob("**/*.ld")) 43 file_paths.extend(stm32cube_dir.glob("**/*.icf")) 44 45 # TODO(vars): allow arbitrary path for generated file list 46 with open(stm32cube_dir / "files.txt", "w") as out_file: 47 out_file.write('# Generated by pw_stm32cube_build/gen_file_list\n') 48 for file_path in file_paths: 49 out_file.write( 50 file_path.relative_to(stm32cube_dir).as_posix() + '\n' 51 ) 52