Coverage for tsfpga/examples/build_fpga.py: 0%

32 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-20 20:51 +0000

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project, a project platform for modern FPGA development. 

5# https://tsfpga.com 

6# https://github.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9# Standard libraries 

10import sys 

11from pathlib import Path 

12from shutil import copy2, make_archive 

13from typing import TYPE_CHECKING 

14 

15# Do PYTHONPATH insert() instead of append() to prefer any local repo checkout over any pip install 

16REPO_ROOT = Path(__file__).parent.parent.parent.resolve() 

17sys.path.insert(0, str(REPO_ROOT)) 

18 

19# Import before others since it modifies PYTHONPATH. pylint: disable=unused-import 

20import tsfpga.examples.example_pythonpath # noqa: F401 

21 

22# First party libraries 

23from tsfpga.build_project_list import BuildProjectList 

24from tsfpga.examples.build_fpga_utils import arguments, generate_register_artifacts, setup_and_run 

25from tsfpga.examples.example_env import TSFPGA_EXAMPLES_TEMP_DIR, get_tsfpga_example_modules 

26from tsfpga.system_utils import create_directory, delete 

27 

28if TYPE_CHECKING: 

29 # First party libraries 

30 from tsfpga.vivado.project import VivadoProject 

31 

32 

33def main() -> None: 

34 """ 

35 Main function for building FPGA projects. If you are setting up a new build flow from scratch, 

36 you probably want to copy and modify this function, and reuse the others. 

37 """ 

38 args = arguments(default_temp_dir=TSFPGA_EXAMPLES_TEMP_DIR) 

39 modules = get_tsfpga_example_modules() 

40 projects = BuildProjectList( 

41 modules=modules, 

42 project_filters=args.project_filters, 

43 include_netlist_not_top_builds=args.netlist_builds, 

44 no_color=args.no_color, 

45 ) 

46 

47 sys.exit( 

48 setup_and_run( 

49 modules=modules, 

50 projects=projects, 

51 args=args, 

52 collect_artifacts_function=collect_artifacts, 

53 ) 

54 ) 

55 

56 

57def collect_artifacts(project: "VivadoProject", output_path: Path) -> bool: 

58 """ 

59 Example of a method to collect build artifacts. Will create a zip file with the bitstream, 

60 hardware definition (.xsa) and register documentation. 

61 

62 Arguments: 

63 project: Project object that has been built, and who's artifacts shall now be collected. 

64 output_path: Path to the build output. Artifact zip will be placed here as well. 

65 

66 Return: 

67 True if everything went well. 

68 """ 

69 version = "0.0.0" 

70 release_dir = create_directory(output_path / f"{project.name}-{version}", empty=True) 

71 print(f"Creating release in {release_dir.resolve()}.zip") 

72 

73 generate_register_artifacts(modules=project.modules, output_path=release_dir / "registers") 

74 copy2(output_path / f"{project.name }.bit", release_dir) 

75 copy2(output_path / f"{project.name}.bin", release_dir) 

76 if (output_path / f"{project.name}.xsa").exists(): 

77 copy2(output_path / f"{project.name}.xsa", release_dir) 

78 

79 make_archive(str(release_dir), "zip", release_dir) 

80 

81 # Remove folder so that only zip remains 

82 delete(release_dir) 

83 

84 return True 

85 

86 

87if __name__ == "__main__": 

88 main()