diff --git a/obal/data/modules/srpm.py b/obal/data/modules/srpm.py index ed649c24..0afcfdfa 100644 --- a/obal/data/modules/srpm.py +++ b/obal/data/modules/srpm.py @@ -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 @@ -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] diff --git a/obal/data/playbooks/scratch/metadata.obal.yaml b/obal/data/playbooks/scratch/metadata.obal.yaml index 9e00308f..a6af6025 100644 --- a/obal/data/playbooks/scratch/metadata.obal.yaml +++ b/obal/data/playbooks/scratch/metadata.obal.yaml @@ -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). diff --git a/obal/data/playbooks/srpm/metadata.obal.yaml b/obal/data/playbooks/srpm/metadata.obal.yaml index 3d7815d4..4cae4a35 100644 --- a/obal/data/playbooks/srpm/metadata.obal.yaml +++ b/obal/data/playbooks/srpm/metadata.obal.yaml @@ -13,3 +13,9 @@ variables: build_srpm_output_dir: parameter: --dir help: Absolute path to output dir for SRPM. Defaults to /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). diff --git a/obal/data/roles/build_srpm/tasks/main.yaml b/obal/data/roles/build_srpm/tasks/main.yaml index dbc81b10..2b63dfd3 100644 --- a/obal/data/roles/build_srpm/tasks/main.yaml +++ b/obal/data/roles/build_srpm/tasks/main.yaml @@ -1,4 +1,8 @@ --- +- name: 'Before SRPM' + debug: + msg: "Before" + - name: 'Build SRPM' srpm: package: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}" diff --git a/tests/fixtures/help/scratch.txt b/tests/fixtures/help/scratch.txt index 0288597c..1efeee06 100644 --- a/tests/fixtures/help/scratch.txt +++ b/tests/fixtures/help/scratch.txt @@ -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 @@ -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 diff --git a/tests/fixtures/help/srpm.txt b/tests/fixtures/help/srpm.txt index a900c589..2a63c0db 100644 --- a/tests/fixtures/help/srpm.txt +++ b/tests/fixtures/help/srpm.txt @@ -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 @@ -18,6 +20,11 @@ optional arguments: Absolute path to output dir for SRPM. Defaults to /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