From dc0ff31b4314d787d6da75bb907d36183df9b4dd Mon Sep 17 00:00:00 2001 From: William Douglas Date: Fri, 28 Jun 2024 15:06:19 -0700 Subject: [PATCH] Add support for a copy_prepend config file This patch has a few interrelated changes in it but primarily it is supporting a new copy_prepend configuration file for autospec. This is intended to support cases where changes should be made to the source directory prior to the source directory being copied for different builds (avx2, 32bit, etc). Also with this change some tweaks to how cmake builds are handled to be more aligned with other build systems. Primarily that the source directoy is now fully copied rather than just creating a cmake build directory per build in the same source directory. Finally check support has been updated to account for the new path and update support for meson and apx. Signed-off-by: William Douglas --- README.rst | 6 ++++ autospec/check.py | 16 ++++++--- autospec/config.py | 12 ++++--- autospec/specfiles.py | 81 +++++++++++++++++++++++++++++-------------- 4 files changed, 80 insertions(+), 35 deletions(-) diff --git a/README.rst b/README.rst index 42fd8b8b..cf6f91c4 100644 --- a/README.rst +++ b/README.rst @@ -268,6 +268,12 @@ prep_prepend resulting ``.spec``, and is used for situations where fine-grained control is required. +copy_prepend + Additional actions that should take place directly before the source + directory is copied for other builds (32bit, avx2, etc). This will be + placed in the resulting ``.spec``, and is used for situations where + fine-grained control is required. + build_prepend Additional actions that should take place after ``%build`` and before the ``%configure`` macro or equivalent (``%cmake``, etc.). If autospec diff --git a/autospec/check.py b/autospec/check.py index fa49dbce..f7623832 100644 --- a/autospec/check.py +++ b/autospec/check.py @@ -97,17 +97,23 @@ def scan_for_tests(src_dir, config, requirements, content): } if config.config_opts.get('32bit'): testsuites["makecheck"] += "\ncd ../build32;\n" + make_check + " || :" - testsuites["cmake"] += "\ncd ../clr-build32;\n" + cmake_check + " || :" - testsuites["meson"] += "\ncd ../build32;\n" + meson_check + " || :" + testsuites["cmake"] += "\ncd ../../build32/clr-build32;\n" + cmake_check + " || :" + testsuites["meson"] += "\ncd ../buildapx;\n" + meson_check + " || :" if config.config_opts.get('use_avx2'): testsuites["makecheck"] += "\ncd ../buildavx2;\n" + make_check + " || :" - testsuites["cmake"] += "\ncd ../clr-build-avx2;\n" + cmake_check + " || :" + testsuites["cmake"] += "\ncd ../../buildavx2/clr-build-avx2;\n" + cmake_check + " || :" + testsuites["meson"] += "\ncd ../buildapx;\n" + meson_check + " || :" if config.config_opts.get('use_avx512'): testsuites["makecheck"] += "\ncd ../buildavx512;\n" + make_check + " || :" - testsuites["cmake"] += "\ncd ../clr-build-avx512;\n" + cmake_check + " || :" + testsuites["cmake"] += "\ncd ../../buildavx512/clr-build-avx512;\n" + cmake_check + " || :" + testsuites["meson"] += "\ncd ../buildapx;\n" + meson_check + " || :" + if config.config_opts.get('use_apx'): + testsuites["makecheck"] += "\ncd ../buildapx;\n" + make_check + " || :" + testsuites["cmake"] += "\ncd ../../buildapx/clr-build-apx;\n" + cmake_check + " || :" + testsuites["meson"] += "\ncd ../buildapx;\n" + meson_check + " || :" if config.config_opts.get('openmpi'): testsuites["makecheck"] += "\ncd ../build-openmpi;\n" + make_check_openmpi - testsuites["cmake"] += "\ncd ../clr-build-openmpi;\n" + cmake_check_openmpi + testsuites["cmake"] += "\ncd ../../build-openmpi/clr-build-openmpi;\n" + cmake_check_openmpi files = os.listdir(src_dir) diff --git a/autospec/config.py b/autospec/config.py index 7f6e4d77..d0e74126 100644 --- a/autospec/config.py +++ b/autospec/config.py @@ -91,6 +91,7 @@ def __init__(self, download_path): self.install_macro = "%make_install" self.disable_static = "--disable-static" self.prep_prepend = [] + self.copy_prepend = [] self.build_prepend = [] self.build_prepend_once = [] self.build_append = [] @@ -437,10 +438,11 @@ def create_conf(self): # next the options config_f['autospec'] = {} for fname, comment in sorted(self.config_options.items()): + fpath = os.path.join(self.download_path, fname) config_f.set('autospec', '# {}'.format(comment)) - if os.path.exists(fname): + if os.path.isfile(fpath): config_f['autospec'][fname] = 'true' - os.remove(fname) + os.remove(fpath) else: config_f['autospec'][fname] = 'false' @@ -448,9 +450,10 @@ def create_conf(self): config_f['autospec']['use_lto'] = 'true' # renamed options need special care - if os.path.exists("skip_test_suite"): + skip_path = os.path.join(self.download_path, "skip_test_suite") + if os.path.exists(skip_path): config_f['autospec']['skip_tests'] = 'true' - os.remove("skip_test_suite") + os.remove(skip_path) self.write_config(config_f) def create_buildreq_cache(self, version, buildreqs_cache): @@ -1004,6 +1007,7 @@ def parse_config_files(self, bump, filemanager, version, requirements): requirements.add_buildreq("openssh") self.prep_prepend = self.read_script_file(os.path.join(self.download_path, "prep_prepend")) + self.copy_prepend = self.read_script_file(os.path.join(self.download_path, "copy_prepend")) if os.path.isfile(os.path.join(self.download_path, "prep_append")): os.rename(os.path.join(self.download_path, "prep_append"), os.path.join(self.download_path, "build_prepend")) self.make_prepend = self.read_script_file(os.path.join(self.download_path, "make_prepend")) diff --git a/autospec/specfiles.py b/autospec/specfiles.py index 2979b6cb..260aabf6 100644 --- a/autospec/specfiles.py +++ b/autospec/specfiles.py @@ -520,27 +520,28 @@ def write_prep(self): if self.config.subdir: self._write_strip("popd") - if self.config.default_pattern != 'cmake': - if self.config.config_opts['32bit']: - self._write_strip("pushd ..") - self._write_strip("cp -a {} build32".format(self.content.tarball_prefix)) - self._write_strip("popd") - if self.config.config_opts['use_avx2']: - self._write_strip("pushd ..") - self._write_strip("cp -a {} buildavx2".format(self.content.tarball_prefix)) - self._write_strip("popd") - if self.config.config_opts['use_avx512']: - self._write_strip("pushd ..") - self._write_strip("cp -a {} buildavx512".format(self.content.tarball_prefix)) - self._write_strip("popd") - if self.config.config_opts['use_apx']: - self._write_strip("pushd ..") - self._write_strip("cp -a {} buildapx".format(self.content.tarball_prefix)) - self._write_strip("popd") - if self.config.config_opts['openmpi']: - self._write_strip("pushd ..") - self._write_strip("cp -a {} build-openmpi".format(self.content.tarball_prefix)) - self._write_strip("popd") + self.write_copy_prepend() + + if self.config.config_opts['32bit']: + self._write_strip("pushd ..") + self._write_strip("cp -a {} build32".format(self.content.tarball_prefix)) + self._write_strip("popd") + if self.config.config_opts['use_avx2']: + self._write_strip("pushd ..") + self._write_strip("cp -a {} buildavx2".format(self.content.tarball_prefix)) + self._write_strip("popd") + if self.config.config_opts['use_avx512']: + self._write_strip("pushd ..") + self._write_strip("cp -a {} buildavx512".format(self.content.tarball_prefix)) + self._write_strip("popd") + if self.config.config_opts['use_apx']: + self._write_strip("pushd ..") + self._write_strip("cp -a {} buildapx".format(self.content.tarball_prefix)) + self._write_strip("popd") + if self.config.config_opts['openmpi']: + self._write_strip("pushd ..") + self._write_strip("cp -a {} build-openmpi".format(self.content.tarball_prefix)) + self._write_strip("popd") self._write_strip("\n") def write_32bit_exports(self): @@ -800,6 +801,14 @@ def write_prep_prepend(self): self._write_strip("{}\n".format(line)) self._write_strip("## prep_prepend end") + def write_copy_prepend(self): + """Write out any custom supplied commands prior to creating source copies for avx, etc builds.""" + if self.config.copy_prepend: + self._write_strip("## copy_prepend content") + for line in self.config.copy_prepend: + self._write_strip("{}\n".format(line)) + self._write_strip("## copy_prepend end") + def write_build_prepend(self): """Write out any custom supplied commands at the start of the %build section and every build type.""" if self.config.build_prepend: @@ -915,13 +924,11 @@ def write_cmake_install(self): self._write_strip("export GOAMD64=v2") - if self.config.subdir: - self._write_strip("pushd " + self.config.subdir) - if self.config.config_opts['use_ninja'] and self.config.install_macro == '%make_install': self.config.install_macro = '%ninja_install' if self.config.config_opts['32bit']: + self._write_strip("pushd ../build32/" + self.config.subdir) self._write_strip("pushd clr-build32") self._write_strip("{}32 {} {}".format(self.config.install_macro, self.config.extra_make_install, @@ -939,30 +946,42 @@ def write_cmake_install(self): self._write_strip(" popd") self._write_strip("fi") self._write_strip("popd") + self._write_strip("popd") if self.config.config_opts['use_avx2']: + self._write_strip("pushd ../buildavx2/" + self.config.subdir) self._write_strip("GOAMD64=v3") self._write_strip("pushd clr-build-avx2") self._write_strip("%s_v3 %s || :\n" % (self.config.install_macro, self.config.extra_make_install)) self._write_strip("popd") + self._write_strip("popd") if self.config.config_opts['use_avx512']: + self._write_strip("pushd ../buildavx512/" + self.config.subdir) self._write_strip("GOAMD64=v4") self._write_strip("pushd clr-build-avx512") self._write_strip("%s_v4 %s || :\n" % (self.config.install_macro, self.config.extra_make_install)) self._write_strip("popd") + self._write_strip("popd") if self.config.config_opts['use_apx']: + self._write_strip("pushd ../buildapx/" + self.config.subdir) self._write_strip("GOAMD64=v3") self._write_strip("pushd clr-build-apx") self._write_strip("%s_va %s || :\n" % (self.config.install_macro, self.config.extra_make_install)) self._write_strip("popd") + self._write_strip("popd") if self.config.config_opts['openmpi']: + self._write_strip("pushd ../build-openmpi/" + self.config.subdir) self._write_strip("GOAMD64=v3") self._write_strip("pushd clr-build-openmpi") self.write_install_openmpi() self._write_strip("popd") + self._write_strip("popd") + + if self.config.subdir: + self._write_strip("pushd " + self.config.subdir) self._write_strip("GOAMD64=v2") self._write_strip("pushd clr-build") @@ -1656,7 +1675,11 @@ def write_cmake_pattern(self): self.write_make_line() self._write_strip("popd") + if self.config.subdir: + self._write_strip("popd") + if self.config.config_opts['use_avx2']: + self._write_strip("pushd ../buildavx2/" + self.config.subdir) self._write_strip("mkdir -p clr-build-avx2") self._write_strip("pushd clr-build-avx2") self.write_build_prepend() @@ -1669,8 +1692,10 @@ def write_cmake_pattern(self): self._write_strip(f"%cmake {self.config.cmake_srcdir} {self.extra_cmake} {cmake_type}") self.write_make_line() self._write_strip("popd") + self._write_strip("popd") if self.config.config_opts['use_avx512']: + self._write_strip("pushd ../buildavx512/" + self.config.subdir) self._write_strip("mkdir -p clr-build-avx512") self._write_strip("pushd clr-build-avx512") self.write_build_prepend() @@ -1683,8 +1708,10 @@ def write_cmake_pattern(self): self._write_strip(f"%cmake {self.config.cmake_srcdir} {self.extra_cmake} {cmake_type}") self.write_make_line() self._write_strip("popd") + self._write_strip("popd") if self.config.config_opts['use_apx'] and not self.config.config_opts['use_clang']: + self._write_strip("pushd ../buildapx/" + self.config.subdir) self._write_strip("mkdir -p clr-build-apx") self._write_strip("pushd clr-build-apx") self.write_build_prepend() @@ -1697,8 +1724,10 @@ def write_cmake_pattern(self): self._write_strip(f"%cmake {self.config.cmake_srcdir} {self.extra_cmake} {cmake_type}") self.write_make_line() self._write_strip("popd") + self._write_strip("popd") if self.config.config_opts['32bit']: + self._write_strip("pushd ../build32/" + self.config.subdir) self._write_strip("mkdir -p clr-build32") self._write_strip("pushd clr-build32") self.write_build_prepend() @@ -1711,8 +1740,10 @@ def write_cmake_pattern(self): self.write_make_line() self._write_strip("unset PKG_CONFIG_PATH") self._write_strip("popd") + self._write_strip("popd") if self.config.config_opts['openmpi']: + self._write_strip("pushd ../build-openmpi/" + self.config.subdir) self._write_strip("mkdir -p clr-build-openmpi") self._write_strip("pushd clr-build-openmpi") self._write_strip(". /usr/share/defaults/etc/profile.d/modules.sh") @@ -1728,8 +1759,6 @@ def write_cmake_pattern(self): self.write_make_line() self._write_strip("module unload openmpi") self._write_strip("popd") - - if self.config.subdir: self._write_strip("popd") self._write_strip("\n")