def install(self, reference, current_path, remote=None, options=None, settings=None, build_mode=False, filename=None, update=False, check_updates=False, integrity=False, scopes=None, generators=None): """ Fetch and build all dependencies for the given reference @param reference: ConanFileReference or path to user space conanfile @param current_path: where the output files will be saved @param remote: install only from that remote @param options: list of tuples: [(optionname, optionvalue), (optionname, optionvalue)...] @param settings: list of tuples: [(settingname, settingvalue), (settingname, value)...] """ generators = generators or [] objects = self._get_graph(reference, current_path, remote, options, settings, filename, update, check_updates, integrity, scopes) (_, deps_graph, _, registry, conanfile, remote_proxy, loader) = objects Printer(self._user_io.out).print_graph(deps_graph, registry) # Warn if os doesn't match try: if detected_os() != loader._settings.os: message = '''You are building this package with settings.os='%s' on a '%s' system. If this is your intention, you can ignore this message. If not: - Check the passed settings (-s) - Check your global settings in ~/.conan/conan.conf - Remove conaninfo.txt to avoid bad cached settings ''' % (loader._settings.os, detected_os()) self._user_io.out.warn(message) except ConanException: # Setting os doesn't exist pass installer = ConanInstaller(self._paths, self._user_io, remote_proxy) installer.install(deps_graph, build_mode) scope_prefix = "PROJECT" if not isinstance(reference, ConanFileReference) else str(reference) output = ScopedOutput(scope_prefix, self._user_io.out) # Write generators tmp = list(conanfile.generators) # Add the command line specified generators tmp.extend(generators) conanfile.generators = tmp write_generators(conanfile, current_path, output) if not isinstance(reference, ConanFileReference): content = normalize(conanfile.info.dumps()) save(os.path.join(current_path, CONANINFO), content) output.info("Generated %s" % CONANINFO) local_installer = FileImporter(deps_graph, self._paths, current_path) conanfile.copy = local_installer conanfile.imports() copied_files = local_installer.execute() import_output = ScopedOutput("%s imports()" % output.scope, output) report_copied_files(copied_files, import_output)
def _build_package(self, export_folder, src_folder, build_folder, package_folder, conan_file, output): """ builds the package, creating the corresponding build folder if necessary and copying there the contents from the src folder. The code is duplicated in every build, as some configure processes actually change the source code """ output.info('Building your package in %s' % build_folder) if not os.path.exists(build_folder): self._config_source(export_folder, src_folder, conan_file, output) output.info('Copying sources to build folder') shutil.copytree(src_folder, build_folder, symlinks=True) os.chdir(build_folder) conan_file._conanfile_directory = build_folder # Read generators from conanfile and generate the needed files write_generators(conan_file, build_folder, output) # Build step might need DLLs, binaries as protoc to generate source files # So execute imports() before build, storing the list of copied_files from conans.client.importer import FileImporter local_installer = FileImporter(self._deps_graph, self._paths, build_folder) conan_file.copy = local_installer conan_file.imports() copied_files = local_installer.execute() try: # This is necessary because it is different for user projects # than for packages conan_file._conanfile_directory = build_folder conan_file.package_folder = package_folder conan_file.build() self._out.writeln("") output.success("Package '%s' built" % os.path.basename(build_folder)) output.info("Build folder %s" % build_folder) except Exception as e: os.chdir(src_folder) self._out.writeln("") output.error("Package '%s' build failed" % os.path.basename(build_folder)) output.warn("Build folder %s" % build_folder) raise ConanException("%s: %s" % (conan_file.name, str(e))) finally: conan_file._conanfile_directory = export_folder # Now remove all files that were imported with imports() for f in copied_files: try: os.remove(f) except Exception: self._out.warn( "Unable to remove imported file from build: %s" % f)
def install(self, reference, current_path, remote=None, options=None, settings=None, build_mode=False, info=None): """ Fetch and build all dependencies for the given reference param reference: ConanFileReference or path to user space conanfile param current_path: where the output files will be saved param remote: install only from that remote param options: written in JSON, e.g. {"compiler": "Visual Studio 12", ...} """ if not isinstance(reference, ConanFileReference): conanfile_path = reference reference = None loader = self._loader(current_path, settings, options) installer = ConanInstaller(self._paths, self._user_io, loader, self.remote_manager, remote) if reference: conanfile = installer.retrieve_conanfile(reference, consumer=True) else: try: conan_file_path = os.path.join(conanfile_path, CONANFILE) conanfile = loader.load_conan(conan_file_path, consumer=True) is_txt = False except NotFoundException: # Load requirements.txt conan_path = os.path.join(conanfile_path, CONANFILE_TXT) conanfile = loader.load_conan_txt(conan_path) is_txt = True # build deps graph and install it builder = DepsBuilder(installer, self._user_io.out) deps_graph = builder.load(reference, conanfile) if info: Printer(self._user_io.out).print_info(deps_graph, info) return Printer(self._user_io.out).print_graph(deps_graph) installer.install(deps_graph, build_mode) if not reference: if is_txt: conanfile.info.settings = loader._settings.values conanfile.info.full_settings = loader._settings.values save(os.path.join(current_path, CONANINFO), conanfile.info.dumps()) self._user_io.out.info("Generated %s" % CONANINFO) write_generators(conanfile, current_path, self._user_io.out) local_installer = FileImporter(deps_graph, self._paths, current_path) conanfile.copy = local_installer conanfile.imports() local_installer.execute()
def _build_package(self, export_folder, src_folder, build_folder, conan_file, output): """ builds the package, creating the corresponding build folder if necessary and copying there the contents from the src folder. The code is duplicated in every build, as some configure processes actually change the source code """ output.info("Building your package in %s" % build_folder) if not os.path.exists(build_folder): self._config_source(export_folder, src_folder, conan_file, output) output.info("Copying sources to build folder") shutil.copytree(src_folder, build_folder, symlinks=True) os.chdir(build_folder) conan_file._conanfile_directory = build_folder # Read generators from conanfile and generate the needed files write_generators(conan_file, build_folder, output) # Build step might need DLLs, binaries as protoc to generate source files # So execute imports() before build, storing the list of copied_files from conans.client.importer import FileImporter local_installer = FileImporter(self._deps_graph, self._paths, build_folder) conan_file.copy = local_installer conan_file.imports() copied_files = local_installer.execute() try: # This is necessary because it is different for user projects # than for packages conan_file._conanfile_directory = build_folder conan_file.build() self._out.writeln("") output.success("Package '%s' built" % os.path.basename(build_folder)) output.info("Build folder %s" % build_folder) except Exception as e: os.chdir(src_folder) self._out.writeln("") output.error("Package '%s' build failed" % os.path.basename(build_folder)) output.warn("Build folder %s" % build_folder) raise ConanException("%s: %s" % (conan_file.name, str(e))) finally: conan_file._conanfile_directory = export_folder # Now remove all files that were imported with imports() for f in copied_files: try: os.remove(f) except Exception: self._out.warn("Unable to remove imported file from build: %s" % f)
def install(self, reference, current_path, remote=None, options=None, settings=None, build_mode=False, info=None, filename=None, update=False): """ Fetch and build all dependencies for the given reference @param reference: ConanFileReference or path to user space conanfile @param current_path: where the output files will be saved @param remote: install only from that remote @param options: list of tuples: [(optionname, optionvalue), (optionname, optionvalue)...] @param settings: list of tuples: [(settingname, settingvalue), (settingname, value)...] """ reference_given = True if not isinstance(reference, ConanFileReference): conanfile_path = reference reference_given = False reference = None loader = self._loader(current_path, settings, options) # Not check for updates for info command, it'll be checked when dep graph is built check_updates = not info remote_proxy = ConanProxy(self._paths, self._user_io, self._remote_manager, remote, update, check_updates) if reference_given: project_reference = None conanfile_path = remote_proxy.get_conanfile(reference) output = ScopedOutput(str(reference), self._user_io.out) conanfile = loader.load_conan(conanfile_path, output, consumer=True) else: project_reference = "PROJECT" output = ScopedOutput(project_reference, self._user_io.out) try: if filename and filename.endswith(".txt"): raise NotFoundException("") conan_file_path = os.path.join(conanfile_path, filename or CONANFILE) conanfile = loader.load_conan(conan_file_path, output, consumer=True) is_txt = False if conanfile.name is not None and conanfile.version is not None: project_reference = "%s/%s@" % (conanfile.name, conanfile.version) project_reference += "PROJECT" except NotFoundException: # Load requirements.txt conan_path = os.path.join(conanfile_path, filename or CONANFILE_TXT) conanfile = loader.load_conan_txt(conan_path, output) is_txt = True # build deps graph and install it builder = DepsBuilder(remote_proxy, self._user_io.out, loader) deps_graph = builder.load(reference, conanfile) registry = RemoteRegistry(self._paths.registry, self._user_io.out) if info: graph_updates_info = builder.get_graph_updates_info(deps_graph) Printer(self._user_io.out).print_info(deps_graph, project_reference, info, registry, graph_updates_info, remote) return Printer(self._user_io.out).print_graph(deps_graph, registry) installer = ConanInstaller(self._paths, self._user_io, remote_proxy) installer.install(deps_graph, build_mode) if not reference_given: if is_txt: conanfile.info.settings = loader._settings.values # Just in case the current package is header only, we still store the full settings # for reference and compiler checks conanfile.info.full_settings = loader._settings.values content = normalize(conanfile.info.dumps()) save(os.path.join(current_path, CONANINFO), content) output.info("Generated %s" % CONANINFO) write_generators(conanfile, current_path, output) local_installer = FileImporter(deps_graph, self._paths, current_path) conanfile.copy = local_installer conanfile.imports() copied_files = local_installer.execute() import_output = ScopedOutput("%s imports()" % output.scope, output) report_copied_files(copied_files, import_output)
def _build_package(self, export_folder, src_folder, build_folder, package_folder, conan_file, output): """ builds the package, creating the corresponding build folder if necessary and copying there the contents from the src folder. The code is duplicated in every build, as some configure processes actually change the source code """ output.info('Building your package in %s' % build_folder) if not os.path.exists(build_folder): self._config_source(export_folder, src_folder, conan_file, output) output.info('Copying sources to build folder') def check_max_path_len(src, files): if platform.system() != "Windows": return [] filtered_files = [] for the_file in files: source_path = os.path.join(src, the_file) # Without storage path, just relative rel_path = os.path.relpath(source_path, src_folder) dest_path = os.path.normpath( os.path.join(build_folder, rel_path)) # it is NOT that "/" is counted as "\\" so it counts double # seems a bug in python, overflows paths near the limit of 260, if len(dest_path) >= 249: filtered_files.append(the_file) output.warn("Filename too long, file excluded: %s" % dest_path) return filtered_files shutil.copytree(src_folder, build_folder, symlinks=True, ignore=check_max_path_len) os.chdir(build_folder) conan_file._conanfile_directory = build_folder # Read generators from conanfile and generate the needed files write_generators(conan_file, build_folder, output) # Build step might need DLLs, binaries as protoc to generate source files # So execute imports() before build, storing the list of copied_files from conans.client.importer import FileImporter local_installer = FileImporter(self._deps_graph, self._paths, build_folder) conan_file.copy = local_installer conan_file.imports() copied_files = local_installer.execute() try: # This is necessary because it is different for user projects # than for packages conan_file._conanfile_directory = build_folder conan_file.package_folder = package_folder conan_file.build() self._out.writeln("") output.success("Package '%s' built" % os.path.basename(build_folder)) output.info("Build folder %s" % build_folder) except Exception as e: os.chdir(src_folder) self._out.writeln("") output.error("Package '%s' build failed" % os.path.basename(build_folder)) output.warn("Build folder %s" % build_folder) raise ConanException("%s: %s" % (conan_file.name, str(e))) finally: conan_file._conanfile_directory = export_folder # Now remove all files that were imported with imports() for f in copied_files: try: os.remove(f) except Exception: self._out.warn( "Unable to remove imported file from build: %s" % f)
def install(self, reference, current_path, remote=None, options=None, settings=None, build_mode=False, info=None, filename=None, update=False): """ Fetch and build all dependencies for the given reference @param reference: ConanFileReference or path to user space conanfile @param current_path: where the output files will be saved @param remote: install only from that remote @param options: list of tuples: [(optionname, optionvalue), (optionname, optionvalue)...] @param settings: list of tuples: [(settingname, settingvalue), (settingname, settingvalue)...] """ reference_given = True if not isinstance(reference, ConanFileReference): conanfile_path = reference reference_given = False reference = None loader = self._loader(current_path, settings, options) # Not check for updates for info command, it'll be checked when dep graph is built check_updates = not info remote_proxy = ConanProxy(self._paths, self._user_io, self._remote_manager, remote, update, check_updates) if reference_given: project_reference = None conanfile_path = remote_proxy.get_conanfile(reference) output = ScopedOutput(str(reference), self._user_io.out) conanfile = loader.load_conan(conanfile_path, output, consumer=True) else: project_reference = "PROJECT" output = ScopedOutput(project_reference, self._user_io.out) try: if filename and filename.endswith(".txt"): raise NotFoundException() conan_file_path = os.path.join(conanfile_path, filename or CONANFILE) conanfile = loader.load_conan(conan_file_path, output, consumer=True) is_txt = False if conanfile.name is not None and conanfile.version is not None: project_reference = "%s/%s@" % (conanfile.name, conanfile.version) project_reference += "PROJECT" except NotFoundException: # Load requirements.txt conan_path = os.path.join(conanfile_path, filename or CONANFILE_TXT) conanfile = loader.load_conan_txt(conan_path, output) is_txt = True # build deps graph and install it builder = DepsBuilder(remote_proxy, self._user_io.out, loader) deps_graph = builder.load(reference, conanfile) registry = RemoteRegistry(self._paths.registry, self._user_io.out) if info: graph_updates_info = builder.get_graph_updates_info(deps_graph) Printer(self._user_io.out).print_info(deps_graph, project_reference, info, registry, graph_updates_info, remote) return Printer(self._user_io.out).print_graph(deps_graph, registry) installer = ConanInstaller(self._paths, self._user_io, remote_proxy) installer.install(deps_graph, build_mode) if not reference_given: if is_txt: conanfile.info.settings = loader._settings.values # Just in case the current package is header only, we still store the full settings # for reference and compiler checks conanfile.info.full_settings = loader._settings.values content = normalize(conanfile.info.dumps()) save(os.path.join(current_path, CONANINFO), content) output.info("Generated %s" % CONANINFO) write_generators(conanfile, current_path, output) local_installer = FileImporter(deps_graph, self._paths, current_path) conanfile.copy = local_installer conanfile.imports() local_installer.execute()
def install(self, reference, current_path, remote=None, options=None, settings=None, build_mode=False, info=None, filename=None, update=False, check_updates=False, integrity=False, scopes=None): """ Fetch and build all dependencies for the given reference @param reference: ConanFileReference or path to user space conanfile @param current_path: where the output files will be saved @param remote: install only from that remote @param options: list of tuples: [(optionname, optionvalue), (optionname, optionvalue)...] @param settings: list of tuples: [(settingname, settingvalue), (settingname, value)...] """ reference_given = True if not isinstance(reference, ConanFileReference): conanfile_path = reference reference_given = False reference = None loader = self._loader(current_path, settings, options, scopes) # Not check for updates for info command, it'll be checked when dep graph is built remote_proxy = ConanProxy(self._paths, self._user_io, self._remote_manager, remote, update=update, check_updates=check_updates, check_integrity=integrity) if reference_given: project_reference = None conanfile_path = remote_proxy.get_conanfile(reference) output = ScopedOutput(str(reference), self._user_io.out) conanfile = loader.load_conan(conanfile_path, output, consumer=True) else: project_reference = "PROJECT" output = ScopedOutput(project_reference, self._user_io.out) try: if filename and filename.endswith(".txt"): raise NotFoundException("") conan_file_path = os.path.join(conanfile_path, filename or CONANFILE) conanfile = loader.load_conan(conan_file_path, output, consumer=True) is_txt = False if conanfile.name is not None and conanfile.version is not None: project_reference = "%s/%s@" % (conanfile.name, conanfile.version) project_reference += "PROJECT" except NotFoundException: # Load requirements.txt conan_path = os.path.join(conanfile_path, filename or CONANFILE_TXT) conanfile = loader.load_conan_txt(conan_path, output) is_txt = True # build deps graph and install it builder = DepsBuilder(remote_proxy, self._user_io.out, loader) deps_graph = builder.load(reference, conanfile) registry = RemoteRegistry(self._paths.registry, self._user_io.out) if info: if check_updates: graph_updates_info = builder.get_graph_updates_info(deps_graph) else: graph_updates_info = {} Printer(self._user_io.out).print_info(deps_graph, project_reference, info, registry, graph_updates_info, remote) return Printer(self._user_io.out).print_graph(deps_graph, registry) # Warn if os doesn't match try: if detected_os() != conanfile.settings.os: message = '''You are building this package with settings.os='%s' on a '%s' system. If this is your intention, you can ignore this message. If not: - Check the passed settings (-s) - Check your global settings in ~/.conan/conan.conf - Remove conaninfo.txt to avoid bad cached settings ''' % (conanfile.settings.os, detected_os()) self._user_io.out.warn(message) except ConanException: # Setting os doesn't exist pass installer = ConanInstaller(self._paths, self._user_io, remote_proxy) installer.install(deps_graph, build_mode) if not reference_given: if is_txt: conanfile.info.settings = loader._settings.values # Just in case the current package is header only, we still store the full settings # for reference and compiler checks conanfile.info.full_settings = loader._settings.values conanfile.info.scope = self._current_scopes content = normalize(conanfile.info.dumps()) save(os.path.join(current_path, CONANINFO), content) output.info("Generated %s" % CONANINFO) write_generators(conanfile, current_path, output) local_installer = FileImporter(deps_graph, self._paths, current_path) conanfile.copy = local_installer conanfile.imports() copied_files = local_installer.execute() import_output = ScopedOutput("%s imports()" % output.scope, output) report_copied_files(copied_files, import_output)
def _build_package(self, export_folder, src_folder, build_folder, package_folder, conan_file, output): """ builds the package, creating the corresponding build folder if necessary and copying there the contents from the src folder. The code is duplicated in every build, as some configure processes actually change the source code """ output.info('Building your package in %s' % build_folder) if not os.path.exists(build_folder): self._config_source(export_folder, src_folder, conan_file, output) output.info('Copying sources to build folder') def check_max_path_len(src, files): if platform.system() != "Windows": return [] filtered_files = [] for the_file in files: source_path = os.path.join(src, the_file) # Without storage path, just relative rel_path = os.path.relpath(source_path, src_folder) dest_path = os.path.normpath(os.path.join(build_folder, rel_path)) # it is NOT that "/" is counted as "\\" so it counts double # seems a bug in python, overflows paths near the limit of 260, if len(dest_path) >= 249: filtered_files.append(the_file) output.warn("Filename too long, file excluded: %s" % dest_path) return filtered_files shutil.copytree(src_folder, build_folder, symlinks=True, ignore=check_max_path_len) os.chdir(build_folder) conan_file._conanfile_directory = build_folder # Read generators from conanfile and generate the needed files write_generators(conan_file, build_folder, output) # Build step might need DLLs, binaries as protoc to generate source files # So execute imports() before build, storing the list of copied_files from conans.client.importer import FileImporter local_installer = FileImporter(self._deps_graph, self._paths, build_folder) conan_file.copy = local_installer conan_file.imports() copied_files = local_installer.execute() try: # This is necessary because it is different for user projects # than for packages conan_file._conanfile_directory = build_folder conan_file.package_folder = package_folder conan_file.build() self._out.writeln("") output.success("Package '%s' built" % os.path.basename(build_folder)) output.info("Build folder %s" % build_folder) except Exception as e: os.chdir(src_folder) self._out.writeln("") output.error("Package '%s' build failed" % os.path.basename(build_folder)) output.warn("Build folder %s" % build_folder) raise ConanException("%s: %s" % (conan_file.name, str(e))) finally: conan_file._conanfile_directory = export_folder # Now remove all files that were imported with imports() for f in copied_files: try: os.remove(f) except Exception: self._out.warn("Unable to remove imported file from build: %s" % f)
def install(self, reference, current_path, remote=None, options=None, settings=None, build_mode=False, info=None, filename=None): """ Fetch and build all dependencies for the given reference @param reference: ConanFileReference or path to user space conanfile @param current_path: where the output files will be saved @param remote: install only from that remote @param options: written in JSON, e.g. {"compiler": "Visual Studio 12", ...} """ reference_given = True if not isinstance(reference, ConanFileReference): conanfile_path = reference reference_given = False reference = None loader = self._loader(current_path, settings, options) installer = ConanInstaller(self._paths, self._user_io, loader, self.remote_manager, remote) if reference_given: project_reference = None conanfile = installer.retrieve_conanfile(reference, consumer=True) else: project_reference = "PROJECT" output = ScopedOutput(project_reference, self._user_io.out) try: if filename and filename.endswith(".txt"): raise NotFoundException() conan_file_path = os.path.join(conanfile_path, filename or CONANFILE) conanfile = loader.load_conan(conan_file_path, output, consumer=True) is_txt = False if conanfile.name is not None and conanfile.version is not None: project_reference = "%s/%s@" % (conanfile.name, conanfile.version) # Calculate a placeholder conan file reference for the project current_user = self._localdb.get_username() if current_user: project_reference += "%s/" % current_user project_reference += "PROJECT" except NotFoundException: # Load requirements.txt conan_path = os.path.join(conanfile_path, filename or CONANFILE_TXT) conanfile = loader.load_conan_txt(conan_path, output) is_txt = True # build deps graph and install it builder = DepsBuilder(installer, self._user_io.out) deps_graph = builder.load(reference, conanfile) if info: Printer(self._user_io.out).print_info(deps_graph, project_reference, info) return Printer(self._user_io.out).print_graph(deps_graph) installer.install(deps_graph, build_mode) if not reference_given: if is_txt: conanfile.info.settings = loader._settings.values # Just in case the current package is header only, we still store the full settings # for reference and compiler checks conanfile.info.full_settings = loader._settings.values content = normalize(conanfile.info.dumps()) save(os.path.join(current_path, CONANINFO), content) self._user_io.out.writeln("") output.info("Generated %s" % CONANINFO) write_generators(conanfile, current_path, output) local_installer = FileImporter(deps_graph, self._paths, current_path) conanfile.copy = local_installer conanfile.imports() local_installer.execute()