Skip to content

Commit

Permalink
Ignore recipe in defaults-*.sh to match old behaviour (#821)
Browse files Browse the repository at this point in the history
* Ignore recipe in defaults-*.sh to match old behaviour

To match hashes of the "defaults-release" package to previous alibuild
versions, the recipe needs to be blank.

Warn the user if any ignored recipe is found. Recipes consisting only of
comment lines don't trigger this warning.

* Test defaults recipe behaviour
  • Loading branch information
TimoWilken authored Dec 12, 2023
1 parent 53558b8 commit 833dd30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 11 additions & 3 deletions alibuild_helpers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from alibuild_helpers.cmd import decode_with_fallback, getoutput
from alibuild_helpers.git import git
from alibuild_helpers.log import dieOnError
from alibuild_helpers.log import warning, dieOnError


class SpecError(Exception):
Expand Down Expand Up @@ -383,10 +383,18 @@ def getPackageList(packages, specs, configDir, preferSystem, noSystem,
dieOnError(spec["package"].lower() != pkg_filename,
"%s.sh has different package field: %s" % (p, spec["package"]))

# Re-rewrite the defaults' name to "defaults-release". Everything auto-
# depends on "defaults-release", so we need something with that name.
if p == "defaults-release":
# Re-rewrite the defaults' name to "defaults-release". Everything auto-
# depends on "defaults-release", so we need something with that name.
spec["package"] = "defaults-release"

# Never run the defaults' recipe, to match previous behaviour.
# Warn if a non-trivial recipe is found (i.e., one with any non-comment lines).
for line in map(str.strip, recipe.splitlines()):
if line and not line.startswith("#"):
warning("%s.sh contains a recipe, which will be ignored", pkg_filename)
recipe = ""

dieOnError(spec["package"] != p,
"%s should be spelt %s." % (p, spec["package"]))

Expand Down
11 changes: 9 additions & 2 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package: defaults-release
version: v1
---
: this line should trigger a warning
"""
TEST_DEFAULT_RELEASE_BUILD_HASH = "27ce49698e818e8efb56b6eff6dd785e503df341"

Expand Down Expand Up @@ -206,6 +207,7 @@ class BuildTestCase(unittest.TestCase):
@patch("alibuild_helpers.build.sys")
@patch("alibuild_helpers.build.dieOnError", new=MagicMock())
@patch("alibuild_helpers.utilities.dieOnError", new=MagicMock())
@patch("alibuild_helpers.utilities.warning")
@patch("alibuild_helpers.build.readDefaults",
new=MagicMock(return_value=(OrderedDict({"package": "defaults-release", "disable": []}), "")))
@patch("alibuild_helpers.build.makedirs", new=MagicMock(return_value=None))
Expand All @@ -225,9 +227,10 @@ class BuildTestCase(unittest.TestCase):
@patch("alibuild_helpers.workarea.is_writeable", new=MagicMock(return_value=True))
@patch("alibuild_helpers.build.basename", new=MagicMock(return_value="aliBuild"))
@patch("alibuild_helpers.build.install_wrapper_script", new=MagicMock())
def test_coverDoBuild(self, mock_debug, mock_glob, mock_sys, mock_git_git):
def test_coverDoBuild(self, mock_debug, mock_glob, mock_warning, mock_sys, mock_git_git):
mock_git_git.side_effect = dummy_git
mock_debug.side_effect = lambda *args: None
mock_warning.side_effect = lambda *args: None
mock_glob.side_effect = lambda x: {
"*": ["zlib"],
"/sw/TARS/osx_x86-64/defaults-release/defaults-release-v1-*.osx_x86-64.tar.gz": ["/sw/TARS/osx_x86-64/defaults-release/defaults-release-v1-1.osx_x86-64.tar.gz"],
Expand Down Expand Up @@ -286,18 +289,22 @@ def test_coverDoBuild(self, mock_debug, mock_glob, mock_sys, mock_git_git):

mock_git_git.reset_mock()
mock_debug.reset_mock()
mock_warning.reset_mock()
exit_code = doBuild(args, mock_parser)
self.assertEqual(exit_code, 0)
mock_warning.assert_called_with("%s.sh contains a recipe, which will be ignored", "defaults-release")
mock_debug.assert_called_with("Everything done")
self.assertEqual(mock_git_git.call_count, len(common_calls))
mock_git_git.assert_has_calls(common_calls, any_order=True)

# Force fetching repos
mock_git_git.reset_mock()
mock_debug.reset_mock()
mock_warning.reset_mock()
args.fetchRepos = True
exit_code = doBuild(args, mock_parser)
self.assertEqual(exit_code, 0)
mock_warning.assert_called_with("%s.sh contains a recipe, which will be ignored", "defaults-release")
mock_debug.assert_called_with("Everything done")
mock_glob.assert_called_with("/sw/TARS/osx_x86-64/ROOT/ROOT-v6-08-30-*.osx_x86-64.tar.gz")
# We can't compare directly against the list of calls here as they
Expand All @@ -311,7 +318,7 @@ def setup_spec(self, script):
"""Parse the alidist recipe in SCRIPT and return its spec."""
err, spec, recipe = parseRecipe(lambda: script)
self.assertIsNone(err)
spec["recipe"] = recipe.strip("\n")
spec["recipe"] = "" if spec["package"].startswith("defaults-") else recipe.strip("\n")
spec.setdefault("tag", spec["version"])
spec["tag"] = resolve_tag(spec)
return spec
Expand Down

0 comments on commit 833dd30

Please sign in to comment.