Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 38 additions & 13 deletions obal/data/modules/srpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ 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
"""
if os.path.isdir(source_location):
source_files = os.listdir(source_location)

for source in source_files:
shutil.copy(os.path.join(source_location, source), sources_dir)
else:
shutil.copy(source_location, 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 +141,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)
else:
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).
4 changes: 4 additions & 0 deletions obal/data/roles/build_srpm/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---
- name: 'Before SRPM'
debug:
msg: "Before"

- name: 'Build SRPM'
srpm:
package: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
Expand Down
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