Skip to content

Commit 4f90794

Browse files
bryteisephmccarty
authored andcommitted
Move target directory to Config
Many different components require the target download path and it is needed early. Previously code existed to attempt to autodetect its location and so defining the path was enforced later in the build process. This created problems with ordering functions based on this requirement but since the target path is now certain to be defined at startup (due to previous changes) we can better align the location and initialization of the data to the Config class. As part of this change also avoid requiring the temporary working directory to be setup as part of the Build class. This is done as a cleanup due to the only real user of this location being the Content class. This also drops the stand-alone pkg_integrety main function that was initially used as a one off test to avoid needing to run autospec to validate the integrity of a package. This feature was seldom used and doesn't function well without handling configuration so it was dropped.
1 parent f72b990 commit 4f90794

19 files changed

+371
-417
lines changed

autospec/autospec.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def main():
241241
"even number of arguments"))
242242

243243
if args.prep_only:
244+
os.makedirs("workingdir", exists_ok=True)
244245
package(args, url, name, archives, "./workingdir", infile_dict)
245246
else:
246247
with tempfile.TemporaryDirectory() as workingdir:
@@ -249,25 +250,25 @@ def main():
249250

250251
def package(args, url, name, archives, workingdir, infile_dict):
251252
"""Entry point for building a package with autospec."""
252-
conf = config.Config()
253+
conf = config.Config(args.target)
253254
check_requirements(args.git)
254-
package = build.Build(workingdir)
255+
package = build.Build()
255256

256257
#
257258
# First, download the tarball, extract it and then do a set
258259
# of static analysis on the content of the tarball.
259260
#
260261
filemanager = files.FileManager(conf, package)
261-
content = tarball.Content(url, name, args.version, archives, conf)
262-
content.process(args.target, filemanager)
263-
conf.create_versions(package.download_path, content.multi_version)
262+
content = tarball.Content(url, name, args.version, archives, conf, workingdir)
263+
content.process(filemanager)
264+
conf.create_versions(content.multi_version)
264265
conf.content = content # hack to avoid recursive dependency on init
265266
# Search up one level from here to capture multiple versions
266267
_dir = content.path
267268

