Zane Shelley | 79cfb64 | 2022-12-13 15:33:03 -0600 | [diff] [blame] | 1 | import os |
| 2 | import subprocess |
Zane Shelley | 2d30a28 | 2021-06-04 13:21:46 -0500 | [diff] [blame] | 3 | |
| 4 | from setuptools import setup |
| 5 | from setuptools.command.build_py import build_py |
| 6 | |
Zane Shelley | 2d30a28 | 2021-06-04 13:21:46 -0500 | [diff] [blame] | 7 | # Typically in files like this we'd use find_packages() to traverse directories |
| 8 | # for any static packages. However, we are trying to add data to a package that |
| 9 | # will actually exist in another repository. Therefore, we have to explicitly |
| 10 | # list out the package name, directory, and data information. |
| 11 | |
| 12 | # We are building data for the following module: |
Zane Shelley | 79cfb64 | 2022-12-13 15:33:03 -0600 | [diff] [blame] | 13 | package_name = "pel.hwdiags" |
Zane Shelley | 2d30a28 | 2021-06-04 13:21:46 -0500 | [diff] [blame] | 14 | |
| 15 | # Since we are not using find_packages() we have to provide a package directory, |
| 16 | # but in this case nothing exists because there are no static package |
| 17 | # directories. Therefore, we will just use the empty string. |
Zane Shelley | 79cfb64 | 2022-12-13 15:33:03 -0600 | [diff] [blame] | 18 | package_dir = "" |
Zane Shelley | 2d30a28 | 2021-06-04 13:21:46 -0500 | [diff] [blame] | 19 | |
| 20 | # Split the package data directory into its components. |
Zane Shelley | 79cfb64 | 2022-12-13 15:33:03 -0600 | [diff] [blame] | 21 | data_dir_components = [*package_name.split("."), "data"] |
Zane Shelley | 2d30a28 | 2021-06-04 13:21:46 -0500 | [diff] [blame] | 22 | |
| 23 | # It is important to note that '/' must be used as the path separator, even on |
| 24 | # Windows. Setuptools will automatically convert the slashes where appropriate. |
Zane Shelley | 79cfb64 | 2022-12-13 15:33:03 -0600 | [diff] [blame] | 25 | package_data_glob = "/".join(data_dir_components) |
| 26 | |
Zane Shelley | 2d30a28 | 2021-06-04 13:21:46 -0500 | [diff] [blame] | 27 | |
| 28 | # This is a custom build class that is used to dynamically build the data files. |
| 29 | class my_build_py(build_py): |
| 30 | def run(self): |
Zane Shelley | 79cfb64 | 2022-12-13 15:33:03 -0600 | [diff] [blame] | 31 | if not self.dry_run: # honor --dry-run flag |
Zane Shelley | 2d30a28 | 2021-06-04 13:21:46 -0500 | [diff] [blame] | 32 | # Make sure the build directory for the data exists. |
| 33 | # Yes, os.path.join() is necessary in this case, which is different |
| 34 | # that what is stated above regarding package_data_glob. |
| 35 | data_dir = os.path.join(self.build_lib, *data_dir_components) |
| 36 | self.mkpath(data_dir) |
| 37 | |
| 38 | # Generate the PEL parser data JSON from the Chip Data XML. |
| 39 | # TODO: The current tool to build the PEL parser JSON files is a |
| 40 | # perl script. Eventually, it will be converted to a python |
| 41 | # module. |
| 42 | # TODO: The list of data file directories will need to be |
| 43 | # configurable via the package config in the bitbake recipes. |
Zane Shelley | 79cfb64 | 2022-12-13 15:33:03 -0600 | [diff] [blame] | 44 | for chip in ("p10", "explorer"): |
| 45 | subprocess.run( |
| 46 | [ |
| 47 | "./parse_chip_data_xml", |
| 48 | "--json", |
| 49 | "-i", |
| 50 | chip, |
| 51 | "-o", |
| 52 | data_dir, |
| 53 | ], |
| 54 | check=True, |
| 55 | ) |
Zane Shelley | 2d30a28 | 2021-06-04 13:21:46 -0500 | [diff] [blame] | 56 | |
| 57 | # Call the superclass run() to ensure everything else builds. |
| 58 | super().run() |
| 59 | |
| 60 | |
| 61 | setup( |
Zane Shelley | 79cfb64 | 2022-12-13 15:33:03 -0600 | [diff] [blame] | 62 | name="openpower-hw-diags-pel-parser-data", |
| 63 | version=os.getenv("PELTOOL_VERSION", "1.0"), |
| 64 | classifiers=["License :: OSI Approved :: Apache Software License"], |
| 65 | cmdclass={"build_py": my_build_py}, # register custom build class |
| 66 | packages=[package_name], |
| 67 | package_dir={package_name: package_dir}, |
| 68 | package_data={package_name: [package_data_glob]}, |
Zane Shelley | 2d30a28 | 2021-06-04 13:21:46 -0500 | [diff] [blame] | 69 | ) |