blob: c6cbec18a05b57bca5d8810e533dc28ac8f12d30 [file] [log] [blame]
Zane Shelley2215d232023-04-07 14:43:40 -05001import os
Caleb Palmere2e645e2024-09-03 15:34:45 -05002import sys
Zane Shelley2215d232023-04-07 14:43:40 -05003
4from parse_chip_data import gen_peltool_json
5from setuptools import setup
6from setuptools.command.build_py import build_py
7
8# Typically in files like this we'd use find_packages() to traverse directories
9# for any static packages. However, we are trying to add data to a package that
10# will actually exist in another repository. Therefore, we have to explicitly
11# list out the package name, directory, and data information.
12
13# We are building data for the following module:
14package_name = "pel.hwdiags"
15
16# Since we are not using find_packages() we have to provide a package directory,
17# but in this case nothing exists because there are no static package
18# directories. Therefore, we will just use the empty string.
19package_dir = ""
20
21# Split the package data directory into its components.
22data_dir_components = [*package_name.split("."), "data"]
23
24# It is important to note that '/' must be used as the path separator, even on
25# Windows. Setuptools will automatically convert the slashes where appropriate.
26package_data_glob = "/".join(data_dir_components)
27
Caleb Palmere2e645e2024-09-03 15:34:45 -050028# These are the possible chip config options to build the PEL parser data json
29# from. By default all configs will be built. The '--chip-config' option can be
30# used in recipes to specify manually.
31chipConfig = ["p10_10", "p10_20", "explorer", "odyssey"]
32
33# The chip-config option is manually handled here, rather than added as a custom
34# option in the my_build_py class to facilitate use with setuptools which will
35# use bdist_wheel in the build. There is currently not a way to indicate a
36# option only for the custom build_py through bdist_wheel. As such the option
37# will be handled generically here with the chipConfig variable only used in the
38# custom build class.
39if "--chip-config" in sys.argv:
40 chipConfig = sys.argv.pop(sys.argv.index("--chip-config") + 1).split(",")
41 sys.argv.remove("--chip-config")
42
Zane Shelley2215d232023-04-07 14:43:40 -050043
44# This is a custom build class that is used to dynamically build the data files.
45class my_build_py(build_py):
Caleb Palmerae60d8e2024-08-28 16:09:20 -050046
Zane Shelley2215d232023-04-07 14:43:40 -050047 def run(self):
48 if not self.dry_run: # honor --dry-run flag
49 # Make sure the build directory for the data exists.
50 # Yes, os.path.join() is necessary in this case, which is different
51 # that what is stated above regarding package_data_glob.
52 data_dir = os.path.join(self.build_lib, *data_dir_components)
53 self.mkpath(data_dir)
54
55 # Generate the PEL parser data JSON from the Chip Data XML.
Caleb Palmere2e645e2024-09-03 15:34:45 -050056 for chip in chipConfig:
Zane Shelley2215d232023-04-07 14:43:40 -050057 gen_peltool_json(chip, data_dir)
58
59 # Call the superclass run() to ensure everything else builds.
60 super().run()
61
62
63setup(
64 name="openpower-hw-diags-pel-parser-data",
65 version=os.getenv("PELTOOL_VERSION", "1.0"),
66 classifiers=["License :: OSI Approved :: Apache Software License"],
67 cmdclass={"build_py": my_build_py}, # register custom build class
68 packages=[package_name],
69 package_dir={package_name: package_dir},
70 package_data={package_name: [package_data_glob]},
71)