Skip to content

Commit

Permalink
Allow building by pointing to a local source on disk
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Sep 30, 2022
1 parent 7ca526a commit 90266cb
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
48 changes: 35 additions & 13 deletions obal/data/modules/srpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ def fetch_remote_sources(source_location, source_system, sources_dir):
zip_file.extract(zip_info, sources_dir)


def fetch_local_sources(source_location, sources_dir):
"""
Copy RPM sources from a local source on disk
"""
source_files = os.listdir(source_location)

for source in source_files:
shutil.copy(os.path.join(source_location, source), sources_dir)


def rpmbuild_command(base_dir, build_dir, sources_dir):
"""
Generate the base rpmbuild command
"""
command = ['rpmbuild', '-bs']
command += ['--define', '_topdir %s' % base_dir]
command += ['--define', '_sourcedir %s' % sources_dir]
command += ['--define', '_builddir %s' % build_dir]
command += ['--define', '_srcrpmdir %s' % base_dir]
command += ['--define', '_rpmdir %s' % base_dir]
command += ['--undefine', 'dist']

return command


def main():
"""
Build a package using tito
Expand Down Expand Up @@ -113,23 +138,20 @@ def main():
os.mkdir(build_dir)

if source_location:
try:
fetch_remote_sources(source_location, source_system, sources_dir)
except HTTPError as error:
module.fail_json(msg="HTTP %s: %s. Check %s exists." % (error.code, error.reason, source_location))
except KeyError as error:
module.fail_json(msg="Unknown source_system specified.", output=error)
if os.path.exists(source_location):
fetch_local_sources(source_location, sources_dir)
elif:
try:
fetch_remote_sources(source_location, source_system, sources_dir)
except HTTPError as error:
module.fail_json(msg="HTTP %s: %s. Check %s exists." % (error.code, error.reason, source_location))
except KeyError as error:
module.fail_json(msg="Unknown source_system specified.", output=error)

copy_sources(spec_file, package, sources_dir)
shutil.copy(spec_file, base_dir)

command = ['rpmbuild', '-bs']
command += ['--define', '_topdir %s' % base_dir]
command += ['--define', '_sourcedir %s' % sources_dir]
command += ['--define', '_builddir %s' % build_dir]
command += ['--define', '_srcrpmdir %s' % base_dir]
command += ['--define', '_rpmdir %s' % base_dir]
command += ['--undefine', 'dist']
command = rpmbuild_command(base_dir, build_dir, sources_dir)

if scl:
command += ['--define', 'scl %s' % scl]
Expand Down
6 changes: 6 additions & 0 deletions obal/data/playbooks/scratch/metadata.obal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ variables:
action: store_false
parameter: --skip-koji-whitelist-check
help: ignore koji whitelist check and scratch build the package anyway
source_location:
paramter: --source-location
help: Pass a path or URL to a location for the SRPM source.
source_system:
paramter: --source-system
help: If passing a URL to source-location, set this to the system being used (e.g. jenkins).
6 changes: 6 additions & 0 deletions obal/data/playbooks/srpm/metadata.obal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ variables:
build_srpm_output_dir:
parameter: --dir
help: Absolute path to output dir for SRPM. Defaults to <inventory_dir>/SRPMs
source_location:
paramter: --source-location
help: Pass a path or URL to a location for the SRPM source.
source_system:
paramter: --source-system
help: If passing a URL to source-location, set this to the system being used (e.g. jenkins).
7 changes: 7 additions & 0 deletions tests/fixtures/help/scratch.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
usage: obal scratch [-h] [-v] [-e EXTRA_VARS] [--skip-koji-whitelist-check]
[--source-location SOURCE_LOCATION]
[--source-system SOURCE_SYSTEM]
target [target ...]

Create a scratch build of a package
Expand All @@ -14,6 +16,11 @@ optional arguments:
--skip-koji-whitelist-check
ignore koji whitelist check and scratch build the
package anyway
--source-location SOURCE_LOCATION
Pass a path or URL to a location for the SRPM source.
--source-system SOURCE_SYSTEM
If passing a URL to source-location, set this to the
system being used (e.g. jenkins).

advanced arguments:
-e EXTRA_VARS, --extra-vars EXTRA_VARS
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/help/srpm.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
usage: obal srpm [-h] [-v] [-e EXTRA_VARS] [--dist BUILD_SRPM_DIST]
[--dir BUILD_SRPM_OUTPUT_DIR] [--scl BUILD_SRPM_SCL]
[--source-location SOURCE_LOCATION]
[--source-system SOURCE_SYSTEM]
target [target ...]

Build a SRPM for packages
Expand All @@ -18,6 +20,11 @@ optional arguments:
Absolute path to output dir for SRPM. Defaults to
<inventory_dir>/SRPMs
--scl BUILD_SRPM_SCL SCL to set when building a SRPM
--source-location SOURCE_LOCATION
Pass a path or URL to a location for the SRPM source.
--source-system SOURCE_SYSTEM
If passing a URL to source-location, set this to the
system being used (e.g. jenkins).

advanced arguments:
-e EXTRA_VARS, --extra-vars EXTRA_VARS
Expand Down

0 comments on commit 90266cb

Please sign in to comment.