def _common_cmake_on_test(self, context, build_type): assert context.build_tests # Figure out if there is a setup file to source prefix = self._get_command_prefix('test', context) if not IS_WINDOWS: if has_make_target(context.build_space, 'test') or context.dry_run: cmd = prefix + [MAKE_EXECUTABLE, 'test'] if 'ARGS' not in os.environ: cmd.append('ARGS="-V"') yield BuildAction(cmd) else: self.warn( "Could not run tests for '{0}' package because it has no " "'test' target".format(build_type)) else: if MSBUILD_EXECUTABLE is None: raise VerbExecutionError("Could not find 'msbuild' executable") run_tests_project_file = project_file_exists_at( context.build_space, 'RUN_TESTS') if run_tests_project_file is not None or context.dry_run: yield BuildAction(prefix + [MSBUILD_EXECUTABLE, run_tests_project_file]) else: self.warn( "Could not find Visual Studio project file 'RUN_TESTS.vcxproj'" )
def _common_cmake_on_uninstall(self, context, build_type): # Figure out if there is a setup file to source prefix = self._get_command_prefix('uninstall', context) if not IS_WINDOWS: if has_make_target(context.build_space, 'uninstall'): if MAKE_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'make' executable") cmd = prefix + [MAKE_EXECUTABLE, 'uninstall'] yield BuildAction(cmd) else: self.warn( "Could not run uninstall for '{0}' package because it has no " "'uninstall' target".format(build_type)) else: if MSBUILD_EXECUTABLE is None: raise VerbExecutionError("Could not find 'msbuild' executable") uninstall_project_file = project_file_exists_at( context.build_space, 'UNINSTALL') if uninstall_project_file is not None: yield BuildAction(prefix + [MSBUILD_EXECUTABLE, uninstall_project_file]) else: self.warn( "Could not find Visual Studio project file 'UNINSTALL.vcxproj'" )
def _common_cmake_on_install(self, context): # Figure out if there is a setup file to source prefix = self._get_command_prefix('install', context) if not IS_WINDOWS: if has_make_target(context.build_space, 'install') or context.dry_run: if MAKE_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'make' executable") yield BuildAction(prefix + [MAKE_EXECUTABLE, 'install']) else: self.warn( 'Could not run installation for package because it has no ' "'install' target") else: install_project_file = project_file_exists_at( context.build_space, 'INSTALL') if install_project_file is not None: if MSBUILD_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'msbuild' executable") yield BuildAction(prefix + [ MSBUILD_EXECUTABLE, '/p:Configuration=' + self._get_visual_studio_configuration(context), install_project_file ]) else: self.warn( "Could not find Visual Studio project file 'INSTALL.vcxproj'" )
def _common_cmake_on_uninstall(self, context, build_type): # Figure out if there is a setup file to source prefix = self._get_command_prefix('uninstall', context) if IS_LINUX: build_action = self._make_uninstall(context, build_type, prefix) if build_action: yield build_action elif IS_WINDOWS: if MSBUILD_EXECUTABLE is None: raise VerbExecutionError("Could not find 'msbuild' executable") uninstall_project_file = project_file_exists_at( context.build_space, 'UNINSTALL') if uninstall_project_file is not None: yield BuildAction(prefix + [MSBUILD_EXECUTABLE, uninstall_project_file]) else: self.warn( "Could not find Visual Studio project file 'UNINSTALL.vcxproj'" ) elif IS_MACOSX: if self._using_xcode_generator(context): if XCODEBUILD_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'xcodebuild' executable") cmd = prefix + [XCODEBUILD_EXECUTABLE] cmd += ['-target', 'uninstall'] yield BuildAction(cmd) else: build_action = self._make_uninstall(context, build_type, prefix) if build_action: yield build_action else: raise VerbExecutionError('Could not determine operating system')
def _make_or_ninja_build(self, context, prefix): if context.use_ninja: if NINJA_EXECUTABLE is None: raise VerbExecutionError("Could not find 'make' executable") return BuildAction(prefix + [NINJA_EXECUTABLE] + context.make_flags) else: if MAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'make' executable") return BuildAction(prefix + [MAKE_EXECUTABLE] + context.make_flags)
def _common_cmake_on_test(self, context, build_type): assert context.build_tests # Figure out if there is a setup file to source # also pass the exec dependencies into the command prefix file prefix = self._get_command_prefix( 'test', context, additional_dependencies=context.exec_dependency_paths_in_workspace) if not IS_WINDOWS: if has_make_target(context.build_space, 'test') or context.dry_run: if MAKE_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'make' executable") cmd = prefix + [MAKE_EXECUTABLE, 'test'] if 'ARGS' not in os.environ: args = [ '-V', # verbose output and generate xml of test summary '-D', 'ExperimentalTest', '--no-compress-output' ] elif os.environ['ARGS']: args = [os.environ['ARGS']] else: args = [] args += context.ctest_args if context.retest_until_pass and context.test_iteration: args += ['--rerun-failed'] if args: # the valus is not quoted here # since each item will be quoted by shlex.quote later if necessary cmd.append('ARGS=%s' % ' '.join(args)) yield BuildAction(cmd) else: self.warn( "Could not run tests for '{0}' package because it has no " "'test' target".format(build_type)) else: if CTEST_EXECUTABLE is None: raise VerbExecutionError("Could not find 'ctest' executable") # invoke CTest directly in order to pass arguments # it needs a specific configuration and currently there are no conf. specific tests cmd = prefix + [ CTEST_EXECUTABLE, # choose configuration on e.g. Windows '-C', self._get_visual_studio_configuration(context), # generate xml of test summary '-D', 'ExperimentalTest', '--no-compress-output', # show all test output '-V', '--force-new-ctest-process'] + \ context.ctest_args if context.retest_until_pass and context.test_iteration: cmd += ['--rerun-failed'] yield BuildAction(cmd)
def _common_cmake_on_install(self, context): # Figure out if there is a setup file to source prefix = self._get_command_prefix('install', context) if IS_LINUX: build_action = self._make_or_ninja_install(context, prefix) if build_action: yield build_action elif IS_WINDOWS: install_project_file = project_file_exists_at( context.build_space, 'INSTALL') if install_project_file is not None: if MSBUILD_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'msbuild' executable") yield BuildAction(prefix + [ MSBUILD_EXECUTABLE, '/p:Configuration=' + self._get_configuration_from_cmake(context), install_project_file ]) else: self.warn( "Could not find Visual Studio project file 'INSTALL.vcxproj'" ) elif IS_MACOSX: if self._using_xcode_generator(context): # The Xcode CMake generator will produce a file named # install_postBuildPhase.makeRelease in the CMakeScripts directory if there is an # install command in the CMakeLists.txt file of the package. We use that to only # call xcodebuild's install target if there is anything to install install_cmake_file_path = os.path.join( context.build_space, 'CMakeScripts', 'install_postBuildPhase.makeRelease') install_cmake_file = os.path.isfile(install_cmake_file_path) if install_cmake_file: if XCODEBUILD_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'xcodebuild' executable") cmd = prefix + [XCODEBUILD_EXECUTABLE] cmd += ['-target', 'install'] cmd += [ '-configuration', self._get_configuration_from_cmake(context) ] if self._get_sdk_from_cmake(context) != "": cmd += ['-sdk', self._get_sdk_from_cmake(context)] cmd += ['EFFECTIVE_PLATFORM_NAME='] yield BuildAction(cmd) else: build_action = self._make_or_ninja_install(context, prefix) if build_action: yield build_action else: raise VerbExecutionError('Could not determine operating system')
def _make_or_ninja_install(self, context, prefix): if context.use_ninja: if NINJA_EXECUTABLE is None: raise VerbExecutionError("Could not find 'ninja' executable") return BuildAction(prefix + [NINJA_EXECUTABLE, 'install']) else: if has_make_target(context.build_space, 'install') or context.dry_run: if MAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'make' executable") return BuildAction(prefix + [MAKE_EXECUTABLE, 'install']) else: self.warn("Could not run installation for package '{0}' because it has no " "'install' target".format(context.package_manifest.name))
def _common_cmake_on_test(self, context, build_type): assert context.build_tests # Figure out if there is a setup file to source # also pass the exec dependencies into the command prefix file prefix = self._get_command_prefix( 'test', context, additional_dependencies=context.exec_dependency_paths_in_workspace) if IS_LINUX: build_action = self._make_test(context, build_type, prefix) if build_action: yield build_action elif IS_WINDOWS: if CTEST_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'ctest' executable, try setting the " 'environment variable ' + CTEST_EXECUTABLE_ENV) # invoke CTest directly in order to pass arguments # it needs a specific configuration and currently there are no conf. specific tests cmd = prefix + [ CTEST_EXECUTABLE, # choose configuration on e.g. Windows '-C', self._get_configuration_from_cmake(context), # generate xml of test summary '-D', 'ExperimentalTest', '--no-compress-output', # show all test output '-V', '--force-new-ctest-process'] + \ context.ctest_args if context.retest_until_pass and context.test_iteration: cmd += ['--rerun-failed'] yield BuildAction(cmd) elif IS_MACOSX: if self._using_xcode_generator(context): if XCODEBUILD_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'xcodebuild' executable") xcodebuild_args = ['build'] xcodebuild_args += ['-configuration'] xcodebuild_args += [ self._get_configuration_from_cmake(context) ] xcodebuild_args += ['-target', 'RUN_TESTS'] yield BuildAction(prefix + [XCODEBUILD_EXECUTABLE] + xcodebuild_args) else: build_action = self._make_test(context, build_type, prefix) if build_action: yield build_action else: raise VerbExecutionError('Could not determine operating system')
def _make_test(self, context, build_type, prefix): if has_make_target(context.build_space, 'test') or context.dry_run: if MAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'make' executable") cmd = prefix + [MAKE_EXECUTABLE, 'test'] if 'ARGS' not in os.environ: args = [ '-V', # verbose output and generate xml of test summary '-D', 'ExperimentalTest', '--no-compress-output' ] elif os.environ['ARGS']: args = [os.environ['ARGS']] else: args = [] args += context.ctest_args if context.retest_until_pass and context.test_iteration: args += ['--rerun-failed'] if args: # the valus is not quoted here # since each item will be quoted by shlex.quote later if necessary cmd.append('ARGS=%s' % ' '.join(args)) return BuildAction(cmd) else: self.warn( "Could not run tests for package '{0}' because it has no " "'test' target".format(context.package_manifest.name))
def _common_cmake_on_build(self, should_run_configure, context, prefix, extra_cmake_args): # Execute the configure step # (either cmake or the cmake_check_build_system make target) if should_run_configure: cmake_args = [context.source_space] cmake_args.extend(extra_cmake_args) cmake_args += ["-DCMAKE_INSTALL_PREFIX=" + context.install_space] if IS_WINDOWS: vsv = get_visual_studio_version() if vsv is None: sys.stderr.write( 'VisualStudioVersion is not set, ' 'please run within a Visual Studio Command Prompt.\n') raise VerbExecutionError('Could not determine Visual Studio Version') supported_vsv = { '14.0': 'Visual Studio 14 2015 Win64', } if vsv not in supported_vsv: raise VerbExecutionError('Unknown / unsupported VS version: ' + vsv) cmake_args += ['-G', supported_vsv[vsv]] if CMAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'cmake' executable") yield BuildAction(prefix + [CMAKE_EXECUTABLE] + cmake_args) elif not IS_WINDOWS: # Check for reconfigure if available. if MAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'make' executable") cmd = prefix + [MAKE_EXECUTABLE, 'cmake_check_build_system'] yield BuildAction(cmd) # Now execute the build step if not IS_WINDOWS: if MAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'make' executable") yield BuildAction(prefix + [MAKE_EXECUTABLE] + context.make_flags) else: if MSBUILD_EXECUTABLE is None: raise VerbExecutionError("Could not find 'msbuild' executable") solution_file = solution_file_exists_at( context.build_space, context.package_manifest.name) cmd = prefix + [MSBUILD_EXECUTABLE] if '-j1' in context.make_flags: cmd += ['/m'] cmd += [ '/p:Configuration=%s' % self._get_visual_studio_configuration(context), solution_file] yield BuildAction(cmd)
def _make_uninstall(self, context, build_type, prefix): if has_make_target(context.build_space, 'uninstall'): if MAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'make' executable") cmd = prefix + [MAKE_EXECUTABLE, 'uninstall'] return BuildAction(cmd) else: self.warn("Could not run uninstall for package '{0}' because it has no " "'uninstall' target".format(context.package_manifest.name))
def on_uninstall(self, context): yield BuildAction(self._uninstall_action_files, type='function') # Figure out if there is a setup file to source prefix = self._get_command_prefix('uninstall', context) for action in self._undo_develop(context, prefix) or []: yield action self._undo_install(context)
def _common_cmake_on_build(self, should_run_configure, context, prefix, extra_cmake_args): # Execute the configure step # (either cmake or the cmake_check_build_system make target) if should_run_configure: cmake_args = [context.source_space] cmake_args.extend(extra_cmake_args) cmake_args += ["-DCMAKE_INSTALL_PREFIX=" + context.install_space] if IS_WINDOWS: vsv = get_visual_studio_version() if vsv is None: print("VisualStudioVersion is not set, please run within " "a VS2013 or VS2015 Command Prompt.") raise VerbExecutionError( "Could not determine Visual Studio Version.") generator = None if vsv == '12.0': generator = 'Visual Studio 12 2013 Win64' elif vsv == '14.0': generator = 'Visual Studio 14 2015 Win64' else: raise VerbExecutionError("Unknown VS version: " + vsv) cmake_args += ['-G', generator] if CMAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'cmake' executable") yield BuildAction(prefix + [CMAKE_EXECUTABLE] + cmake_args) elif not IS_WINDOWS: # Check for reconfigure if available. cmd = prefix + [MAKE_EXECUTABLE, 'cmake_check_build_system'] yield BuildAction(cmd) # Now execute the build step if not IS_WINDOWS: if MAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'make' executable") yield BuildAction(prefix + [MAKE_EXECUTABLE] + context.make_flags) else: if MSBUILD_EXECUTABLE is None: raise VerbExecutionError("Could not find 'msbuild' executable") solution_file = solution_file_exists_at( context.build_space, context.package_manifest.name) if '-j1' in context.make_flags: yield BuildAction(prefix + [MSBUILD_EXECUTABLE, solution_file]) else: yield BuildAction(prefix + [MSBUILD_EXECUTABLE, '/m', solution_file])
def on_install(self, context): # deploy package manifest deploy_file(context, context.source_space, 'package.xml', dst_subfolder=os.path.join('share', context.package_manifest.name)) # create marker file marker_file = os.path.join(context.install_space, 'share', 'ament_index', 'resource_index', 'packages', context.package_manifest.name) if not os.path.exists(marker_file): marker_dir = os.path.dirname(marker_file) if not os.path.exists(marker_dir): os.makedirs(marker_dir) with open(marker_file, 'w'): # "touching" the file pass ext = '.sh' if not IS_WINDOWS else '.bat' # deploy AMENT_PREFIX_PATH environment hook app_template_path = get_environment_hook_template_path( 'ament_prefix_path' + ext) deploy_file(context, os.path.dirname(app_template_path), os.path.basename(app_template_path), dst_subfolder=os.path.join('share', context.package_manifest.name, 'environment')) # deploy PATH environment hook path_template_path = get_environment_hook_template_path('path' + ext) deploy_file(context, os.path.dirname(path_template_path), os.path.basename(path_template_path), dst_subfolder=os.path.join('share', context.package_manifest.name, 'environment')) # deploy CLASSPATH environment hook destination_file = 'classpath' + ('.sh' if not IS_WINDOWS else '.bat') deploy_file( context, context.build_space, os.path.join('share', context.package_manifest.name, 'environment', destination_file)) # deploy package-level setup files for name in get_package_level_template_names(): assert name.endswith('.in') deploy_file( context, context.build_space, os.path.join('share', context.package_manifest.name, name[:-3])) yield BuildAction(self._prepare_cmd(context, gradle_task='assemble'), cwd=context.build_space)
def on_build(self, context): cmd_args = [ '-Pament.build_space=' + context.build_space, '-Pament.install_space=' + context.install_space, '-Pament.dependencies=' + ':'.join(context.build_dependencies), '-Pament.build_tests=' + str(context.build_tests), ] cmd_args += context.ament_gradle_args cmd = [get_gradle_executable(context)] cmd += cmd_args cmd += ['assemble'] yield BuildAction(cmd, cwd=context.source_space) environment_hooks_path = os.path.join('share', context.package_manifest.name, 'environment') ext = '.sh' if not IS_WINDOWS else '.bat' path_environment_hook = os.path.join(environment_hooks_path, 'path' + ext) # expand environment hook for JAVAPATH ext = '.sh.in' if not IS_WINDOWS else '.bat.in' template_path = self.get_environment_hook_template_path('javapath' + ext) javapath = os.path.join('$AMENT_CURRENT_PREFIX', 'share', context.package_manifest.name, 'java', '*') javapath_depends = os.path.join('$AMENT_CURRENT_PREFIX', 'lib', 'java', '*') content = configure_file(template_path, { 'JAVAPATH': javapath, 'JAVAPATH_DEPENDS': javapath_depends }) javapath_environment_hook = os.path.join( environment_hooks_path, os.path.basename(template_path)[:-3]) destination_path = os.path.join(context.build_space, javapath_environment_hook) destination_dir = os.path.dirname(destination_path) if not os.path.exists(destination_dir): os.makedirs(destination_dir) with open(destination_path, 'w') as h: h.write(content) environment_hooks = [ path_environment_hook, javapath_environment_hook, ] # expand package-level setup files expand_package_level_setup_files(context, environment_hooks, environment_hooks_path)
def _common_cmake_on_install(self, context): # Figure out if there is a setup file to source prefix = self._get_command_prefix('install', context) if not IS_WINDOWS: # Assumption: install target exists if MAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'make' executable") yield BuildAction(prefix + [MAKE_EXECUTABLE, 'install']) else: if MSBUILD_EXECUTABLE is None: raise VerbExecutionError("Could not find 'msbuild' executable") install_project_file = project_file_exists_at( context.build_space, 'INSTALL') if install_project_file is None: raise VerbExecutionError( "Could not find Visual Studio project file 'INSTALL.vcxproj'" ) yield BuildAction(prefix + [MSBUILD_EXECUTABLE, install_project_file])
def on_uninstall(self, context): # clalancette: Note that bazel has no real concept of an install # target. Thus, we define a de-facto one here which is a run # command with a target of //:uninstall. if _has_target(context.source_space, '//:uninstall'): cmd = [BAZEL_EXECUTABLE, 'run'] + context.bazel_args + \ ['//:uninstall', context.install_space] yield BuildAction(cmd, cwd=context.source_space) else: self.warn("Could not uninstall package '{0}' because it has no " "'//:uninstall' target".format( context.package_manifest.name))
def on_test(self, context): # Execute nosetests # and avoid placing any files in the source space coverage_file = os.path.join(context.build_space, '.coverage') additional_lines = [] if not IS_WINDOWS: additional_lines.append('export COVERAGE_FILE="%s"' % coverage_file) else: additional_lines.append('set "COVERAGE_FILE=%s"' % coverage_file) # also pass the exec dependencies into the command prefix file prefix = self._get_command_prefix( 'test', context, additional_lines=additional_lines, additional_dependencies=context.exec_dependency_paths_in_workspace, ) xunit_file = os.path.join(context.build_space, 'test_results', context.package_manifest.name, 'nosetests.xunit.xml') if not os.path.exists(os.path.dirname(xunit_file)): os.makedirs(os.path.dirname(xunit_file)) assert NOSETESTS_EXECUTABLE, 'Could not find nosetests' coverage_xml_file = os.path.join(context.build_space, 'coverage.xml') cmd = NOSETESTS_EXECUTABLE + [ '--nocapture', '--with-xunit', '--xunit-file=%s' % xunit_file, '--with-coverage', '--cover-erase', '--cover-tests', '--cover-branches', '--cover-inclusive', '--cover-xml', '--cover-xml-file=%s' % coverage_xml_file, ] if LooseVersion(nose.__version__) >= LooseVersion('1.3.5'): cmd += [ '--xunit-testsuite-name=%s.nosetests' % context.package_manifest.name ] if LooseVersion(nose.__version__) >= LooseVersion('1.3.8'): cmd += ['--xunit-prefix-with-testsuite-name'] # coverage for all root-packages packages = setuptools.find_packages(context.source_space, exclude=['*.*']) for package in packages: if package in ['test', 'tests']: continue cmd += ['--cover-package=%s' % package] yield BuildAction(prefix + cmd, cwd=context.source_space)
def on_test(self, context): cmd_args = [ '-Pament.build_space=' + context.build_space, '-Pament.install_space=' + context.install_space, '-Pament.dependencies=' + ':'.join(context.build_dependencies), '-Pament.build_tests=' + str(context.build_tests), ] cmd_args += context.ament_gradle_args cmd = [get_gradle_executable(context)] cmd += cmd_args cmd += ['test'] yield BuildAction(cmd, cwd=context.source_space)
def _undo_develop(self, context, prefix): # Undo previous develop if .egg-info is found and develop symlinks egg_info = os.path.join(context.build_space, '%s.egg-info' % context.package_manifest.name) setup_py_build_space = os.path.join( context.build_space, 'setup.py') if os.path.exists(egg_info) and \ os.path.exists(setup_py_build_space) and \ os.path.islink(setup_py_build_space): cmd = [ context.python_interpreter, 'setup.py', 'develop', '--prefix', context.install_space, '--uninstall', ] self._add_install_layout(context, cmd) yield BuildAction(prefix + cmd, cwd=context.build_space)
def on_test(self, context): # Execute pytest # and avoid placing any files in the source space xunit_file = os.path.join(context.build_space, 'test_results', context.package_manifest.name, 'pytest.xunit.xml') os.makedirs(os.path.dirname(xunit_file), exist_ok=True) args = [ '--junit-xml=' + xunit_file, '--junit-prefix=' + context.package_manifest.name, ] # coverage arguments coverage_file = os.path.join(context.build_space, '.coverage') args += [ '--cov=' + context.source_space, '--cov-report=xml:' + coverage_file, '--cov-branch', ] additional_lines = [] if not IS_WINDOWS: additional_lines.append('export PYTEST_ADDOPTS="%s"' % ' '.join(args)) else: # backslashes need to be escaped to be passed through env var args = [a.replace('\\', '\\\\') for a in args] additional_lines.append('set "PYTEST_ADDOPTS=%s"' % ' '.join(args)) # also pass the exec dependencies into the command prefix file prefix = self._get_command_prefix( 'test', context, additional_lines=additional_lines, additional_dependencies=context.exec_dependency_paths_in_workspace, ) assert pytest, 'Could not find pytest' cmd = [ context.python_interpreter, 'setup.py', 'pytest', 'egg_info', '--egg-base', context.build_space, ] yield BuildAction(prefix + cmd, cwd=context.source_space)
def on_build(self, context): environment_hooks_path = os.path.join('share', context.package_manifest.name, 'environment') ext = '.sh' if not IS_WINDOWS else '.bat' # expand environment hook for AMENT_PREFIX_PATH ament_prefix_path_environment_hook = os.path.join(environment_hooks_path, 'ament_prefix_path' + ext) # expand environment hook for PATH path_environment_hook = os.path.join(environment_hooks_path, 'path' + ext) # expand environment hook for CLASSPATH classpath_filename = 'classpath' + ext template = get_environment_hook_classpath_template_path() # If using the Gradle Ament Plugin, JAR files are installed into # $AMENT_CURRENT_PREFIX/share/$PROJECT_NAME/java/$PROJECT_NAME.jar classpath = os.path.join('$AMENT_CURRENT_PREFIX', 'share', context.package_manifest.name, 'java', context.package_manifest.name + ".jar") content = configure_string(template, {'_AMENT_EXPORT_JARS_CLASSPATH': classpath, }) classpath_environment_hook = os.path.join(environment_hooks_path, os.path.basename(classpath_filename)) destination_path = os.path.join(context.build_space, classpath_environment_hook) destination_dir = os.path.dirname(destination_path) if not os.path.exists(destination_dir): os.makedirs(destination_dir) with open(destination_path, 'w') as h: h.write(content) environment_hooks = [ ament_prefix_path_environment_hook, classpath_environment_hook, path_environment_hook, ] # expand package-level setup files expand_package_level_setup_files(context, environment_hooks, environment_hooks_path) # remove anything that's on the destination tree but not in the source tree src_package_src_dir = os.path.join(context.source_space, 'src') dst_package_src_dir = os.path.join(context.build_space, 'src') src_dirnames, src_filenames = self._build_file_tree(src_package_src_dir) dst_dirnames, dst_filenames = self._build_file_tree(dst_package_src_dir) prune_dirnames = dst_dirnames - src_dirnames prune_filenames = dst_filenames - src_filenames for prune_filename in prune_filenames: os.remove(os.path.join(dst_package_src_dir, prune_filename)) for prune_dirname in prune_dirnames: if os.path.exists(prune_dirname): shutil.rmtree(os.path.join(dst_package_src_dir, prune_dirname)) # copy files from source_space to build_space to avoid poluting the latter # during the build process dir_util.copy_tree(context.source_space, context.build_space, update=1) yield BuildAction( self._prepare_cmd( context, gradle_task='assemble'), cwd=context.build_space)
def _common_cmake_on_build(self, should_run_configure, context, prefix, extra_cmake_args): # Execute the configure step # (either cmake or the cmake_check_build_system make target) if should_run_configure: cmake_args = [context.source_space] cmake_args.extend(extra_cmake_args) cmake_args += ['-DCMAKE_INSTALL_PREFIX=' + context.install_space] if IS_WINDOWS: vsv = get_visual_studio_version() if vsv is None: sys.stderr.write( 'VisualStudioVersion is not set, ' 'please run within a Visual Studio Command Prompt.\n') raise VerbExecutionError( 'Could not determine Visual Studio Version') supported_vsv = { '14.0': 'Visual Studio 14 2015 Win64', '15.0': 'Visual Studio 15 2017 Win64', } if vsv not in supported_vsv: raise VerbExecutionError( 'Unknown / unsupported VS version: ' + vsv) cmake_args += ['-G', supported_vsv[vsv]] elif IS_MACOSX: if context.use_xcode or self._using_xcode_generator(context): cmake_args += ['-G', 'Xcode'] else: cmake_args += ['-G', 'Unix Makefiles'] if CMAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'cmake' executable") yield BuildAction(prefix + [CMAKE_EXECUTABLE] + cmake_args) elif IS_LINUX: # Check for reconfigure if available. if MAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'make' executable") cmd = prefix + [MAKE_EXECUTABLE, 'cmake_check_build_system'] yield BuildAction(cmd) # Now execute the build step if IS_LINUX: yield self._make_or_ninja_build(context, prefix) elif IS_WINDOWS: if MSBUILD_EXECUTABLE is None: raise VerbExecutionError("Could not find 'msbuild' executable") solution_file = solution_file_exists_at( context.build_space, context.package_manifest.name) cmd = prefix + [MSBUILD_EXECUTABLE] env = None # Convert make parallelism flags into msbuild flags msbuild_flags = [ x.replace('-j', '/m:') for x in context.make_flags if x.startswith('-j') ] if msbuild_flags: cmd += msbuild_flags # If there is a parallelism flag in msbuild_flags and it's not /m1, # then turn on /MP for the compiler (intra-project parallelism) if any(x.startswith('/m') for x in msbuild_flags) and \ '/m:1' not in msbuild_flags: env = dict(os.environ) if 'CL' in env: # make sure env['CL'] doesn't include an /MP already if not any( x.startswith('/MP') for x in env['CL'].split(' ')): env['CL'] += ' /MP' else: # CL not in environment; let's add it with our flag env['CL'] = '/MP' cmd += [ '/p:Configuration=%s' % self._get_configuration_from_cmake(context), solution_file ] yield BuildAction(cmd, env=env) elif IS_MACOSX: if self._using_xcode_generator(context): if XCODEBUILD_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'xcodebuild' executable") cmd = prefix + [XCODEBUILD_EXECUTABLE] cmd += ['build'] xcodebuild_flags = [] for flag in context.make_flags: if flag.startswith('-j'): xcodebuild_flags.append( flag.replace( '-j', '-IDEBuildOperationMaxNumberOfConcurrentCompileTasks=' )) elif not flag.startswith('-l'): xcodebuild_flags.append(flag) xcodebuild_flags += ['-configuration'] xcodebuild_flags += [ self._get_configuration_from_cmake(context) ] cmd.extend(xcodebuild_flags) yield BuildAction(cmd) else: yield self._make_or_ninja_build(context, prefix) else: raise VerbExecutionError('Could not determine operating system')
def on_build(self, context): # expand all templates in build space yield BuildAction(self._build_action, type='function')
def on_install(self, context): yield BuildAction(self._install_action_files, type='function') # setup.py egg_info requires the --egg-base to exist if not os.path.exists(context.build_space): os.makedirs(context.build_space) # setup.py install/develop requires the PYTHONPATH to exist python_path = os.path.join(context.install_space, self._get_python_lib(context)) if not os.path.exists(python_path): os.makedirs(python_path) # Figure out if there is a setup file to source prefix = self._get_command_prefix('install', context) if not context.symlink_install: for action in self._undo_develop(context, prefix) or []: yield action # Execute the setup.py install step with lots of arguments # to avoid placing any files in the source space cmd = [ PYTHON_EXECUTABLE, 'setup.py', 'egg_info', '--egg-base', context.build_space, 'build', '--build-base', os.path.join(context.build_space, 'build'), 'install', '--prefix', context.install_space, '--install-scripts', os.path.join(context.install_space, 'bin'), '--record', os.path.join(context.build_space, 'install.log'), ] self._add_install_layout(context, cmd) cmd += [ 'bdist_egg', '--dist-dir', os.path.join(context.build_space, 'dist'), ] yield BuildAction(prefix + cmd, cwd=context.source_space) else: yield BuildAction(self._install_action_python, type='function') # Execute the setup.py develop step in build space # to avoid placing any files in the source space cmd = [ PYTHON_EXECUTABLE, 'setup.py', 'develop', '--prefix', context.install_space, '--script-dir', os.path.join(context.install_space, 'bin'), ] self._add_install_layout(context, cmd) yield BuildAction(prefix + cmd, cwd=context.build_space)
def on_install(self, context): # deploy PATH environment hook ext = '.sh' if not IS_WINDOWS else '.bat' template_path = get_environment_hook_template_path('path' + ext) deploy_file(context, os.path.dirname(template_path), os.path.basename(template_path), dst_subfolder=os.path.join('share', context.package_manifest.name, 'environment')) # deploy JAVAPATH environment hook destination_file = 'javapath' + ('.sh' if not IS_WINDOWS else '.bat') deploy_file( context, context.build_space, os.path.join('share', context.package_manifest.name, 'environment', destination_file)) # create marker file marker_file = os.path.join(context.install_space, 'share', 'ament_index', 'resource_index', 'packages', context.package_manifest.name) if not os.path.exists(marker_file): marker_dir = os.path.dirname(marker_file) if not os.path.exists(marker_dir): os.makedirs(marker_dir) with open(marker_file, 'w'): # "touching" the file pass for name in get_package_level_template_names(): assert name.endswith('.in') deploy_file( context, context.build_space, os.path.join('share', context.package_manifest.name, name[:-3])) cmd_args = [ '-Pament.build_space=' + context.build_space, '-Pament.install_space=' + context.install_space, '-Pament.dependencies=' + ':'.join(context.build_dependencies), '-Pament.build_tests=' + str(context.build_tests), ] cmd_args += context.ament_gradle_args cmd = [get_gradle_executable(context)] cmd += cmd_args cmd += ['assemble'] yield BuildAction(cmd, cwd=context.source_space) #Deploy libs dependencies filesDir = os.path.join(context.build_space, 'lib', 'java') if os.path.exists(filesDir): for filename in os.listdir(filesDir): deploy_file( context, context.build_space, os.path.join('lib', 'java', os.path.basename(filename))) #Deploy share files self.deploy_files( context, os.path.join('share', context.package_manifest.name, 'java')) #Deploy scripts filesDir = os.path.join(context.build_space, 'bin') if os.path.exists(filesDir): for filename in os.listdir(filesDir): deploy_file(context, context.build_space, os.path.join('bin', os.path.basename(filename)))
def _common_cmake_on_build(self, should_run_configure, context, prefix, extra_cmake_args): # Execute the configure step # (either cmake or the cmake_check_build_system make target) if should_run_configure: cmake_args = [context.source_space] cmake_args.extend(extra_cmake_args) cmake_args += ["-DCMAKE_INSTALL_PREFIX=" + context.install_space] if IS_WINDOWS: vsv = get_visual_studio_version() if vsv is None: sys.stderr.write( 'VisualStudioVersion is not set, ' 'please run within a Visual Studio Command Prompt.\n') raise VerbExecutionError( 'Could not determine Visual Studio Version') supported_vsv = { '14.0': 'Visual Studio 14 2015 Win64', } if vsv not in supported_vsv: raise VerbExecutionError( 'Unknown / unsupported VS version: ' + vsv) cmake_args += ['-G', supported_vsv[vsv]] if CMAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'cmake' executable") yield BuildAction(prefix + [CMAKE_EXECUTABLE] + cmake_args) elif not IS_WINDOWS: # Check for reconfigure if available. if MAKE_EXECUTABLE is None: raise VerbExecutionError("Could not find 'make' executable") cmd = prefix + [MAKE_EXECUTABLE, 'cmake_check_build_system'] yield BuildAction(cmd) # Now execute the build step if not IS_WINDOWS: if context.use_ninja: if NINJA_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'make' executable") yield BuildAction(prefix + [NINJA_EXECUTABLE] + context.make_flags) else: if MAKE_EXECUTABLE is None: raise VerbExecutionError( "Could not find 'make' executable") yield BuildAction(prefix + [MAKE_EXECUTABLE] + context.make_flags) else: if MSBUILD_EXECUTABLE is None: raise VerbExecutionError("Could not find 'msbuild' executable") solution_file = solution_file_exists_at( context.build_space, context.package_manifest.name) cmd = prefix + [MSBUILD_EXECUTABLE] env = None # Convert make parallelism flags into msbuild flags msbuild_flags = [ x.replace('-j', '/m:') for x in context.make_flags if x.startswith('-j') ] if msbuild_flags: cmd += msbuild_flags # If there is a parallelism flag in msbuild_flags and it's not /m1, # then turn on /MP for the compiler (intra-project parallelism) if any([x.startswith('/m') for x in msbuild_flags]) and \ '/m:1' not in msbuild_flags: env = dict(os.environ) if 'CL' in env: # make sure env['CL'] doesn't include an /MP already if not any([ x.startswith('/MP') for x in env['CL'].split(' ') ]): env['CL'] += ' /MP' else: # CL not in environment; let's add it with our flag env['CL'] = '/MP' cmd += [ '/p:Configuration=%s' % self._get_visual_studio_configuration(context), solution_file ] yield BuildAction(cmd, env=env)
def on_uninstall(self, context): yield BuildAction(self._prepare_cmd(context, gradle_task='clean'), cwd=context.build_space)
def on_test(self, context): yield BuildAction(self._prepare_cmd(context, gradle_task='test'), cwd=context.build_space)