Skip to content

Commit df7f973

Browse files
authored
Directly generate build script in recipe folder, and support additional_cmake_args and additional_folder arguments (#84)
* Generate build scripts and activation scripts directly in recipe directory without intermediate files * Add support for additional_cmake_args in pkg_additional_info.yaml * Add support for specifying additional_folder in rosdistro_additional_recipes.yaml
1 parent 260af42 commit df7f973

9 files changed

Lines changed: 101 additions & 103 deletions

vinca/distro.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ def get_package_xml_for_additional_package(self, pkg_info):
153153
owner_repo = raw_url_base.split("github.com/")[-1]
154154
tag = pkg_info.get("tag")
155155
xml_name = pkg_info.get("package_xml_name", "package.xml")
156-
raw_url = f"https://raw.githubusercontent.com/{owner_repo}/{tag}/{xml_name}"
156+
additional_folder = pkg_info.get("additional_folder", "")
157+
if additional_folder != "":
158+
additional_folder = additional_folder + "/"
159+
raw_url = f"https://raw.githubusercontent.com/{owner_repo}/{tag}/{additional_folder}{xml_name}"
157160
try:
158161
with urllib.request.urlopen(raw_url) as resp:
159162
return resp.read().decode('utf-8')

vinca/main.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,19 +1084,8 @@ def main():
10841084

10851085
snapshot, additional_packages_snapshot = read_snapshot(vinca_conf)
10861086

1087-
from .template import generate_bld_ament_cmake
1088-
from .template import generate_bld_ament_python
1089-
from .template import generate_bld_catkin
1090-
from .template import generate_activate_hook
1091-
from .template import generate_bld_colcon_merge
1092-
from .template import generate_bld_catkin_merge
1093-
1094-
generate_bld_ament_cmake()
1095-
generate_bld_ament_python()
1096-
generate_bld_catkin()
1097-
generate_bld_colcon_merge()
1098-
generate_bld_catkin_merge()
1099-
generate_activate_hook()
1087+
# Store additional_packages_snapshot in vinca_conf for template access
1088+
vinca_conf["_additional_packages_snapshot"] = additional_packages_snapshot or {}
11001089

11011090
if arguments.trigger_new_versions:
11021091
vinca_conf["trigger_new_versions"] = True

vinca/template.py

Lines changed: 85 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,44 @@ def write_recipe(source, outputs, vinca_conf, single_file=True):
130130
shutil.copyfile(p, recipe_dir / p)
131131

132132
build_scripts = re.findall(r"'(.*?)'", meta["build"]["script"])
133-
baffer = meta["build"]["script"]
134133
for script in build_scripts:
135134
script_filename = script.replace("$RECIPE_DIR", "").replace("%RECIPE_DIR%", "").replace("/", "").replace("\\", "")
136-
copyfile_with_exec_permissions(script_filename, recipe_dir / script_filename)
135+
# Generate the build script directly in the recipe directory
136+
# Get additional CMake arguments from pkg_additional_info
137+
from vinca.utils import get_pkg_additional_info, ensure_name_is_without_distro_prefix_and_with_underscores
138+
pkg_name = o["package"]["name"]
139+
# Use the proper utility function to normalize the package name
140+
pkg_shortname = ensure_name_is_without_distro_prefix_and_with_underscores(pkg_name, vinca_conf)
141+
142+
additional_cmake_args = ""
143+
additional_folder = ""
144+
if pkg_shortname:
145+
pkg_additional_info = get_pkg_additional_info(pkg_shortname, vinca_conf)
146+
additional_cmake_args = pkg_additional_info.get("additional_cmake_args", "")
147+
148+
# Check if this package has folder info from additional_packages_snapshot
149+
if (vinca_conf.get("_additional_packages_snapshot") and
150+
pkg_shortname in vinca_conf["_additional_packages_snapshot"]):
151+
additional_folder = vinca_conf["_additional_packages_snapshot"][pkg_shortname].get("additional_folder", "")
152+
153+
generate_build_script_for_recipe(script_filename, recipe_dir / script_filename, additional_cmake_args, additional_folder)
137154
if "catkin" in o["package"]["name"] or "workspace" in o["package"]["name"]:
138-
shutil.copyfile("activate.sh", recipe_dir / "activate.sh")
139-
shutil.copyfile("activate.bat", recipe_dir / "activate.bat")
140-
shutil.copyfile("activate.ps1", recipe_dir / "activate.ps1")
141-
shutil.copyfile("deactivate.sh", recipe_dir / "deactivate.sh")
142-
shutil.copyfile("deactivate.bat", recipe_dir / "deactivate.bat")
143-
shutil.copyfile("deactivate.ps1", recipe_dir / "deactivate.ps1")
155+
# Generate activation scripts directly in the recipe directory
156+
generate_activation_scripts_for_recipe(recipe_dir)
144157

145-
146-
def generate_template(template_in, template_out):
158+
def generate_template(template_in, template_out, extra_globals=None):
147159
import em
148160
from vinca.config import skip_testing, ros_distro
149161

150-
g = {"ros_distro": ros_distro, "skip_testing": "ON" if skip_testing else "OFF"}
162+
g = {
163+
"ros_distro": ros_distro,
164+
"skip_testing": "ON" if skip_testing else "OFF"
165+
}
166+
167+
# Merge additional global variables if provided
168+
if extra_globals:
169+
g.update(extra_globals)
170+
151171
interpreter = em.Interpreter(
152172
output=template_out, options={em.RAW_OPT: True, em.BUFFERED_OPT: True}
153173
)
@@ -163,81 +183,63 @@ def generate_template(template_in, template_out):
163183
# Set executable permissions for user, group, and others
164184
os.chmod(template_out.name, current_permissions | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
165185

166-
def generate_bld_ament_cmake():
167-
import pkg_resources
168-
169-
template_in = pkg_resources.resource_filename(
170-
"vinca", "templates/bld_ament_cmake.bat.in"
171-
)
172-
generate_template(template_in, open("bld_ament_cmake.bat", "w"))
173-
template_in = pkg_resources.resource_filename(
174-
"vinca", "templates/build_ament_cmake.sh.in"
175-
)
176-
generate_template(template_in, open("build_ament_cmake.sh", "w"))
177-
178-
179-
def generate_bld_ament_python():
180-
import pkg_resources
181-
182-
template_in = pkg_resources.resource_filename(
183-
"vinca", "templates/bld_ament_python.bat.in"
184-
)
185-
generate_template(template_in, open("bld_ament_python.bat", "w"))
186-
template_in = pkg_resources.resource_filename(
187-
"vinca", "templates/build_ament_python.sh.in"
188-
)
189-
generate_template(template_in, open("build_ament_python.sh", "w"))
190-
191-
192-
def generate_bld_catkin():
193-
import pkg_resources
194-
195-
template_in = pkg_resources.resource_filename(
196-
"vinca", "templates/bld_catkin.bat.in"
197-
)
198-
generate_template(template_in, open("bld_catkin.bat", "w"))
199-
template_in = pkg_resources.resource_filename(
200-
"vinca", "templates/build_catkin.sh.in"
201-
)
202-
generate_template(template_in, open("build_catkin.sh", "w"))
203-
204-
205-
def generate_bld_colcon_merge():
206-
import pkg_resources
207-
208-
template_in = pkg_resources.resource_filename(
209-
"vinca", "templates/bld_colcon_merge.bat.in"
210-
)
211-
generate_template(template_in, open("bld_colcon_merge.bat", "w"))
212-
213-
214-
def generate_bld_catkin_merge():
186+
def generate_build_script_for_recipe(script_name, output_path, additional_cmake_args="", additional_folder=""):
187+
"""Generate a specific build script directly in the recipe directory."""
215188
import pkg_resources
216189

217-
template_in = pkg_resources.resource_filename(
218-
"vinca", "templates/bld_catkin_merge.bat.in"
219-
)
220-
generate_template(template_in, open("bld_catkin_merge.bat", "w"))
190+
# Map script names to their template files
191+
script_templates = {
192+
"build_ament_cmake.sh": "templates/build_ament_cmake.sh.in",
193+
"bld_ament_cmake.bat": "templates/bld_ament_cmake.bat.in",
194+
"build_ament_python.sh": "templates/build_ament_python.sh.in",
195+
"bld_ament_python.bat": "templates/bld_ament_python.bat.in",
196+
"build_catkin.sh": "templates/build_catkin.sh.in",
197+
"bld_catkin.bat": "templates/bld_catkin.bat.in",
198+
"bld_colcon_merge.bat": "templates/bld_colcon_merge.bat.in",
199+
"bld_catkin_merge.bat": "templates/bld_catkin_merge.bat.in"
200+
}
201+
202+
if script_name in script_templates:
203+
template_in = pkg_resources.resource_filename("vinca", script_templates[script_name])
204+
with open(output_path, "w") as output_file:
205+
extra_globals = {}
206+
if additional_cmake_args:
207+
extra_globals["additional_cmake_args"] = additional_cmake_args
208+
else:
209+
extra_globals["additional_cmake_args"] = ""
210+
if additional_folder:
211+
extra_globals["additional_folder"] = additional_folder
212+
else:
213+
extra_globals["additional_folder"] = ""
214+
generate_template(template_in, output_file, extra_globals)
221215

216+
# Set executable permissions on Unix systems
217+
if os.name == 'posix' and script_name.endswith('.sh'):
218+
current_permissions = os.stat(output_path).st_mode
219+
os.chmod(output_path, current_permissions | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
220+
else:
221+
print(f"Warning: Unknown build script template for {script_name}")
222222

223-
def generate_activate_hook():
223+
def generate_activation_scripts_for_recipe(recipe_dir):
224+
"""Generate activation scripts directly in the recipe directory."""
224225
import pkg_resources
225226

226-
template_in = pkg_resources.resource_filename("vinca", "templates/activate.bat.in")
227-
generate_template(template_in, open("activate.bat", "w"))
228-
template_in = pkg_resources.resource_filename(
229-
"vinca", "templates/deactivate.bat.in"
230-
)
231-
generate_template(template_in, open("deactivate.bat", "w"))
232-
233-
template_in = pkg_resources.resource_filename("vinca", "templates/activate.ps1.in")
234-
generate_template(template_in, open("activate.ps1", "w"))
235-
template_in = pkg_resources.resource_filename(
236-
"vinca", "templates/deactivate.ps1.in"
237-
)
238-
generate_template(template_in, open("deactivate.ps1", "w"))
239-
240-
template_in = pkg_resources.resource_filename("vinca", "templates/activate.sh.in")
241-
generate_template(template_in, open("activate.sh", "w"))
242-
template_in = pkg_resources.resource_filename("vinca", "templates/deactivate.sh.in")
243-
generate_template(template_in, open("deactivate.sh", "w"))
227+
activation_templates = {
228+
"activate.sh": "templates/activate.sh.in",
229+
"activate.bat": "templates/activate.bat.in",
230+
"activate.ps1": "templates/activate.ps1.in",
231+
"deactivate.sh": "templates/deactivate.sh.in",
232+
"deactivate.bat": "templates/deactivate.bat.in",
233+
"deactivate.ps1": "templates/deactivate.ps1.in"
234+
}
235+
236+
for script_name, template_path in activation_templates.items():
237+
template_in = pkg_resources.resource_filename("vinca", template_path)
238+
output_path = recipe_dir / script_name
239+
with open(output_path, "w") as output_file:
240+
generate_template(template_in, output_file) # No extra globals needed for activation scripts
241+
242+
# Set executable permissions on Unix systems for shell scripts
243+
if os.name == 'posix' and script_name.endswith('.sh'):
244+
current_permissions = os.stat(output_path).st_mode
245+
os.chmod(output_path, current_permissions | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)

vinca/templates/bld_ament_cmake.bat.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ cmake ^
4343
-DCMAKE_OBJECT_PATH_MAX=255 ^
4444
--compile-no-warning-as-error ^
4545
-DPYTHON_INSTALL_DIR=%PYTHON_INSTALL_DIR% ^
46-
%SRC_DIR%\%PKG_NAME%\src\work
46+
@(additional_cmake_args) ^
47+
%SRC_DIR%\%PKG_NAME%\src\work\@(additional_folder)
4748
if errorlevel 1 exit 1
4849

4950
:: We explicitly pass %CPU_COUNT% to cmake --build as we are not using Ninja,

vinca/templates/bld_ament_python.bat.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ setlocal
44

55
set "PYTHONPATH=%LIBRARY_PREFIX%\lib\site-packages;%SP_DIR%"
66

7-
pushd %SRC_DIR%\%PKG_NAME%\src\work
7+
pushd %SRC_DIR%\%PKG_NAME%\src\work\@(additional_folder)
88
set "PKG_NAME_SHORT=%PKG_NAME:*ros-@(ros_distro)-=%"
99
set "PKG_NAME_SHORT=%PKG_NAME_SHORT:-=_%"
1010

vinca/templates/bld_catkin.bat.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ cmake ^
4242
-DBoost_USE_STATIC_LIBS=OFF ^
4343
%CATKIN_BUILD_BINARY_PACKAGE_ARGS% ^
4444
-DCATKIN_SKIP_TESTING=%SKIP_TESTING% ^
45-
%SRC_DIR%\%PKG_NAME%\src\work
45+
@(additional_cmake_args) ^
46+
%SRC_DIR%\%PKG_NAME%\src\work\@(additional_folder)
4647
if errorlevel 1 exit 1
4748

4849
if "%PKG_NAME%" == "ros-@(ros_distro)-eigenpy" (

vinca/templates/build_ament_cmake.sh.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ elif [ "${PKG_NAME}" == "ros-humble-wasm-cpp" ]; then
103103
elif [ "${PKG_NAME}" == "dynmsg" ]; then
104104
WORK_DIR=$SRC_DIR/$PKG_NAME/src/work/dynmsg
105105
else
106-
WORK_DIR=$SRC_DIR/$PKG_NAME/src/work
106+
WORK_DIR=$SRC_DIR/$PKG_NAME/src/work/@(additional_folder)
107107
fi;
108108

109109
$CMAKE_GEN \
@@ -128,6 +128,7 @@ $CMAKE_GEN \
128128
-DCMAKE_OSX_DEPLOYMENT_TARGET=$OSX_DEPLOYMENT_TARGET \
129129
--compile-no-warning-as-error \
130130
$EXTRA_CMAKE_ARGS \
131+
@(additional_cmake_args) \
131132
$WORK_DIR
132133

133134
$CMAKE_BLD --build . --config $BUILD_TYPE --target install

vinca/templates/build_ament_python.sh.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
set -eo pipefail
55

6-
pushd $SRC_DIR/$PKG_NAME/src/work
6+
pushd $SRC_DIR/$PKG_NAME/src/work/@(additional_folder)
77

88
# If there is a setup.cfg that contains install-scripts then we should not set it here
99
if [ -f setup.cfg ] && grep -q "install[-_]scripts" setup.cfg; then

vinca/templates/build_catkin.sh.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ cmake ${CMAKE_ARGS} --compile-no-warning-as-error \
111111
-DCATKIN_BUILD_BINARY_PACKAGE=$CATKIN_BUILD_BINARY_PACKAGE \
112112
-DCMAKE_OSX_DEPLOYMENT_TARGET=$OSX_DEPLOYMENT_TARGET \
113113
$EXTRA_CMAKE_ARGS \
114+
@(additional_cmake_args) \
114115
-G "$GENERATOR" \
115-
$SRC_DIR/$PKG_NAME/src/work
116+
$SRC_DIR/$PKG_NAME/src/work/@(additional_folder)
116117

117118
cmake --build . --config Release --target all
118119

0 commit comments

Comments
 (0)