diff --git a/MANIFEST.in b/MANIFEST.in index f4d516a..1c0ac90 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,6 +2,8 @@ include README.rst include LICENSE include tox.ini recursive-include osaca/data/ *.yml +recursive-include osaca/data/ *.pickle +include osaca/data/_build_cache.py include examples/* recursive-include tests *.py *.out recursive-include tests/testfiles/ * diff --git a/osaca/data/_build_cache.py b/osaca/data/_build_cache.py new file mode 100644 index 0000000..fad10ed --- /dev/null +++ b/osaca/data/_build_cache.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +from glob import glob +import os.path +import sys +sys.path[0:0] = ['../..'] + +from osaca.semantics.hw_model import MachineModel + +print('Building cache: ', end='') +sys.stdout.flush() + +# Iterating architectures +for f in glob(os.path.join(os.path.dirname(__file__), '*.yml')): + MachineModel(path_to_yaml=f) + print('.', end='') + sys.stdout.flush() + +# Iterating ISAs +for f in glob(os.path.join(os.path.dirname(__file__), 'isa/*.yml')): + MachineModel(path_to_yaml=f) + print('+', end='') + sys.stdout.flush() + +print() \ No newline at end of file diff --git a/setup.py b/setup.py index 2e380b8..ead2243 100755 --- a/setup.py +++ b/setup.py @@ -2,11 +2,14 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages +from setuptools.command.install import install as _install +from setuptools.command.sdist import sdist as _sdist # To use a consistent encoding from codecs import open import os import io import re +import sys here = os.path.abspath(os.path.dirname(__file__)) @@ -27,6 +30,27 @@ def find_version(*file_paths): raise RuntimeError("Unable to find version string.") +def _run_build_cache(dir): + from subprocess import check_call + # This is run inside the install staging directory (that had no .pyc files) + # We don't want to generate any. + # https://github.com/eliben/pycparser/pull/135 + check_call([sys.executable, '-B', '_build_cache.py'], + cwd=os.path.join(dir, 'osaca', 'data')) + + +class install(_install): + def run(self): + _install.run(self) + self.execute(_run_build_cache, (self.install_lib,), msg="Build ISA and architecture cache") + + +class sdist(_sdist): + def make_release_tree(self, basedir, files): + _sdist.make_release_tree(self, basedir, files) + self.execute(_run_build_cache, (basedir,), msg="Build ISA and architecture cache") + + # Get the long description from the README file with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f: long_description = f.read() @@ -124,4 +148,7 @@ setup( 'osaca=osaca.osaca:main', ], }, + + # Overwriting install and sdist to enforce cache distribution with package + cmdclass={'install': install, 'sdist': sdist}, )