Exemple #1
0
 def add_package(self, package: Package, rewrite=False) -> bool:
     full_dir = join(self.path, self.get_package_path(package, True))
     ensure_dir(full_dir)
     info('add ' + package.fullname)
     path = package.path
     LocalCache.__copy_data(rewrite, full_dir, path, 'ebin')
     LocalCache.__copy_include(rewrite, full_dir, path)
     if package.config.with_source:
         LocalCache.__copy_data(rewrite, full_dir, path, 'src')
     if package.config.with_source and package.has_nifs:
         LocalCache.__copy_data(rewrite, full_dir, path, 'c_src')
     if os.path.exists(join(path, 'priv')):
         LocalCache.__copy_data(rewrite, full_dir, path, 'priv')
     enot_package = join(path, package.name + '.ep')
     if not os.path.isfile(enot_package):
         debug('generate missing package')
         package.generate_package()
     copy_file(join(path, 'enot_config.json'),
               join(full_dir, 'enot_config.json'))
     copy_file(enot_package, join(full_dir, package.name + '.ep'))
     resource = resource_filename(Requirement.parse(enot.APPNAME),
                                  'enot/resources/EmptyMakefile')
     debug('copy ' + resource + ' to ' + join(full_dir, 'Makefile'))
     copy_file(resource, join(full_dir, 'Makefile'))
     package.path = full_dir  # update package's dir to point to cache
     return True
Exemple #2
0
 def __copy_include(rewrite, full_dir, path):
     cache_include = join(full_dir, 'include')
     if rewrite or not os.path.exists(cache_include):
         package_include = join(path, 'include')
         if os.path.exists(package_include):
             debug('copy ' + package_include + ' to' + cache_include)
             shutil.copytree(package_include, cache_include)
Exemple #3
0
def ensure_makefile(src_path):
    mkfile = join(src_path, 'Makefile')
    if not os.path.isfile(mkfile):
        resource = resource_filename(Requirement.parse(enot.APPNAME),
                                     'enot/resources/CMakefile')
        debug('copy ' + resource + ' to ' + mkfile)
        copy_file(resource, mkfile)
Exemple #4
0
 def __ensure_resource(self, resource, path):
     resource_path = join(self.package.path, path, resource)
     if not os.path.isfile(resource_path):
         resource = resource_filename(Requirement.parse(enot.APPNAME),
                                      join('enot/resources', resource))
         debug('copy ' + resource + ' to ' + resource_path)
         copy_file(resource, resource_path)
     return resource_path
Exemple #5
0
 def ensure(self, dst_path: str) -> str or None:
     debug('Fetching ' + self.name + ' ' + self.url)
     req = Request(self.url, headers={'User-Agent': 'Mozilla/5.0'})
     try:
         content = urlopen(req).read()
     except HTTPError as e:
         critical('Could not fetch ' + self.name + ': ' + str(e.reason))
         raise RuntimeError('Could not obtain ' + self.name)
     tool_path = join(dst_path, self.name)
     write_file(tool_path, content, True)
     return tool_path
Exemple #6
0
 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
Exemple #7
0
 def link_package(self, package: Package, dest_path: str) -> bool:
     if not dest_path:
         dest_path = os.getcwd()
     cache_path = join(self.path, self.get_package_path(package))
     dep_dir = join(dest_path, 'deps', package.name)
     ensure_dir(dep_dir)
     debug('link ' + package.name)
     changed = []
     for file in listdir(cache_path):
         if file != package.name + '.ep':
             changed.append(
                 LocalCache.link(cache_path, dest_path, package.name, file))
     return all(changed)  # if all links were changed - it is a new version
Exemple #8
0
 def __populate_deps(
         self, level):  # TODO add an ability to fetch deps in parallel
     next_level = []
     for dep in level:
         if dep.name not in self.packages:
             debug('new dep: ' + dep.name)
             self.system_config.cache.populate(
                 dep)  # populated dep becomes package
             self.packages[dep.name] = dep
             next_level += dep.deps
         else:
             next_level += self.__compare_and_select(dep)
     if next_level:
         self.__populate_deps(next_level)
Exemple #9
0
 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
Exemple #10
0
def run_cmd(cmd: str or list,
            project: str,
            path: str,
            env_vars: dict or None = None,
            shell=False,
            output=PIPE) -> bool:
    debug(cmd)
    if env_vars is None:
        env_vars = dict(os.environ)
    ensure_runnable(cmd, path)
    p = subprocess.Popen(cmd,
                         stdout=output,
                         stderr=output,
                         cwd=path,
                         env=env_vars,
                         shell=shell)
    if p.wait() != 0:
        critical(project + ' failed.')
        if output is not None:
            error(p.stderr.read().decode('utf8'))
            error(p.stdout.read().decode('utf8'))
        return False
    else:
        return True
Exemple #11
0
def link_if_needed(include_src: str, include_dst: str) -> bool:
    if os.path.exists(include_src):
        if os.path.islink(include_dst) and os.readlink(
                include_dst) == include_src:  # link up to date
            debug('already linked: ' + include_src)
            return False
        elif os.path.islink(include_dst):  # link outdated or broken
            debug('update link: ' + include_src)
            os.remove(
                include_dst
            )  # TODO we can return False here if only erl version was changed.
            os.symlink(include_src, include_dst)
            return True
        elif not os.path.exists(
                include_dst
        ):  # there was no link. Should add it but return false - there was no update
            debug('link ' + include_src + ' -> ' + include_dst)
            os.symlink(include_src, include_dst)
            return False
        else:  # not a link. May be file
            debug('overwrite ' + include_src + ' -> ' + include_dst)
            remove_dir(include_dst)
            os.symlink(include_src, include_dst)
            return True
Exemple #12
0
def copy_file(src: str, dst: str):
    debug('copy ' + src + ' to ' + dst)
    copyfile(src, dst)
Exemple #13
0
 def check_exists(self, path: str) -> bool:
     debug('check ' + self.path + ' ' + str(path))
     return if_dir_exists(self.path, path) is not None
Exemple #14
0
 def __copy_data(rewrite, full_dir, path, source_dir):
     cache_src = join(full_dir, source_dir)
     if rewrite or not os.path.exists(cache_src):
         package_src = join(path, source_dir)
         debug('copy ' + package_src + ' to ' + cache_src)
         shutil.copytree(package_src, cache_src)