diff --git a/spec/plans/discover.fmf b/spec/plans/discover.fmf index 87d9cc37fd..d96cf4d75c 100644 --- a/spec/plans/discover.fmf +++ b/spec/plans/discover.fmf @@ -259,7 +259,8 @@ description: | Patches are applied by ``rpm-build -bp`` command which runs in ``prepare`` step on the provisioned guest, with - order ``60``. + order ``60``. All created files and directories by this command + are directly in ``TMT_SOURCE_DIR``. .. versionadded:: 1.32 diff --git a/tests/discover/data/demo.spec b/tests/discover/data/demo.spec index 733899c8f3..03d6ebfd19 100644 --- a/tests/discover/data/demo.spec +++ b/tests/discover/data/demo.spec @@ -11,6 +11,8 @@ Some tests are being added by patches, lets discover them correctly %prep %autosetup -n package-src +%build + %install %changelog diff --git a/tests/discover/distgit.sh b/tests/discover/distgit.sh index 9e2cc24061..8585671b8f 100755 --- a/tests/discover/distgit.sh +++ b/tests/discover/distgit.sh @@ -454,19 +454,27 @@ EOF ### discover -h shell ### - rlPhaseStartTest "Shell always merges the plan's git" - rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory" - rlRun 'pushd $tmp' + for build_phase in 'no' 'has'; do + rlPhaseStartTest "Shell always merges the plan's git ($build_phase %build phase in spec)" + rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory" + rlRun 'pushd $tmp' - rlRun "git init" - echo no-tmt-2.tgz > $MOCK_SOURCES_FILENAME - sed -e '/^BuildArch:/aSource0: no-tmt-2.tgz' $TEST_DIR/data/demo.spec > demo.spec - sed -e 's/package-src/no-tmt-2/' -i demo.spec + rlRun "git init" + echo no-tmt-2.tgz > $MOCK_SOURCES_FILENAME + sed -e '/^BuildArch:/aSource0: no-tmt-2.tgz' $TEST_DIR/data/demo.spec > demo.spec + sed -e 's/package-src/no-tmt-2/' -i demo.spec - rlRun "tmt init" - # TODO try again with cd \$TMT_SOURCE_DIR/no-tmt-* - # Fails after the rename - cat < plans.fmf + if [ "$build_phase" == "no" ]; then + sed -e '/%build/d' -i demo.spec + rlAssertNotGrep '%build' demo.spec + else + rlAssertGrep '%build' demo.spec + fi + + rlRun "tmt init" + # TODO try again with cd \$TMT_SOURCE_DIR/no-tmt-* + # Fails after the rename + cat < plans.fmf discover: how: shell tests: @@ -488,19 +496,19 @@ execute: how: tmt EOF - WORKDIR=/var/tmp/tmt/XXX - WORKDIR_SOURCE=$WORKDIR/plans/discover/default-0/source - - rlRun -s "tmt run --keep --id $WORKDIR --scratch -vvv" + WORKDIR=/var/tmp/tmt/XXX + WORKDIR_SOURCE=$WORKDIR/plans/discover/default-0/source - # Source dir has everything available - rlAssertExists $WORKDIR_SOURCE/no-tmt-2/all_in_one - rlAssertExists $WORKDIR_SOURCE/no-tmt-2.tgz + rlRun -s "tmt run --keep --id $WORKDIR --scratch -vvv" - rlRun "popd" - rlRun "rm -rf $tmp" - rlPhaseEnd + # Source dir has everything available + rlAssertExists $WORKDIR_SOURCE/no-tmt-2/all_in_one + rlAssertExists $WORKDIR_SOURCE/no-tmt-2.tgz + rlRun "popd" + rlRun "rm -rf $tmp" + rlPhaseEnd + done rlPhaseStartTest "shell with download-only" rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory" rlRun 'pushd $tmp' diff --git a/tmt/steps/prepare/distgit.py b/tmt/steps/prepare/distgit.py index 1afeb1cbc8..a7211952cf 100644 --- a/tmt/steps/prepare/distgit.py +++ b/tmt/steps/prepare/distgit.py @@ -10,7 +10,7 @@ from tmt.package_managers import Package from tmt.steps.prepare import PreparePlugin, _RawPrepareStepData from tmt.steps.provision import Guest -from tmt.utils import Command, Path, field, uniq +from tmt.utils import Command, Path, ShellScript, field, uniq if TYPE_CHECKING: import tmt.base @@ -148,8 +148,9 @@ class PrepareDistGit(tmt.steps.prepare.PreparePlugin[DistGitData]): Step is responsible: 1. Install required packages for the rpmbuild itself 2. Detect and install build requires - 3. Patch sources - 3. Call function of discover plugin to discover tests from patched sources + 3. Patch sources (rpmbuild -bp) + 4. Move patched sources from buildroot into TMT_SOURCE_DIR + 5. Call function of discover plugin to discover tests from TMT_SOURCE_DIR """ _data_class = DistGitData @@ -246,6 +247,31 @@ def go( except tmt.utils.RunError as error: raise tmt.utils.PrepareError("Unable to 'rpmbuild -bp'.", causes=[error]) + # Workaround around new rpm behavior, https://github.com/teemtee/tmt/issues/2987 + # No hardcoded name, should keep working in the future + cmd = Command( + "rpmbuild", + "-bc", + "--short-circuit", + "--nodeps", + "--define", + '__spec_build_pre echo tmt-get-builddir=%{_builddir}; exit 0', + spec_name, + *dir_defines) + outcome = guest.execute(command=cmd, cwd=source_dir).stdout or '' + match = re.search(r'tmt-get-builddir=(.+)', outcome) + builddir = Path(match.group(1)) if match else None + + # But if the %build is missing in spec (e.g. in our test) the previous output was empty + if builddir is None: + guest.execute(command=ShellScript( + "shopt -s dotglob; if test -e */SPECPARTS; then mv ./*-build/* .; else true; fi"), + cwd=source_dir) + elif builddir.resolve() != source_dir.resolve(): + guest.execute(command=ShellScript(f"shopt -s dotglob; mv {builddir}/* {source_dir}")) + else: + self.debug("Builddir matches source_dir, no need to copy anything.") + # Make sure to pull back sources ... # FIXME -- Do we need to? Can be lot of data... guest.pull(source_dir)