blob: 408c88a5637fc952519f9e1800b35a24e3340970 [file] [log] [blame]
Zane Shelley2215d232023-04-07 14:43:40 -05001import os
2
3from parse_chip_data import gen_peltool_json
4from setuptools import setup
5from setuptools.command.build_py import build_py
6
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:
13package_name = "pel.hwdiags"
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.
18package_dir = ""
19
20# Split the package data directory into its components.
21data_dir_components = [*package_name.split("."), "data"]
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.
25package_data_glob = "/".join(data_dir_components)
26
27
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):
31 if not self.dry_run: # honor --dry-run flag
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 list of data file directories will need to be
40 # configurable via the package config in the bitbake recipes.
41 for chip in ("p10_10", "p10_20", "explorer", "odyssey"):
42 gen_peltool_json(chip, data_dir)
43
44 # Call the superclass run() to ensure everything else builds.
45 super().run()
46
47
48setup(
49 name="openpower-hw-diags-pel-parser-data",
50 version=os.getenv("PELTOOL_VERSION", "1.0"),
51 classifiers=["License :: OSI Approved :: Apache Software License"],
52 cmdclass={"build_py": my_build_py}, # register custom build class
53 packages=[package_name],
54 package_dir={package_name: package_dir},
55 package_data={package_name: [package_data_glob]},
56)