@@ -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 )
0 commit comments