def prepare_build(self): if self.build_reference != self._package_reference and \ os.path.exists(self.build_folder) and hasattr(self._conan_file, "build_id"): self._skip_build = True return # build_id is not caching the build folder, so actually rebuild the package _handle_system_requirements(self._conan_file, self._package_reference, self._client_cache, self._out) export_folder = self._client_cache.export(self._conan_ref) export_source_folder = self._client_cache.export_sources( self._conan_ref, self._conan_file.short_paths) try: rmdir(self.build_folder) rmdir(self.package_folder) except OSError as e: raise ConanException( "%s\n\nCouldn't remove folder, might be busy or open\n" "Close any app using it, and retry" % str(e)) self._out.info('Building your package in %s' % self.build_folder) sources_pointer = self._client_cache.scm_folder(self._conan_ref) local_sources_path = load(sources_pointer) if os.path.exists( sources_pointer) else None config_source(export_folder, export_source_folder, local_sources_path, self.source_folder, self._conan_file, self._out) self._out.info('Copying sources to build folder') if getattr(self._conan_file, 'no_copy_source', False): mkdir(self.build_folder) self._conan_file.source_folder = self.source_folder else: if platform.system( ) == "Windows" and os.getenv("CONAN_USER_HOME_SHORT") != "None": from conans.util.windows import ignore_long_path_files ignore = ignore_long_path_files(self.source_folder, self.build_folder, self._out) else: ignore = None shutil.copytree(self.source_folder, self.build_folder, symlinks=True, ignore=ignore) logger.debug("Copied to %s", self.build_folder) logger.debug("Files copied %s", os.listdir(self.build_folder)) self._conan_file.source_folder = self.build_folder
def prepare_build(self): if os.path.exists(self.build_folder) and hasattr( self._conan_file, "build_id"): self._skip_build = True return # build_id is not caching the build folder, so actually rebuild the package _handle_system_requirements(self._conan_file, self._package_reference, self._client_cache, self._out) package_folder = self._client_cache.package( self._package_reference, self._conan_file.short_paths) src_folder = self._client_cache.source(self._conan_ref, self._conan_file.short_paths) export_folder = self._client_cache.export(self._conan_ref) export_source_folder = self._client_cache.export_sources( self._conan_ref, self._conan_file.short_paths) try: rmdir(self.build_folder) rmdir(package_folder) except OSError as e: raise ConanException( "%s\n\nCouldn't remove folder, might be busy or open\n" "Close any app using it, and retry" % str(e)) self._out.info('Building your package in %s' % self.build_folder) config_source(export_folder, export_source_folder, src_folder, self._conan_file, self._out) self._out.info('Copying sources to build folder') if getattr(self._conan_file, 'no_copy_source', False): mkdir(self.build_folder) self._conan_file.source_folder = src_folder else: if not long_paths_support: from conans.util.windows import ignore_long_path_files ignore = ignore_long_path_files(src_folder, self.build_folder, self._out) else: ignore = None shutil.copytree(src_folder, self.build_folder, symlinks=True, ignore=ignore) logger.debug("Copied to %s", self.build_folder) logger.debug("Files copied %s", os.listdir(self.build_folder)) self._conan_file.source_folder = self.build_folder
def prepare_build(self): if self.build_reference != self._package_reference and \ os.path.exists(self.build_folder) and hasattr(self._conan_file, "build_id"): self._skip_build = True return # build_id is not caching the build folder, so actually rebuild the package _handle_system_requirements(self._conan_file, self._package_reference, self._client_cache, self._out) export_folder = self._client_cache.export(self._conan_ref) export_source_folder = self._client_cache.export_sources(self._conan_ref, self._conan_file.short_paths) try: rmdir(self.build_folder) rmdir(self.package_folder) except OSError as e: raise ConanException("%s\n\nCouldn't remove folder, might be busy or open\n" "Close any app using it, and retry" % str(e)) self._out.info('Building your package in %s' % self.build_folder) config_source(export_folder, export_source_folder, self.source_folder, self._conan_file, self._out) self._out.info('Copying sources to build folder') if getattr(self._conan_file, 'no_copy_source', False): mkdir(self.build_folder) self._conan_file.source_folder = self.source_folder else: if platform.system() == "Windows" and os.getenv("CONAN_USER_HOME_SHORT") != "None": from conans.util.windows import ignore_long_path_files ignore = ignore_long_path_files(self.source_folder, self.build_folder, self._out) else: ignore = None shutil.copytree(self.source_folder, self.build_folder, symlinks=True, ignore=ignore) logger.debug("Copied to %s", self.build_folder) logger.debug("Files copied %s", os.listdir(self.build_folder)) self._conan_file.source_folder = self.build_folder
def _build_package(self): """ 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. Receives the build_folder because it can change if the method build_id() exists """ package_folder = self._client_cache.package( self._package_reference, self._conan_file.short_paths) src_folder = self._client_cache.source(self._conan_ref, self._conan_file.short_paths) export_folder = self._client_cache.export(self._conan_ref) export_source_folder = self._client_cache.export_sources( self._conan_ref, self._conan_file.short_paths) try: rmdir(self.build_folder) rmdir(package_folder) except Exception as e: raise ConanException( "%s\n\nCouldn't remove folder, might be busy or open\n" "Close any app using it, and retry" % str(e)) self._out.info('Building your package in %s' % self.build_folder) config_source(export_folder, export_source_folder, src_folder, self._conan_file, self._out) self._out.info('Copying sources to build folder') if getattr(self._conan_file, 'no_copy_source', False): mkdir(self.build_folder) self._conan_file.source_folder = src_folder else: if platform.system( ) == "Windows" and os.getenv("CONAN_USER_HOME_SHORT") != "None": from conans.util.windows import ignore_long_path_files ignore = ignore_long_path_files(src_folder, self.build_folder, self._out) else: ignore = None shutil.copytree(src_folder, self.build_folder, symlinks=True, ignore=ignore) logger.debug("Copied to %s" % self.build_folder) logger.debug("Files copied %s" % os.listdir(self.build_folder)) self._conan_file.source_folder = self.build_folder os.chdir(self.build_folder) self._conan_file.build_folder = self.build_folder self._conan_file._conanfile_directory = self.build_folder # Read generators from conanfile and generate the needed files logger.debug("Writing generators") write_generators(self._conan_file, self.build_folder, self._out) logger.debug("Files copied after generators %s" % os.listdir(self.build_folder)) # 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 run_imports copied_files = run_imports(self._conan_file, self.build_folder, self._out) try: # This is necessary because it is different for user projects # than for packages logger.debug( "Call conanfile.build() with files in build folder: %s" % os.listdir(self.build_folder)) self._out.highlight("Calling build()") with conanfile_exception_formatter(str(self._conan_file), "build"): self._conan_file.build() self._out.success("Package '%s' built" % self._conan_file.info.package_id()) self._out.info("Build folder %s" % self.build_folder) except Exception as exc: os.chdir(src_folder) self._out.writeln("") self._out.error("Package '%s' build failed" % self._conan_file.info.package_id()) self._out.warn("Build folder %s" % self.build_folder) if isinstance(exc, ConanExceptionInUserConanfileMethod): raise exc raise ConanException(exc) finally: self._conan_file._conanfile_directory = export_folder # Now remove all files that were imported with imports() for f in copied_files: try: if f.startswith(self.build_folder): os.remove(f) except Exception: self._out.warn( "Unable to remove imported file from build: %s" % f)