blob: 1ae5d2f087b2447dcca80f6881f9c248e38a8958 [file] [log] [blame]
Zane Shelley2d30a282021-06-04 13:21:46 -05001
2from setuptools import setup
3from setuptools.command.build_py import build_py
4
5import os
6import subprocess
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
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
33 # Make sure the build directory for the data exists.
34 # Yes, os.path.join() is necessary in this case, which is different
35 # that what is stated above regarding package_data_glob.
36 data_dir = os.path.join(self.build_lib, *data_dir_components)
37 self.mkpath(data_dir)
38
39 # Generate the PEL parser data JSON from the Chip Data XML.
40 # TODO: The current tool to build the PEL parser JSON files is a
41 # perl script. Eventually, it will be converted to a python
42 # module.
43 # TODO: The list of data file directories will need to be
44 # configurable via the package config in the bitbake recipes.
45 for chip in ('p10', 'explorer'):
46 subprocess.run([ './parse_chip_data_xml', '--json',
47 '-i', chip, '-o', data_dir ])
48
49 # Call the superclass run() to ensure everything else builds.
50 super().run()
51
52
53setup(
54 name = 'openpower-hw-diags-pel-parser-data',
55 version = '0.1',
56 classifiers = [ 'License :: OSI Approved :: Apache Software License' ],
57 cmdclass = { 'build_py': my_build_py }, # register custom build class
58 packages = [ package_name ],
59 package_dir = { package_name: package_dir },
60 package_data = { package_name: [ package_data_glob ] },
61)