blob: 74e91c99f58db8b666e36d7b95b705e83cde6225 [file] [log] [blame]
Zane Shelley79cfb642022-12-13 15:33:03 -06001import os
2import subprocess
Zane Shelley2d30a282021-06-04 13:21:46 -05003
4from setuptools import setup
5from setuptools.command.build_py import build_py
6
Zane Shelley2d30a282021-06-04 13:21:46 -05007# 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 Shelley79cfb642022-12-13 15:33:03 -060013package_name = "pel.hwdiags"
Zane Shelley2d30a282021-06-04 13:21:46 -050014
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 Shelley79cfb642022-12-13 15:33:03 -060018package_dir = ""
Zane Shelley2d30a282021-06-04 13:21:46 -050019
20# Split the package data directory into its components.
Zane Shelley79cfb642022-12-13 15:33:03 -060021data_dir_components = [*package_name.split("."), "data"]
Zane Shelley2d30a282021-06-04 13:21:46 -050022
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 Shelley79cfb642022-12-13 15:33:03 -060025package_data_glob = "/".join(data_dir_components)
26
Zane Shelley2d30a282021-06-04 13:21:46 -050027
28# This is a custom build class that is used to dynamically build the data files.
29class my_build_py(build_py):
30 def run(self):
Zane Shelley79cfb642022-12-13 15:33:03 -060031 if not self.dry_run: # honor --dry-run flag
Zane Shelley2d30a282021-06-04 13:21:46 -050032 # 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 Shelley79cfb642022-12-13 15:33:03 -060044 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 Shelley2d30a282021-06-04 13:21:46 -050056
57 # Call the superclass run() to ensure everything else builds.
58 super().run()
59
60
61setup(
Zane Shelley79cfb642022-12-13 15:33:03 -060062 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 Shelley2d30a282021-06-04 13:21:46 -050069)