From d74eeb394155b199a81e8feee2163f3894d2509d Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Mon, 16 Nov 2020 11:19:19 -0500 Subject: [PATCH] MockModuleBuilder: Don't rewrite mock config to add SCM options When we want to pass in SCM options particular to a specific module build, do that on the mock command line rather than by modifying mock.cfg - this avoids invalidating the root cache. --- .../builder/MockModuleBuilder.py | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/module_build_service/builder/MockModuleBuilder.py b/module_build_service/builder/MockModuleBuilder.py index c4804b7c..d4a3d888 100644 --- a/module_build_service/builder/MockModuleBuilder.py +++ b/module_build_service/builder/MockModuleBuilder.py @@ -811,42 +811,44 @@ class SRPMBuilder(BaseBuilder): class SCMBuilder(BaseBuilder): def __init__(self, config, resultsdir, source, artifact_name): super(SCMBuilder, self).__init__(config, resultsdir) - with open(config, "a") as f: - repo_path, branch = source.split("?#") - distgit_cmds = self._get_distgit_commands(source) - # Supply the artifact name for "{0}" and the full path to the repo for "{repo_path}" - distgit_get = distgit_cmds[0].format(artifact_name, repo_path=repo_path) - # mock-scm cannot checkout particular commit hash, but only branch. - # We therefore use a command that combines the distgit-command with - # checking out a particular commit hash. - # See https://bugzilla.redhat.com/show_bug.cgi?id=1459437 for - # more info. Once mock-scm supports this feature, we can remove - # this code. - distgit_get_branch = "sh -c {}'; git -C {} checkout {}'".format( - pipes.quote(distgit_get), artifact_name, branch) + repo_path, branch = source.split("?#") + distgit_cmds = self._get_distgit_commands(source) + # Supply the artifact name for "{0}" and the full path to the repo for "{repo_path}" + distgit_get = distgit_cmds[0].format(artifact_name, repo_path=repo_path) - f.writelines([ - "config_opts['scm'] = True\n", - "config_opts['scm_opts']['method'] = 'distgit'\n", - "config_opts['scm_opts']['package'] = '{}'\n".format(artifact_name), - "config_opts['scm_opts']['distgit_get'] = {!r}\n".format(distgit_get_branch), - ]) + # mock-scm cannot checkout particular commit hash, but only branch. + # We therefore use a command that combines the distgit-command with + # checking out a particular commit hash. + # See https://bugzilla.redhat.com/show_bug.cgi?id=1459437 for + # more info. Once mock-scm supports this feature, we can remove + # this code. + distgit_get_branch = "sh -c {}'; git -C {} checkout {}'".format( + pipes.quote(distgit_get), artifact_name, branch) - # Set distgit_src_get only if it's defined. - if distgit_cmds[1]: - f.write( - "config_opts['scm_opts']['distgit_src_get'] = '{}'\n".format(distgit_cmds[1])) + scm_options = [ + ('method', 'distgit'), + ('package', artifact_name), + ('distgit_get', distgit_get_branch), + ] - # The local git repositories cloned by `fedpkg clone` typically do not have - # the tarballs with sources committed in a git repo. They normally live in lookaside - # cache on remote server, but we should not try getting them from there for true - # local builds. - # Instead, get them from local path with git repository by passing that path to Mock - # using the `ext_src_dir`. - if repo_path.startswith("file://"): - src_dir = repo_path[len("file://"):] - f.write("config_opts['scm_opts']['ext_src_dir'] = '{}'\n".format(src_dir)) + # Set distgit_src_get only if it's defined. + if distgit_cmds[1]: + scm_options.append(('distgit_src_get', distgit_cmds[1])) + + # The local git repositories cloned by `fedpkg clone` typically do not have + # the tarballs with sources committed in a git repo. They normally live in lookaside + # cache on remote server, but we should not try getting them from there for true + # local builds. + # Instead, get them from local path with git repository by passing that path to Mock + # using the `ext_src_dir`. + if repo_path.startswith("file://"): + src_dir = repo_path[len("file://"):] + scm_options.append(('ext_src_dir', src_dir)) + + self.cmd.append('--scm-enable') + for name, value in scm_options: + self.cmd.extend(('--scm-option', '{}={}'.format(name, value))) def _get_distgit_commands(self, source): for host, cmds in conf.distgits.items():