Skip to content

Commit cc79494

Browse files
committed
Allow to specify a different build number for a single package
This commit allow to specify a different build number for a single package, to allow to perform a fix to a build of a single package, without the need to do a full rebuild. This is an advanced option, so special care is needed: * A rebuild is only possible if it does not change the version or in any other way the ABI of the package. * On the following full rebuild, it is important to make sure that the build number select is higher then any custom build number used for single packages.
1 parent aa102b2 commit cc79494

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

vinca/main.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .distro import Distro
1717

1818
from vinca import config
19-
from vinca.utils import get_repodata
19+
from vinca.utils import get_repodata, get_pkg_build_number
2020

2121
unsatisfied_deps = set()
2222
distro = None
@@ -218,6 +218,11 @@ def read_vinca_yaml(filepath):
218218

219219
vinca_conf["trigger_new_versions"] = vinca_conf.get("trigger_new_versions", False)
220220

221+
if (Path(filepath).parent / "pkg_additional_info.yaml").exists():
222+
vinca_conf["_pkg_additional_info"] = yaml.load(open(Path(filepath).parent / "pkg_additional_info.yaml"))
223+
else:
224+
vinca_conf["_pkg_additional_info"] = {}
225+
221226
return vinca_conf
222227

223228

@@ -864,6 +869,7 @@ def main():
864869
base_dir = os.path.abspath(arguments.dir)
865870
vinca_yaml = os.path.join(base_dir, "vinca.yaml")
866871
vinca_conf = read_vinca_yaml(vinca_yaml)
872+
867873
snapshot = read_snapshot(arguments.snapshot)
868874

869875
from .template import generate_bld_ament_cmake
@@ -946,19 +952,19 @@ def main():
946952
# only URLs
947953
if "://" in fn:
948954
selected_bn = vinca_conf.get("build_number", 0)
949-
distro = vinca_conf["ros_distro"]
950-
all_pkgs = repodata.get("packages", {})
951-
all_pkgs.update(repodata.get("packages.conda", {}))
952-
for pkg_name, pkg in all_pkgs.items():
953-
if pkg_name.startswith(f"ros-{distro}"):
954-
if pkg_name.rsplit("-", 2)[0] in additional_recipe_names:
955-
print(
956-
f"Skipping additional recipe for build number computation {pkg_name}"
957-
)
958-
continue
959-
selected_bn = max(selected_bn, pkg["build_number"])
960-
961-
print(f"Selected build number: {selected_bn}")
955+
if not vinca_conf.get("use_explicit_build_number", False):
956+
distro = vinca_conf["ros_distro"]
957+
all_pkgs = repodata.get("packages", {})
958+
all_pkgs.update(repodata.get("packages.conda", {}))
959+
for pkg_name, pkg in all_pkgs.items():
960+
if pkg_name.startswith(f"ros-{distro}"):
961+
if pkg_name.rsplit("-", 2)[0] in additional_recipe_names:
962+
print(
963+
f"Skipping additional recipe for build number computation {pkg_name}"
964+
)
965+
continue
966+
selected_bn = max(selected_bn, pkg["build_number"])
967+
962968

963969
explicitly_selected_pkgs = [
964970
f"ros-{distro}-{pkg.replace('_', '-')}"
@@ -969,14 +975,15 @@ def main():
969975
for _, pkg in all_pkgs.items():
970976
is_built = False
971977
if selected_bn is not None:
978+
pkg_build_number = get_pkg_build_number(selected_bn, pkg["name"], vinca_conf)
972979
if vinca_conf.get("full_rebuild", True):
973-
if pkg["build_number"] == selected_bn:
980+
if pkg["build_number"] == pkg_build_number:
974981
is_built = True
975982
else:
976983
# remove all packages except explicitly selected ones
977984
if (
978985
pkg["name"] not in explicitly_selected_pkgs
979-
or pkg["build_number"] == selected_bn
986+
or pkg["build_number"] == pkg_build_number
980987
):
981988
is_built = True
982989
else:

vinca/template.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from ruamel import yaml
88
from pathlib import Path
99

10+
from vinca.utils import get_pkg_build_number
11+
1012
TEMPLATE = """\
1113
# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json
1214
@@ -71,7 +73,6 @@ def copyfile_with_exec_permissions(source_file, destination_file):
7173
os.chmod(destination_file, current_permissions | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
7274

7375
def write_recipe(source, outputs, vinca_conf, single_file=True):
74-
build_number = vinca_conf.get("build_number", 0)
7576
# single_file = False
7677
if single_file:
7778
file = yaml.YAML()
@@ -84,7 +85,7 @@ def write_recipe(source, outputs, vinca_conf, single_file=True):
8485
meta["package"]["version"] = f"{datetime.datetime.now():%Y.%m.%d}"
8586
meta["recipe"] = meta["package"]
8687
del meta["package"]
87-
meta["build"]["number"] = build_number
88+
meta["build"]["number"] = vinca_conf.get("build_number", 0)
8889
meta["build"]["post_process"] = post_process_items
8990
with open("recipe.yaml", "w") as stream:
9091
file.dump(meta, stream)
@@ -102,7 +103,7 @@ def write_recipe(source, outputs, vinca_conf, single_file=True):
102103
meta["package"]["name"] = o["package"]["name"]
103104
meta["package"]["version"] = o["package"]["version"]
104105

105-
meta["build"]["number"] = build_number
106+
meta["build"]["number"] = get_pkg_build_number(vinca_conf.get("build_number", 0), o["package"]["name"], vinca_conf)
106107
meta["build"]["post_process"] = post_process_items
107108

108109
if test := vinca_conf["_tests"].get(o["package"]["name"]):

vinca/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,20 @@ def get_repodata(url_or_path, platform=None):
6565
with open(fn, "w") as fcache:
6666
fcache.write(content.decode("utf-8"))
6767
return json.loads(content)
68+
69+
def ensure_name_is_without_distro_prefix_and_with_underscores(name, vinca_conf):
70+
"""
71+
Ensure that the name is without distro prefix and with underscores
72+
e.g. "ros-humble-pkg-name" -> "pkg_name"
73+
"""
74+
newname = name.replace("-", "_")
75+
distro_prefix = "ros_" + vinca_conf.get("ros_distro") + "_"
76+
if (newname.startswith(distro_prefix) ):
77+
newname = newname.replace(distro_prefix, "")
78+
79+
return newname
80+
81+
def get_pkg_build_number(default_build_number, pkg_name, vinca_conf):
82+
normalized_name = ensure_name_is_without_distro_prefix_and_with_underscores(pkg_name, vinca_conf)
83+
pkg_additional_info = vinca_conf["_pkg_additional_info"].get(normalized_name, {})
84+
return pkg_additional_info.get("build_number", default_build_number)

0 commit comments

Comments
 (0)