From f1796491bd17b023d628cfdbc688df85cf388570 Mon Sep 17 00:00:00 2001 From: William Douglas Date: Tue, 24 Jul 2018 22:18:32 +0000 Subject: [PATCH] Add prep, build and install edge case handlers Add support for package specific configuration to be added before any other actions in each of the %prep, %build and %install sections are run. As part of this rename the prep_append configuration file to build_prepend and make_install_append configuration file to install_append. --- README.rst | 26 ++++++++++-- autospec/config.py | 28 +++++++++---- autospec/git.py | 8 +++- autospec/infile_update_spec.py | 6 +-- autospec/specfiles.py | 76 +++++++++++++++++++++++++--------- 5 files changed, 108 insertions(+), 36 deletions(-) diff --git a/README.rst b/README.rst index a88867d..5bea7fe 100644 --- a/README.rst +++ b/README.rst @@ -145,7 +145,10 @@ Variables included: * Build dependencies * Commands - These are appended to the associated files as comments * ``configure`` - * ``make_install_append`` + * ``prep_prepend`` + * ``build_prepend`` + * ``install_prepend`` + * ``install_append`` Control files @@ -245,11 +248,26 @@ make32_install_args macro in the ``.spec`` for the 32bit build. Again it is appended after make_install_args so 32bit specific overrides can be added. -make_install_append - Additional actions that should take place after the ``make install`` step has - completed. This will be placed in the resulting ``.spec``, and is used for +prep_prepend + Additional actions that should take place directly after ``%prep`` + 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 directly after ``%build`` + This will be placed in the resulting ``.spec``, and is used for + situations where fine-grained control is required. + +install_prepend + Additional actions that should take place directly after ``%install`` + This will be placed in the resulting ``.spec``, and is used for + situations where fine-grained control is required. + +install_append + Additional actions that should take place at the very end of the + ``%install`` section. This will be placed in the resulting ``.spec``, + and is used for situations where fine-grained control is required. + install_macro The contents of this file be used instead of the automatically detected ``install`` routine, i.e. use this if ``%make_install`` is insufficient. diff --git a/autospec/config.py b/autospec/config.py index d5d6100..9f2faf1 100644 --- a/autospec/config.py +++ b/autospec/config.py @@ -45,11 +45,13 @@ extra_make_install = "" extra_make32_install = "" extra_cmake = "" cmake_srcdir = "" -prep_append = [] subdir = "" install_macro = "%make_install" disable_static = "--disable-static" -make_install_append = [] +prep_prepend = [] +build_prepend = [] +install_prepend = [] +install_append = [] patches = [] autoreconf = False custom_desc = "" @@ -548,11 +550,13 @@ def parse_config_files(path, bump, filemanager, version): global extra_make32_install global extra_cmake global cmake_srcdir - global prep_append global subdir global install_macro global disable_static - global make_install_append + global prep_prepend + global build_prepend + global install_prepend + global install_append global patches global autoreconf global yum_conf @@ -808,8 +812,14 @@ def parse_config_files(path, bump, filemanager, version): buildreq.add_buildreq("gcc-libgcc32") buildreq.add_buildreq("gcc-libstdc++32") - make_install_append = read_conf_file(os.path.join(path, "make_install_append")) - prep_append = read_conf_file(os.path.join(path, "prep_append")) + prep_prepend = read_conf_file(os.path.join(path, "prep_prepend")) + if os.path.isfile(os.path.join(path, "prep_append")): + os.rename(os.path.join(path, "prep_append"), os.path.join(path, "build_prepend")) + build_prepend = read_conf_file(os.path.join(path, "build_prepend")) + install_prepend = read_conf_file(os.path.join(path, "install_prepend")) + if os.path.isfile(os.path.join(path, "make_install_append")): + os.rename(os.path.join(path, "make_install_append"), os.path.join(path, "install_append")) + install_append = read_conf_file(os.path.join(path, "install_append")) profile_payload = read_conf_file(os.path.join(path, "profile_payload")) @@ -829,10 +839,12 @@ def load_specfile(specfile): specfile.extra_make32_install = extra_make32_install specfile.extra_cmake = extra_cmake specfile.cmake_srcdir = cmake_srcdir or specfile.cmake_srcdir - specfile.prep_append = prep_append specfile.subdir = subdir specfile.install_macro = install_macro specfile.disable_static = disable_static - specfile.make_install_append = make_install_append + specfile.prep_prepend = prep_prepend + specfile.build_prepend = build_prepend + specfile.install_prepend = install_prepend + specfile.install_append = install_append specfile.patches = patches specfile.autoreconf = autoreconf diff --git a/autospec/git.py b/autospec/git.py index bd1ce82..46c2cb6 100644 --- a/autospec/git.py +++ b/autospec/git.py @@ -49,8 +49,10 @@ def commit_to_git(path): call("git add upstream", cwd=path) call("bash -c 'shopt -s failglob; git add *.spec'", cwd=path) call("git add %s.tmpfiles" % tarball.name, check=False, stderr=subprocess.DEVNULL, cwd=path) - call("git add make_install_append", check=False, stderr=subprocess.DEVNULL, cwd=path) - call("git add prep_append", check=False, stderr=subprocess.DEVNULL, cwd=path) + call("git add prep_prepend", check=False, stderr=subprocess.DEVNULL, cwd=path) + call("git add build_prepend", check=False, stderr=subprocess.DEVNULL, cwd=path) + call("git add install_prepend", check=False, stderr=subprocess.DEVNULL, cwd=path) + call("git add install_append", check=False, stderr=subprocess.DEVNULL, cwd=path) call("git add series", check=False, stderr=subprocess.DEVNULL, cwd=path) call("bash -c 'shopt -s failglob; git add -f *.asc'", check=False, stderr=subprocess.DEVNULL, cwd=path) call("bash -c 'shopt -s failglob; git add -f *.sig'", check=False, stderr=subprocess.DEVNULL, cwd=path) @@ -78,6 +80,8 @@ def commit_to_git(path): call("git add description", check=False, stderr=subprocess.DEVNULL, cwd=path) # remove deprecated config files + call("git rm make_install_append", check=False, stderr=subprocess.DEVNULL, cwd=path) + call("git rm prep_append", check=False, stderr=subprocess.DEVNULL, cwd=path) call("git rm use_clang", check=False, stderr=subprocess.DEVNULL, cwd=path) call("git rm use_lto", check=False, stderr=subprocess.DEVNULL, cwd=path) call("git rm use_avx2", check=False, stderr=subprocess.DEVNULL, cwd=path) diff --git a/autospec/infile_update_spec.py b/autospec/infile_update_spec.py index 0143d1a..e8be6b2 100644 --- a/autospec/infile_update_spec.py +++ b/autospec/infile_update_spec.py @@ -27,9 +27,9 @@ cmd_mappings = { "do_configure_prepend": "configure", "do_configure_append": "configure", "EXTRA_OECONF": "configure", - "do_install": "make_install_append", - "do_install_append": "make_install_append", - "do_install_prepend": "make_install_append" + "do_install": "install_append", + "do_install_append": "install_append", + "do_install_prepend": "install_prepend" } diff --git a/autospec/specfiles.py b/autospec/specfiles.py index ddf1f6a..b6f91cc 100644 --- a/autospec/specfiles.py +++ b/autospec/specfiles.py @@ -66,7 +66,6 @@ class Specfile(object): self.rawname = "" self.golibpath = "" self.archive_details = {} - self.prep_append = [] self.need_avx2_flags = False self.need_avx512_flags = False self.tests_config = "" @@ -75,7 +74,10 @@ class Specfile(object): self.disable_static = "--disable-static" self.extra_cmake = "" self.cmake_srcdir = ".." - self.make_install_append = [] + self.prep_prepend = [] + self.build_prepend = [] + self.install_prepend = [] + self.install_append = [] self.excludes = [] self.keyid = "" self.email = "" @@ -298,7 +300,7 @@ class Specfile(object): pattern_method() self.write_source_installs() - self.write_make_install_append() + self.write_install_append() # self.write_systemd_units() def write_scriplets(self): @@ -353,6 +355,7 @@ class Specfile(object): def write_lang_c(self, export_epoch=False): """Write C language pattern""" self._write_strip("%build") + self.write_build_prepend() self.write_proxy_exports() self._write_strip("export LANG=C") if export_epoch: @@ -381,6 +384,7 @@ class Specfile(object): def write_prep(self, ruby_pattern=False): """Write prep section to spec file""" self._write_strip("%prep") + self.write_prep_prepend() if ruby_pattern: self._write_strip("gem unpack %{SOURCE0}") self._write_strip("%setup -q -D -T -n " + self.tarball_prefix) @@ -417,15 +421,6 @@ class Specfile(object): self._write_strip("cp -a {} buildavx512".format(self.tarball_prefix)) self._write_strip("popd") self._write_strip("\n") - self.write_prep_append() - - def write_prep_append(self): - """write out any custom supplied commands at the very end of the %prep section""" - if self.prep_append and self.prep_append[0]: - for line in self.prep_append: - self._write_strip("{}\n".format(line)) - - self._write_strip("\n") def write_variables(self): """Write variable exports to spec file""" @@ -517,6 +512,7 @@ class Specfile(object): def write_make_install(self): """Write install section to spec file for make builds""" self._write_strip("%install") + self.write_install_prepend() # time.time() returns a float, but we only need second-precision self._write_strip("export SOURCE_DATE_EPOCH={}".format(int(time.time()))) self._write_strip("rm -rf %{buildroot}") @@ -559,13 +555,37 @@ class Specfile(object): self.write_find_lang() - def write_make_install_append(self): - """write out any custom supplied commands at the very end of the %install section""" - if self.make_install_append and self.make_install_append[0]: - self._write_strip("## make_install_append content") - for line in self.make_install_append: + def write_prep_prepend(self): + """write out any custom supplied commands at the start of the %prep section""" + if self.prep_prepend: + self._write_strip("## prep_prepend content") + for line in self.prep_prepend: self._write_strip("{}\n".format(line)) - self._write_strip("## make_install_append end") + self._write_strip("## prep_prepend end") + + def write_build_prepend(self): + """write out any custom supplied commands at the start of the %build section""" + if self.build_prepend: + self._write_strip("## build_prepend content") + for line in self.build_prepend: + self._write_strip("{}\n".format(line)) + self._write_strip("## build_prepend end") + + def write_install_prepend(self): + """write out any custom supplied commands at the start of the %install section""" + if self.install_prepend: + self._write_strip("## install_prepend content") + for line in self.install_prepend: + self._write_strip("{}\n".format(line)) + self._write_strip("## install_prepend end") + + def write_install_append(self): + """write out any custom supplied commands at the very end of the %install section""" + if self.install_append: + self._write_strip("## install_append content") + for line in self.install_append: + self._write_strip("{}\n".format(line)) + self._write_strip("## install_append end") def write_source_installs(self): """write out installs from SourceX lines""" @@ -582,6 +602,7 @@ class Specfile(object): def write_cmake_install(self): """Write install section to spec file for cmake builds""" self._write_strip("%install") + self.write_install_prepend() self._write_strip("export SOURCE_DATE_EPOCH={}".format(int(time.time()))) self._write_strip("rm -rf %{buildroot}") @@ -937,6 +958,7 @@ class Specfile(object): self.write_proxy_exports() self._write_strip(self.tests_config) self._write_strip("%install") + self.write_install_prepend() self._write_strip("rm -rf %{buildroot}") if len(self.license_files) > 0: @@ -961,6 +983,7 @@ class Specfile(object): self.write_proxy_exports() self._write_strip(self.tests_config) self._write_strip("%install") + self.write_install_prepend() self._write_strip("rm -rf %{buildroot}") if len(self.license_files) > 0: @@ -990,6 +1013,7 @@ class Specfile(object): self._write_strip(self.tests_config) self._write_strip("%install") + self.write_install_prepend() self._write_strip("export SOURCE_DATE_EPOCH={}".format(int(time.time()))) self._write_strip("rm -rf %{buildroot}") @@ -1013,6 +1037,7 @@ class Specfile(object): self._write_strip("\n") self._write_strip("%install") + self.write_install_prepend() self._write_strip("rm -rf %{buildroot}") self._write_strip("export SOURCE_DATE_EPOCH={}".format(int(time.time()))) self._write_strip("export LANG=C") @@ -1073,12 +1098,14 @@ class Specfile(object): """Write build pattern for ruby packages""" self.write_prep(ruby_pattern=True) self._write_strip("%build") + self.write_build_prepend() self.write_proxy_exports() self._write_strip("export LANG=C") self._write_strip("gem build {}.gemspec".format(self.name)) self._write_strip("\n") self._write_strip("%install") + self.write_install_prepend() self._write_strip("%global gem_dir $(ruby -e'puts Gem.default_dir')") self._write_strip("gem install -V \\") self._write_strip(" --local \\") @@ -1177,6 +1204,7 @@ class Specfile(object): self.write_prep() self._write_strip("%build") + self.write_build_prepend() self.write_proxy_exports() self._write_strip("export LANG=C") self.write_variables() @@ -1200,6 +1228,7 @@ class Specfile(object): self.write_prep() src_dir = "/usr/share/rust/src/{0}".format(self.name) self._write_strip("%build") + self.write_build_prepend() self.write_proxy_exports() self._write_strip("mkdir .cargo") self._write("echo \"[source.crates-io]\nreplace-with = 'vendored-sources'\n[source.vendored-sources]\ndirectory = '{}'\" > .cargo/config\n".format(os.path.dirname(src_dir))) @@ -1211,17 +1240,18 @@ class Specfile(object): self._write_strip("cargo build --release") self._write_strip("\n") self._write_strip("%install") + self.write_install_prepend() if self.cargo_bin: self._write_strip("cargo install --frozen --root /") self._write_strip("cargo clean") self._write_strip("install -d -p %{buildroot}" + src_dir) self._write_strip("cp -a . %{buildroot}" + src_dir) - self.write_make_install_append() def write_cpan_pattern(self): """Write cpan build pattern to spec file""" self.write_prep() self._write_strip("%build") + self.write_build_prepend() self.write_proxy_exports() self._write_strip("export LANG=C") self._write_strip("if test -f Makefile.PL; then") @@ -1234,6 +1264,7 @@ class Specfile(object): self._write_strip("\n") self.write_check() self._write_strip("%install") + self.write_install_prepend() self._write_strip("rm -rf %{buildroot}") if len(self.license_files) > 0: self._write_strip("mkdir -p %{buildroot}/usr/share/doc/" + self.name) @@ -1255,12 +1286,14 @@ class Specfile(object): """Write scons build pattern to spec file""" self.write_prep() self._write_strip("%build") + self.write_build_prepend() self.write_proxy_exports() self._write_strip("export LANG=C") self.write_variables() self._write_strip("scons{} {}".format(config.parallel_build, config.extra_configure)) self._write_strip("\n") self._write_strip("%install") + self.write_install_prepend() self._write_strip("scons install " + self.extra_make_install) if len(self.license_files) > 0: self._write_strip("mkdir -p %{buildroot}/usr/share/doc/" + self.name) @@ -1272,12 +1305,14 @@ class Specfile(object): """Write build pattern for go packages""" self.write_prep() self._write_strip("%build") + self.write_build_prepend() self.write_proxy_exports() self._write_strip("export LANG=C") self._write_strip("export GOPATH=\"$PWD\"") self._write_strip("go build") self._write_strip("\n") self._write_strip("%install") + self.write_install_prepend() self._write_strip("rm -rf %{buildroot}") if len(self.license_files) > 0: self._write_strip("mkdir -p %{buildroot}/usr/share/doc/" + self.name) @@ -1292,10 +1327,12 @@ class Specfile(object): self.write_prep() self._write_strip("%build") + self.write_build_prepend() self.write_proxy_exports() self._write_strip("python3 /usr/share/java-utils/mvn_build.py " + self.extra_make) self._write_strip("\n") self._write_strip("%install") + self.write_install_prepend() self._write_strip("xmvn-install -R .xmvn-reactor -n {} -d %{{buildroot}}" .format(mvn)) @@ -1326,6 +1363,7 @@ class Specfile(object): self._write_strip("\n") self.write_check() self._write_strip("%install") + self.write_install_prepend() if len(self.license_files) > 0: self._write_strip("mkdir -p %{buildroot}/usr/share/doc/" + self.name) for file in self.license_files: