Esempio n. 1
0
def replace(config: Config) -> None:
    for patterns in config.replace.regex:
        for filename in config.glob(common.resolve(patterns.pattern, config)):
            replace_in_file(filename, patterns.substitutions, config)

    for files in config.replace.template_files:
        src = common.resolve_path(files.source, config)
        dst = common.resolve_path(files.destination, config)

        replace_in_file_all(src, dst, config)
Esempio n. 2
0
    def process_dependency(dep: Dependency):
        src = common.resolve_path(dep.path, config)
        dst = common.resolve_path(dep.destination, config)

        for pattern in dep.include:
            zipfiles.include(src / pattern, dst, True)

        for pattern in dep.exclude:
            zipfiles.exclude(src / pattern)

        for file_map in dep.map:
            _src = common.resolve_path(file_map.source, config)
            if not _src.is_absolute():
                _src = src / _src
            zipfiles.map(_src, file_map.destination)
Esempio n. 3
0
def package(config: Config, file_list: ZipFiles, verbose: bool) -> None:
    package = config.package

    compression = package.compression_value
    name = common.resolve(package.filename, config)
    outdir = common.resolve_path(package.output_dir, config)
    archive = outdir / name

    if verbose:
        print(f"Packaging {archive!s}")

    archive.parent.mkdir(parents=True, exist_ok=True)

    if compression is None:
        archive = archive.with_suffix("")
        archive.mkdir(exist_ok=True)
        for src, _dst in file_list.items():
            dst = archive / _dst
            dst.parent.mkdir(parents=True, exist_ok=True)
            if dst.is_dir():
                continue
            if verbose:
                print(f"Writing {src!s} -> {dst!s}")
            shutil.copyfile(src, dst)
    else:
        with zipfile.ZipFile(archive, "w", compression=compression) as zip:
            for src, dst in file_list.items():
                if verbose:
                    print(f"Writing {src!s} -> {dst!s}")
                zip.write(src, dst)

    print(archive)
Esempio n. 4
0
def clean(paths: Iterable[PathLike], config: Config):
    for path in paths:
        path = common.resolve_path(str(path), config)
        if path.exists():
            if path.is_dir():
                print(f"Removing directory {path!s}")
                shutil.rmtree(path)
            else:
                print(f"Removing file {path!s}")
                os.remove(path)
Esempio n. 5
0
def install(mapping: Iterable[FileCopy], config: Config):
    for item in mapping:
        src = common.resolve(item.source, config)
        dst = common.resolve_path(item.destination, config)

        for path in config.glob(src):
            if path.is_dir():
                print(f"Copying tree {path!s} -> {dst!s}")
                shutil.copytree(path, dst)
            else:
                print(f"Copying file {path!s} -> {dst!s}")
                shutil.copy(path, dst)
Esempio n. 6
0
def add_path_list_option(args: List[str], target: BurstTarget, name: str,
                         option_name: str, config: Config) -> None:
    paths: Optional[List[pathlib.Path]] = getattr(target, name, None)
    if paths is None:
        return

    path: pathlib.Path
    for path in paths:
        path = common.resolve_path(path, config)
        if "*" in str(path):
            for p in config.glob(path):
                args.append(f"--{option_name}={p}")
        else:
            args.append(f"--{option_name}={path}")
Esempio n. 7
0
def post_build(config: Config, configuration_name: str,
               target_path: PathLike) -> None:
    update_config(config, configuration_name, target_path)
    events = config.post_build

    if events.pdb2mdb is not None:
        pdb2mdb(
            common.resolve_path(events.pdb2mdb, config),
            str(config.variables["TargetPath"]),
        )

    if events.clean:
        clean(events.clean, config)

    if events.install:
        install(events.install, config)
Esempio n. 8
0
def add_value_option(
    args: List[str],
    target: BurstTarget,
    name: str,
    config: Config,
    is_path: bool = False,
) -> None:
    option = getattr(target, name, None)
    if option is None:
        return

    if is_path:
        option = common.resolve_path(option, config)
    else:
        option = common.resolve(option, config)

    args.append(f"--{name.replace('_', '-')}={option}")
Esempio n. 9
0
def burst_compile_all(config: Config, print_help: bool = False) -> None:
    compile_config = config.burst_compile
    bcl = compile_config.bcl
    bcl = common.resolve_path(bcl, config)

    if print_help:
        subprocess.call([bcl, "--help"])
        sys.exit(0)

    debug = compile_config.debug

    targets = get_targets(compile_config)
    for platform, target in targets.items():
        try:
            burst_compile(bcl, target, config, debug)
        except Exception:
            logger.exception("Exception compiling target '%s'", platform)
Esempio n. 10
0
 def _glob(self, pattern: PathLike) -> Iterable[pathlib.Path]:
     pattern = common.resolve_path(pattern, self.config)
     return self.config.glob(pattern)
Esempio n. 11
0
    def map(self, src: PathLike, dst: PathLike) -> None:
        dst = common.resolve_path(dst, self.config)

        for file in self._glob(src):
            self.append(file, dst)