268269
if args.license_only:
269270
try:
270-
with open(os.path.join(package.download_path,
271+
with open(os.path.join(conf.download_path,
271272
content.name + ".license"), "r") as dotlic:
272273
for word in dotlic.read().split():
273274
if ":" not in word:
@@ -282,20 +283,20 @@ def package(args, url, name, archives, workingdir, infile_dict):
282283
conf.config_file = args.config
283284
requirements = buildreq.Requirements(content.url)
284285
requirements.set_build_req()
285-
conf.parse_config_files(package.download_path, args.bump, filemanager, content.version, requirements)
286+
conf.parse_config_files(args.bump, filemanager, content.version, requirements)
286287
conf.setup_patterns(conf.failed_pattern_dir)
287-
conf.parse_existing_spec(package.download_path, content.name)
288+
conf.parse_existing_spec(content.name)
288289

289290
if args.prep_only:
290291
write_prep(conf, workingdir, content)
291292
exit(0)
292293

293-
requirements.scan_for_configure(_dir, content.name, package.download_path, conf)
294+
requirements.scan_for_configure(_dir, content.name, conf)
294295
specdescription.scan_for_description(content.name, _dir, conf.license_translations, conf.license_blacklist)
295296
# Start one directory higher so we scan *all* versions for licenses
296297
license.scan_for_licenses(os.path.dirname(_dir), conf, content.name)
297-
commitmessage.scan_for_changes(package.download_path, _dir, conf.transforms)
298-
add_sources(package.download_path, archives, content)
298+
commitmessage.scan_for_changes(conf.download_path, _dir, conf.transforms)
299+
add_sources(conf.download_path, archives, content)
299300
check.scan_for_tests(_dir, conf, requirements, content)
300301

301302
#
@@ -323,14 +324,14 @@ def package(args, url, name, archives, workingdir, infile_dict):
323324

324325
if args.integrity:
325326
interactive_mode = not args.non_interactive
326-
pkg_integrity.check(url, package.download_path, conf, interactive=interactive_mode)
327+
pkg_integrity.check(url, conf, interactive=interactive_mode)
327328
pkg_integrity.load_specfile(specfile)
328329

329-
specfile.write_spec(package.download_path)
330+
specfile.write_spec()
330331
while 1:
331332
package.package(filemanager, args.mock_config, args.mock_opts, conf, requirements, content, args.cleanup)
332333
filemanager.load_specfile(specfile)
333-
specfile.write_spec(package.download_path)
334+
specfile.write_spec()
334335
filemanager.newfiles_printed = 0
335336
mock_chroot = "/var/lib/mock/clear-{}/root/builddir/build/BUILDROOT/" \
336337
"{}-{}-{}.x86_64".format(package.uniqueext,
@@ -344,12 +345,12 @@ def package(args, url, name, archives, workingdir, infile_dict):
344345
if package.round > 20 or package.must_restart == 0:
345346
break
346347

347-
save_mock_logs(package.download_path, package.round)
348+
save_mock_logs(conf.download_path, package.round)
348349

349-
check.check_regression(package.download_path, conf.config_opts['skip_tests'])
350+
check.check_regression(conf.download_path, conf.config_opts['skip_tests'])
350351

351352
if package.success == 0:
352-
conf.create_buildreq_cache(package.download_path, content.version, requirements.buildreqs_cache)
353+
conf.create_buildreq_cache(content.version, requirements.buildreqs_cache)
353354
print_fatal("Build failed, aborting")
354355
sys.exit(1)
355356
elif os.path.isfile("README.clear"):
@@ -363,20 +364,20 @@ def package(args, url, name, archives, workingdir, infile_dict):
363364
except Exception:
364365
pass
365366

366-
examine_abi(package.download_path, content.name)
367+
examine_abi(conf.download_path, content.name)
367368
if os.path.exists("/var/lib/rpm"):
368369
pkg_scan.get_whatrequires(content.name, conf.yum_conf)
369370

370-
write_out(package.download_path + "/release", content.release + "\n")
371+
write_out(conf.download_path + "/release", content.release + "\n")
371372

372373
# record logcheck output
373-
logcheck(package.download_path)
374+
logcheck(conf.download_path)
374375

375-
commitmessage.guess_commit_message(pkg_integrity.IMPORTED, conf, content, package)
376-
conf.create_buildreq_cache(package.download_path, content.version, requirements.buildreqs_cache)
376+
commitmessage.guess_commit_message(pkg_integrity.IMPORTED, conf, content)
377+
conf.create_buildreq_cache(content.version, requirements.buildreqs_cache)
377378

378379
if args.git:
379-
git.commit_to_git(package.download_path, conf, content.name, package.success)
380+
git.commit_to_git(conf, content.name, package.success)
380381
else:
381382
print("To commit your changes, git add the relevant files and "
382383
"run 'git commit -F commitmsg'")

autospec/build.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,11 @@ def get_mock_cmd():
8282
class Build(object):
8383
"""Manage package builds."""
8484

85-
def __init__(self, base_path):
85+
def __init__(self):
8686
"""Initialize default build settings."""
8787
self.success = 0
8888
self.round = 0
8989
self.must_restart = 0
90-
self.base_path = base_path
91-
self.download_path = None
9290
self.uniqueext = ''
9391
self.warned_about = set()
9492

@@ -272,8 +270,8 @@ def package(self, filemanager, mockconfig, mockopts, config, requirements, conte
272270
print("{} mock chroot at /var/lib/mock/clear-{}".format(content.name, self.uniqueext))
273271

274272
if self.round == 1:
275-
shutil.rmtree('{}/results'.format(self.download_path), ignore_errors=True)
276-
os.makedirs('{}/results'.format(self.download_path))
273+
shutil.rmtree('{}/results'.format(config.download_path), ignore_errors=True)
274+
os.makedirs('{}/results'.format(config.download_path))
277275

278276
cmd_args = [
279277
mock_cmd,
@@ -287,12 +285,12 @@ def package(self, filemanager, mockconfig, mockopts, config, requirements, conte
287285
mockopts,
288286
]
289287
util.call(" ".join(cmd_args),
290-
logfile=f"{self.download_path}/results/mock_srpm.log",
291-
cwd=self.download_path)
288+
logfile=f"{config.download_path}/results/mock_srpm.log",
289+
cwd=config.download_path)
292290

293291
# back up srpm mock logs
294-
util.call("mv results/root.log results/srpm-root.log", cwd=self.download_path)
295-
util.call("mv results/build.log results/srpm-build.log", cwd=self.download_path)
292+
util.call("mv results/root.log results/srpm-root.log", cwd=config.download_path)
293+
util.call("mv results/build.log results/srpm-build.log", cwd=config.download_path)
296294

297295
srcrpm = f"results/{content.name}-{content.version}-{content.release}.src.rpm"
298296

@@ -307,18 +305,18 @@ def package(self, filemanager, mockconfig, mockopts, config, requirements, conte
307305
mockopts,
308306
]
309307
ret = util.call(" ".join(cmd_args),
310-
logfile=f"{self.download_path}/results/mock_build.log",
308+
logfile=f"{config.download_path}/results/mock_build.log",
311309
check=False,
312-
cwd=self.download_path)
310+
cwd=config.download_path)
313311

314312
# sanity check the build log
315-
if not os.path.exists(self.download_path + "/results/build.log"):
313+
if not os.path.exists(config.download_path + "/results/build.log"):
316314
util.print_fatal("Mock command failed, results log does not exist. User may not have correct permissions.")
317315
exit(1)
318316

319-
is_clean = self.parse_buildroot_log(self.download_path + "/results/root.log", ret)
317+
is_clean = self.parse_buildroot_log(config.download_path + "/results/root.log", ret)
320318
if is_clean:
321-
self.parse_build_results(self.download_path + "/results/build.log", ret, filemanager, config, requirements, content)
319+
self.parse_build_results(config.download_path + "/results/build.log", ret, filemanager, config, requirements, content)
322320
if filemanager.has_banned:
323321
util.print_fatal("Content in banned paths found, aborting build")
324322
exit(1)

autospec/buildreq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ def parse_catkin_deps(self, cmakelists_file, conf32):
750750
self.extra_cmake.add("-DCATKIN_BUILD_BINARY_PACKAGE=ON")
751751
self.extra_cmake.add("-DSETUPTOOLS_DEB_LAYOUT=OFF")
752752

753-
def scan_for_configure(self, dirn, tname, dlpath, config):
753+
def scan_for_configure(self, dirn, tname, config):
754754
"""Scan the package directory for build files to determine build pattern."""
755755
if buildpattern.default_pattern == "distutils36":
756756
self.add_buildreq("buildreq-distutils36")
@@ -876,7 +876,7 @@ def scan_for_configure(self, dirn, tname, dlpath, config):
876876
if buildpattern.default_pattern == "distutils3":
877877
# First look for a local override
878878
pypi_json = ""
879-
pypi_file = os.path.join(dlpath, "pypi.json")
879+
pypi_file = os.path.join(config.download_path, "pypi.json")
880880
if os.path.isfile(pypi_file):
881881
with open(pypi_file, "r") as pfile:
882882
pypi_json = pfile.read()

autospec/commitmessage.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def process_git(giturl, oldversion, newversion, name):
216216
return shortlog
217217

218218

219-
def guess_commit_message(keyinfo, config, content, package):
219+
def guess_commit_message(keyinfo, config, content):
220220
"""Parse newsfile for a commit message.
221221
222222
Try and find a sane commit message for the newsfile. The commit message defaults to the
@@ -268,14 +268,14 @@ def guess_commit_message(keyinfo, config, content, package):
268268
newsfiles = ["NEWS", "ChangeLog"]
269269
for newsfile in newsfiles:
270270
# parse news files for relevant version updates and cve fixes
271-
newcommitmessage, newcves = process_NEWS(newsfile, config.old_version, content.name, content.version, package.download_path)
271+
newcommitmessage, newcves = process_NEWS(newsfile, config.old_version, content.name, content.version, config.download_path)
272272
commitmessage.extend(newcommitmessage)
273273
cves.update(newcves)
274274

275275
if cves:
276276
# make the package security sensitive if a CVE was patched
277277
config.config_opts['security_sensitive'] = True
278-
config.rewrite_config_opts(package.base_path)
278+
config.rewrite_config_opts()
279279
# append CVE fixes to end of commit message
280280
commitmessage.append("CVEs fixed in this build:")
281281
commitmessage.extend(sorted(list(cves)))
@@ -284,7 +284,7 @@ def guess_commit_message(keyinfo, config, content, package):
284284
if keyinfo:
285285
commitmessage.append("Key imported:\n{}".format(keyinfo))
286286

287-
util.write_out(os.path.join(package.download_path, "commitmsg"),
287+
util.write_out(os.path.join(config.download_path, "commitmsg"),
288288
"\n".join(commitmessage) + "\n")
289289

290290
print("Guessed commit message:")

0 commit comments

Comments
 (0)