diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 3918bea8..9b9173bb 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -34,10 +34,10 @@ pmaports_min_version = "7" # Version of the work folder (as asked during 'pmbootstrap init'). Increase # this number, whenever migration is required and provide the migration code, # see migrate_work_folder()). -work_version = 5 +work_version = 6 # Minimum required version of postmarketos-ondev (pmbootstrap install --ondev). -# Try to support the current versions of all channels (edge, stable). When +# Try to support the current versions of all channels (edge, v21.03). When # bumping > 0.4.0, remove compat code in pmb/install/_install.py (search for # get_ondev_pkgver). ondev_min_version = "0.2.0" @@ -138,6 +138,9 @@ locales = [ ] +# Legacy channels and their new names (pmb#2015) +pmaports_channels_legacy = {"stable": "v20.05", + "stable-next": "v21.03"} # # CHROOT # @@ -165,7 +168,7 @@ chroot_host_path = os.environ["PATH"] + ":/usr/sbin/" # Folders, that get mounted inside the chroot # $WORK gets replaced with args.work # $ARCH gets replaced with the chroot architecture (eg. x86_64, armhf) -# $CHANNEL gets replaced with the release channel (e.g. edge, stable) +# $CHANNEL gets replaced with the release channel (e.g. edge, v21.03) chroot_mount_bind = { "/proc": "/proc", "$WORK/cache_apk_$ARCH": "/var/cache/apk", diff --git a/pmb/config/init.py b/pmb/config/init.py index d75f6f1e..2efc9c0f 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -80,7 +80,7 @@ def ask_for_channel(args): """ Ask for the postmarketOS release channel. The channel dictates, which pmaports branch pmbootstrap will check out, and which repository URLs will be used when initializing chroots. - :returns: channel name (e.g. "edge", "stable") """ + :returns: channel name (e.g. "edge", "v21.03") """ channels_cfg = pmb.helpers.git.parse_channels_cfg(args) count = len(channels_cfg["channels"]) diff --git a/pmb/config/pmaports.py b/pmb/config/pmaports.py index f4d06141..175b8f94 100644 --- a/pmb/config/pmaports.py +++ b/pmb/config/pmaports.py @@ -6,6 +6,7 @@ import os import pmb.config import pmb.helpers.git +import pmb.helpers.pmaports def check_legacy_folder(): @@ -107,6 +108,9 @@ def read_config(args): check_version_pmaports(ret["version"]) check_version_pmbootstrap(ret["pmbootstrap_min_version"]) + # Translate legacy channel names + ret["channel"] = pmb.helpers.pmaports.get_channel_new(ret["channel"]) + # Cache and return args.cache[cache_key] = ret return ret @@ -153,7 +157,7 @@ def init(args): def switch_to_channel_branch(args, channel_new): """ Checkout the channel's branch in pmaports.git. - :channel_new: channel name (e.g. "edge", "stable") + :channel_new: channel name (e.g. "edge", "v21.03") :returns: True if another branch was checked out, False otherwise """ # Check current pmaports branch channel channel_current = read_config(args)["channel"] diff --git a/pmb/helpers/git.py b/pmb/helpers/git.py index 32ca4129..93e9571f 100644 --- a/pmb/helpers/git.py +++ b/pmb/helpers/git.py @@ -8,6 +8,7 @@ import time import pmb.build import pmb.chroot.apk import pmb.config +import pmb.helpers.pmaports import pmb.helpers.run @@ -138,11 +139,13 @@ def parse_channels_cfg(args): if channel == "channels.cfg": continue # meta section - ret["channels"][channel] = {} + channel_new = pmb.helpers.pmaports.get_channel_new(channel) + + ret["channels"][channel_new] = {} for key in ["description", "branch_pmaports", "branch_aports", "mirrordir_alpine"]: value = cfg.get(channel, key) - ret["channels"][channel][key] = value + ret["channels"][channel_new][key] = value args.cache[cache_key] = ret return ret diff --git a/pmb/helpers/other.py b/pmb/helpers/other.py index b5b633b0..58726756 100644 --- a/pmb/helpers/other.py +++ b/pmb/helpers/other.py @@ -199,6 +199,34 @@ def migrate_work_folder(args): migrate_success(args, 5) current = 5 + if current == 5: + # Ask for confirmation + logging.info("Changelog:") + logging.info("* besides edge, pmaports channels have the same name") + logging.info(" as the branch now (pmbootstrap#2015)") + logging.info("Migration will do the following:") + logging.info("* Zap your chroots") + logging.info("* Adjust subdirs of your locally built packages dir:") + logging.info(f" {args.work}/packages") + logging.info(" stable => v20.05") + logging.info(" stable-next => v21.03") + if not pmb.helpers.cli.confirm(args): + raise RuntimeError("Aborted.") + + # Zap chroots to avoid potential "ERROR: Chroot 'native' was created + # for the 'stable' channel, but you are on the 'v20.05' channel now." + pmb.chroot.zap(args, False) + + # Migrate + packages_dir = f"{args.work}/packages" + for old, new in pmb.config.pmaports_channels_legacy.items(): + if os.path.exists(f"{packages_dir}/{old}"): + pmb.helpers.run.root(args, ["mv", old, new], packages_dir) + + # Update version file + migrate_success(args, 6) + current = 6 + # Can't migrate, user must delete it if current != required: raise RuntimeError("Sorry, we can't migrate that automatically. Please" diff --git a/pmb/helpers/pmaports.py b/pmb/helpers/pmaports.py index cc81a7a6..f34616b6 100644 --- a/pmb/helpers/pmaports.py +++ b/pmb/helpers/pmaports.py @@ -222,3 +222,19 @@ def check_arches(arches, arch): if value in arches: return True return False + + +def get_channel_new(channel): + """ Translate legacy channel names to the new ones. Legacy names are still + supported for compatibility with old branches (pmb#2015). + :param channel: name as read from pmaports.cfg or channels.cfg, like + "edge", "v21.03" etc., or potentially a legacy name + like "stable". + :returns: name in the new format, e.g. "edge" or "v21.03" + """ + legacy_cfg = pmb.config.pmaports_channels_legacy + if channel in legacy_cfg: + ret = legacy_cfg[channel] + logging.verbose(f"Legacy channel '{channel}' translated to '{ret}'") + return ret + return channel diff --git a/test/test_config_pmaports.py b/test/test_config_pmaports.py index 98acccf4..8e357a25 100644 --- a/test/test_config_pmaports.py +++ b/test/test_config_pmaports.py @@ -39,13 +39,13 @@ def test_switch_to_channel_branch(args, monkeypatch, tmpdir): # Fail: git error (could be any error, but here: branch does not exist) with pytest.raises(RuntimeError) as e: - func(args, "stable") + func(args, "v20.05") assert str(e.value).startswith("Failed to switch branch") # Success: switch channel and change branch run_git(["checkout", "-b", "v20.05"]) run_git(["checkout", "master"]) - assert func(args, "stable") is True + assert func(args, "v20.05") is True branch = pmb.helpers.git.rev_parse(args, path, extra_args=["--abbrev-ref"]) assert branch == "v20.05" diff --git a/test/test_config_workdir.py b/test/test_config_workdir.py index c73fab62..a8bc1c50 100644 --- a/test/test_config_workdir.py +++ b/test/test_config_workdir.py @@ -29,9 +29,9 @@ def test_chroot_save_init(args, tmpdir, monkeypatch): return 1234567890.1234 monkeypatch.setattr(time, "time", fake_time) - # Pretend channel=stable in pmaports.cfg + # Pretend channel=v20.05 in pmaports.cfg def read_config(args): - return {"channel": "stable"} + return {"channel": "v20.05"} monkeypatch.setattr(pmb.config.pmaports, "read_config", read_config) args.work = str(tmpdir) @@ -41,7 +41,7 @@ def test_chroot_save_init(args, tmpdir, monkeypatch): expected = ("[chroot-init-dates]\n" "native = 1234567890\n\n" "[chroot-channels]\n" - "native = stable\n\n") + "native = v20.05\n\n") with open(args.work + "/workdir.cfg", "r") as handle: assert handle.read() == expected @@ -51,8 +51,8 @@ def test_chroot_save_init(args, tmpdir, monkeypatch): "native = 1234567890\n" "buildroot_armhf = 1234567890\n\n" "[chroot-channels]\n" - "native = stable\n" - "buildroot_armhf = stable\n\n") + "native = v20.05\n" + "buildroot_armhf = v20.05\n\n") with open(args.work + "/workdir.cfg", "r") as handle: assert handle.read() == expected @@ -104,7 +104,7 @@ def test_chroot_check_channel(args, tmpdir, monkeypatch): # Write workdir.cfg with open(f"{args.work}/workdir.cfg", "w") as handle: - handle.write("[chroot-channels]\nnative = stable\n\n") + handle.write("[chroot-channels]\nnative = v20.05\n\n") # workdir.cfg: no entry for buildroot_armhf chroot with pytest.raises(RuntimeError) as e: @@ -114,11 +114,11 @@ def test_chroot_check_channel(args, tmpdir, monkeypatch): # Chroot was created for wrong channel with pytest.raises(RuntimeError) as e: func(args, "native") - exp = "created for the 'stable' channel, but you are on the 'edge'" + exp = "created for the 'v20.05' channel, but you are on the 'edge'" assert exp in str(e.value) # Check runs through without raising an exception - channel = "stable" + channel = "v20.05" func(args, "native") diff --git a/test/test_crossdirect.py b/test/test_crossdirect.py index 00adbe2c..5a62f46c 100644 --- a/test/test_crossdirect.py +++ b/test/test_crossdirect.py @@ -37,11 +37,11 @@ def test_crossdirect_rust(args): working. """ pmbootstrap_run(args, ["-y", "zap"]) try: - # Switch to "stable" channel, as the stable release of alpine is more + # Switch to "v20.05" channel, as a stable release of alpine is more # likely to have the same rustc version across various architectures. # If armv7/x86_64 have a different rustc version, this test will fail: # 'found crate `std` compiled by an incompatible version of rustc' - pmb.config.pmaports.switch_to_channel_branch(args, "stable") + pmb.config.pmaports.switch_to_channel_branch(args, "v20.05") pmbootstrap_run(args, ["build_init", "-barmv7"]) pmbootstrap_run(args, ["chroot", "--add=rust", "-barmv7", "--", diff --git a/test/test_helpers_git.py b/test/test_helpers_git.py index e757b9a2..984db1f1 100644 --- a/test/test_helpers_git.py +++ b/test/test_helpers_git.py @@ -116,10 +116,14 @@ def test_parse_channels_cfg(args): "branch_pmaports": "master", "branch_aports": "master", "mirrordir_alpine": "edge"}, - "stable": {"description": "For workgroups", + "v20.05": {"description": "For workgroups", "branch_pmaports": "v20.05", "branch_aports": "3.11-stable", - "mirrordir_alpine": "v3.11"}}} + "mirrordir_alpine": "v3.11"}, + "v21.03": {"description": "Second beta release", + "branch_pmaports": "v21.03", + "branch_aports": "3.13-stable", + "mirrordir_alpine": "v3.13"}}} assert pmb.helpers.git.parse_channels_cfg(args) == exp diff --git a/test/test_helpers_repo.py b/test/test_helpers_repo.py index f6ec8fcb..1309218f 100644 --- a/test/test_helpers_repo.py +++ b/test/test_helpers_repo.py @@ -36,7 +36,7 @@ def test_alpine_apkindex_path(args): def test_urls(args, monkeypatch): func = pmb.helpers.repo.urls - channel = "stable" + channel = "v20.05" args.mirror_alpine = "http://localhost/alpine/" # Second mirror with /master at the end is legacy, gets fixed by func. @@ -50,7 +50,7 @@ def test_urls(args, monkeypatch): return {"channel": channel} monkeypatch.setattr(pmb.config.pmaports, "read_config", read_config) - # Channel: stable + # Channel: v20.05 assert func(args) == ["/mnt/pmbootstrap-packages", "http://localhost/pmos1/v20.05", "http://localhost/pmos2/v20.05", diff --git a/test/test_questions.py b/test/test_questions.py index af037f58..4c5d11d5 100644 --- a/test/test_questions.py +++ b/test/test_questions.py @@ -296,5 +296,5 @@ def test_questions_hostname(args, monkeypatch): def test_questions_channel(args, monkeypatch): - fake_answers(monkeypatch, ["invalid-channel", "stable"]) - assert pmb.config.init.ask_for_channel(args) == "stable" + fake_answers(monkeypatch, ["invalid-channel", "v20.05"]) + assert pmb.config.init.ask_for_channel(args) == "v20.05" diff --git a/test/testdata/channels.cfg b/test/testdata/channels.cfg index 6de251fb..b5eb81e8 100644 --- a/test/testdata/channels.cfg +++ b/test/testdata/channels.cfg @@ -8,8 +8,15 @@ branch_pmaports=master branch_aports=master mirrordir_alpine=edge +# Legacy channel name, gets translated to v20.05 [stable] description=For workgroups branch_pmaports=v20.05 branch_aports=3.11-stable mirrordir_alpine=v3.11 + +[v21.03] +description=Second beta release +branch_pmaports=v21.03 +branch_aports=3.13-stable +mirrordir_alpine=v3.13