def _adjust_path(self, path): if self._base_compiler == 'Visual Studio': path = path.replace('/', '\\') else: path = path.replace('\\', '/') path = subsystem_path(self._subsystem, path) return '"%s"' % path if ' ' in path else path
def environment_wrap_command(env_filenames, cmd, subsystem=None, cwd=None): from conan.tools.microsoft.subsystems import subsystem_path assert env_filenames filenames = [env_filenames ] if not isinstance(env_filenames, list) else env_filenames bats, shs = [], [] cwd = cwd or os.getcwd() for f in filenames: f = f if os.path.isabs(f) else os.path.join(cwd, f) if f.lower().endswith(".sh"): if os.path.isfile(f): f = subsystem_path(subsystem, f) shs.append(f) elif f.lower().endswith(".bat"): if os.path.isfile(f): bats.append(f) else: # Simple name like "conanrunenv" path_bat = "{}.bat".format(f) path_sh = "{}.sh".format(f) if os.path.isfile(path_bat): bats.append(path_bat) elif os.path.isfile(path_sh): path_sh = subsystem_path(subsystem, path_sh) shs.append(path_sh) if bats and shs: raise ConanException( "Cannot wrap command with different envs, {} - {}".format( bats, shs)) if bats: launchers = " && ".join('"{}"'.format(b) for b in bats) return '{} && {}'.format(launchers, cmd) elif shs: launchers = " && ".join('. "{}"'.format(f) for f in shs) return '{} && {}'.format(launchers, cmd) else: return cmd
def configure(self, build_script_folder=None): """ http://jingfenghanmax.blogspot.com.es/2010/09/configure-with-host-target-and-build.html https://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html """ source = self._conanfile.source_folder if build_script_folder: source = os.path.join(self._conanfile.source_folder, build_script_folder) configure_cmd = "{}/configure".format(source) subsystem = deduce_subsystem(self._conanfile, scope="build") configure_cmd = subsystem_path(subsystem, configure_cmd) cmd = "{} {}".format(configure_cmd, self._configure_args) self._conanfile.output.info("Calling:\n > %s" % cmd) self._conanfile.run(cmd)
def _generate_aggregated_env(conanfile): from conan.tools.microsoft.subsystems import subsystem_path def deactivates(filenames): # FIXME: Probably the order needs to be reversed result = [] for s in filenames: folder, f = os.path.split(s) result.append(os.path.join(folder, "deactivate_{}".format(f))) return result for group, env_scripts in conanfile.env_scripts.items(): subsystem = deduce_subsystem(conanfile, group) bats = [] shs = [] for env_script in env_scripts: path = os.path.join(conanfile.generators_folder, env_script) if env_script.endswith(".bat"): bats.append(path) elif env_script.endswith(".sh"): shs.append(subsystem_path(subsystem, path)) if shs: def sh_content(files): return ". " + " && . ".join('"{}"'.format(s) for s in files) filename = "conan{}.sh".format(group) save(os.path.join(conanfile.generators_folder, filename), sh_content(shs)) save( os.path.join(conanfile.generators_folder, "deactivate_{}".format(filename)), sh_content(deactivates(shs))) if bats: def bat_content(files): return "\r\n".join(["@echo off"] + ['call "{}"'.format(b) for b in files]) filename = "conan{}.bat".format(group) save(os.path.join(conanfile.generators_folder, filename), bat_content(bats)) save( os.path.join(conanfile.generators_folder, "deactivate_{}".format(filename)), bat_content(deactivates(bats)))
def get_str(self, placeholder, subsystem, pathsep): """ :param subsystem: :param placeholder: a OS dependant string pattern of the previous env-var value like $PATH, %PATH%, et :param pathsep: The path separator, typically ; or : :return: a string representation of the env-var value, including the $NAME-like placeholder """ values = [] for v in self._values: if v is _EnvVarPlaceHolder: if placeholder: values.append(placeholder.format(name=self._name)) else: if self._path: from conan.tools.microsoft.subsystems import subsystem_path v = subsystem_path(subsystem, v) values.append(v) if self._path: return pathsep.join(values) return self._sep.join(values)