def common( self, log_dir: str ) -> bool: # TODO should I add override config compilation for tests? info('common tests for ' + self.project_name) all_src = self.__get_all_files(self.test_path, 'erl') if self.__do_compile(all_src, output=self.test_path): return self.__do_common_test(log_dir) return False
def fetch_package(self, dep: Package): temp_path = join(self.temp_dir, dep.name) info('fetch ' + temp_path) remove_dir(temp_path) vsn, need_lock = self.__get_vsn(dep) hash_str = LocalCache.fetch(dep.url, vsn, temp_path) dep.update_from_cache(temp_path) if need_lock: self.set_lock(dep, hash_str)
def __rescan_deps(self): deps_dir = join(self.project.path, 'deps') deps = listdir(deps_dir) for dep in deps: # TODO clear old locks too? if dep not in self.packages: dep_path = join(deps_dir, dep) info('Drop dead dep: ' + dep_path) if os.path.islink(dep_path): os.remove(dep_path) else: remove_dir(dep_path)
def unpackage( self, package: Package ): # TODO move me to package? use current dir + <something> instead of temp unpack_dir = join(self.temp_dir, package.fullname) enotpack = join(package.path, package.name + '.ep') ensure_empty(unpack_dir) info('Extract ' + enotpack) with tarfile.open(enotpack) as pack: pack.extractall(unpack_dir) package.path = unpack_dir # update path pointer copy_file(enotpack, join(unpack_dir, package.name + '.ep'))
def unit( self ) -> bool: # TODO run unit tests only for modules with include eunit lib? info('unit tests for ' + self.project_name) debug('run eunit in ' + self.test_path) all_src = self.__get_all_files(self.test_path, 'erl') ensure_dir(self.output_path) if self.__do_compile(all_src, output=self.test_path): modules, test_dirs = self.__get_test_directories( all_src, drop_extension='_SUITE') return self.__do_unit_test(modules, test_dirs) return False
def uninstall(self, fullname: str) -> bool: packages = self.__search_by_name(fullname) if not packages: warning(fullname + ' not installed') return False for package in packages: vsn = package['vsn'] erlang_vsns = self.local_cache.get_erl_versions(fullname, package['vsn']) [latest_erl] = erlang_vsns[-1:] pack = Package.from_path(join(self.local_cache.path, fullname, vsn, latest_erl)) if not pack.uninstall(): warning('Can\'t uninstall package ' + fullname + ': ' + vsn) return False info(fullname + ': ' + vsn + ' uninstalled') self.__remove_from_installed(fullname, vsn) return True
def __compare_vsns(self, dep: Package, pkg_vsn): if not self.compare_versions: raise ValueError # skip vsn check - always prefer versions closer to root [major1, minor1, bug1] = try_get_semver(dep.git_vsn) [major2, minor2, bug2] = try_get_semver(pkg_vsn) if major1 != major2: raise RuntimeError('Deps ' + dep.name + ' has incompatible versions: ' + pkg_vsn + ' vs ' + dep.git_vsn) if minor1 > minor2 or bug1 > bug2: # dep is newer than selected - prefer it info('Prefer newer version for ' + dep.name + ', ' + pkg_vsn + ' -> ' + dep.git_vsn) self.packages[dep.name] = dep # TODO try use same repo to speed up new vsn fetch self.system_config.cache.populate(dep) return dep.deps return []
def install(self, fullname: str, maybe_version: str or None) -> bool: vsn = self.get_package_version(fullname, maybe_version) if not self.system_config.cache.check_exists_local(fullname, vsn): if not self.fetch(fullname, vsn): warning('No ' + fullname + ':' + vsn + ' in local cache. Can\'t fetch it either.') info('Available versions for ' + fullname + ': ' + str(self.local_cache.get_versions(fullname))) return False erlang_vsns = self.local_cache.get_erl_versions(fullname, vsn) [latest_erl] = erlang_vsns[-1:] # populate and build deps builder = Builder.init_from_path(join(self.local_cache.path, fullname, vsn, latest_erl)) builder.populate() builder.deps() if builder.project.install(self.system_config, latest_erl): self.__add_to_installed(fullname, vsn) info(fullname + ': ' + vsn + ' installed') return True return False
def __build_deps(self, package: Package, is_subpackage=True): info('build deps for ' + package.name) is_first_line = package is not self.project if (is_subpackage and not self.project.config.link_all and self.system_config.cache.exists_local(package)): return True # skip building dep's dep if not link all and dep was already built for dep in package.deps: if not self.system_config.cache.exists_local(dep): # if package not in cache - build and add to cache if not self.__build_tree(dep): raise RuntimeError('Can\'t built dep ' + dep.name) if self.project.config.link_all and is_first_line: # link dep's of deps if allowed upd = self.system_config.cache.link_package( dep, self.project.path) self.rescan_deps = upd upd = self.system_config.cache.link_package(dep, package.path) self.rescan_deps = upd self.__build_deps( dep ) # link all dep's deps (build them and add to cache if necessary)
def compile(self, override_config: ConfigFile or None = None) -> bool: info('Enot build ' + self.project_name) self.__run_prebuild(override_config) all_files = self.__get_all_files(self.src_path, 'erl') first_compiled = self.form_compilation_order(all_files) debug('ensure ' + self.output_path) ensure_dir(self.output_path) res = True if self.package.has_nifs: res = CCompiler( self.package).compile(override_config=override_config) if res and first_compiled is not {}: res = self.__do_compile(first_compiled, override=override_config) [ all_files.pop(key) for key in first_compiled if first_compiled[key] == all_files[key] ] if res: res = self.__do_compile(all_files, override=override_config) if res: self.__write_app_file(list(all_files.keys())) return res
def compile(self, override_config: ConfigFile or None = None) -> bool: info(self.executable + ' build ' + self.project_name) return run_cmd(self.executable, self.project_name, self.root_path, output=None)
def compile(self, override_config: ConfigFile or None = None): # self as ensure_tool in builder info('Rebar build ' + self.project_name) return run_cmd([self.executable, 'compile'], self.project_name, self.root_path)
def fetch_erts(self, erlang_vsn: str) -> str: info('fetch erts for ' + erlang_vsn) return self.__download_release(erlang_vsn)
def add_tool(self, toolname: str, toolpath: str): info('add ' + toolname) tool_dst = join(self.tool_dir, toolname) copy_file(toolpath, tool_dst) st = os.stat(tool_dst) os.chmod(tool_dst, st.st_mode | stat.S_IEXEC)