Ejemplo n.º 1
0
def run_gradle_task(gradle_file: Path, project: str, task: str) -> None:
    global logs
    logs = []
    print(f"Running gradle task ./{project} [{task}]")
    return_code = run_process([str(gradle_file), task],
                              log_func=filter_gradle_task)
    if return_code != 0:
        for log in logs:
            print(log, end="")
    print(f"→ {'Success' if return_code == 0 else 'Failed'}")
Ejemplo n.º 2
0
    def run(self,
            *args: str,
            cli: bool = True,
            log_func: Callable[[str], None] = None) -> int:
        command = [str(self.exec)]
        command.extend(args)
        if cli:
            for o in ['-batchmode', '-nographics', '-quit', '-silent-crashes']:
                if o not in command:
                    command.append(o)

        return run_process(command, log_func=log_func)
Ejemplo n.º 3
0
def __get_version_darwin(app: str) -> UnityVersion:
    version = 0, 0, 0, 0
    version_str = str()

    def log_func(line: str):
        nonlocal version_str
        if line.startswith(': kMDItemVersion'):
            version_str = line.rstrip()

    return_code = run_process(['mdls', app], log_func=log_func)

    if return_code == 0 and version_str:
        regex_match = match(
            ':\\s*kMDItemVersion\\s*=\\s*"Unity version (\\d+).(\\d+).(\\d+)f(\\d+)"',
            version_str)
        version = tuple(map(int, regex_match.groups()))

    return UnityVersion(*version)
Ejemplo n.º 4
0
def __get_version_windows(app: str) -> UnityVersion:
    line_num = 1
    version = 0, 0, 0, 0
    version_str = str()

    def log_func(line: str):
        nonlocal line_num
        nonlocal version_str
        if line_num == 4:
            version_str = line.rstrip()
        line_num += 1

    app = app.replace('\\', '\\\\')
    return_code = run_process(
        ['wmic', 'datafile', 'where', f'Name="{app}"', 'get', 'Version'],
        log_func=log_func)

    if return_code == 0 and version_str:
        regex_match = match(': (\\d+).(\\d+).(\\d+).(\\d+)', version_str)
        version = tuple(map(int, regex_match.groups()))

    return UnityVersion(*version)
Ejemplo n.º 5
0
    def compile(self,
                *args: str,
                defines: List[str] = None,
                debug: bool = False,
                doc: str = None,
                nostdlib: bool = False,
                nowarn: List[str] = None,
                optimize: bool = False,
                out: str = None,
                references: List[str] = None,
                stacktrace: bool = False,
                target: str = None,
                unsafe: bool = False,
                warnaserror: List[str] = None,
                log_func: Callable[[str], None] = None) -> int:
        cwd_path = Path(getcwd())
        tmp_path = cwd_path / f'tmp-{datetime.now().strftime("%Y%m%d%H%M%S")}'
        tmp_path.mkdir()
        command = [str(self.mcs)]
        if defines is not None:
            command.append(f'-d:{";".join(defines)}')
        if debug:
            command.append('-debug')
        if doc is not None:
            command.append(f'-doc:{doc}')
        if nostdlib:
            command.append('-nostdlib')
        if nowarn is not None:
            command.append(f'-nowarn:{",".join(nowarn)}')
        if optimize:
            command.append('-optimize')
        if out is not None:
            command.append(f'-out:{out}')
        refs = []
        for r in references if references is not None else []:
            r_path = Path(r)
            if r_path.exists():
                r_name = r_path.name
                copyfile(str(r_path), str(tmp_path / r_name))
                refs.append(r_name)
        if len(refs) > 0:
            command.append(f'-r:{",".join(refs)}')
        if stacktrace:
            command.append('--stacktrace')
        if target is not None and target in [
                'exe', 'library', 'module', 'winexe'
        ]:
            command.append(f'-t:{target}')
        if unsafe:
            command.append('-unsafe')
        if warnaserror is not None:
            command.append(f'-warnaserror:{",".join(warnaserror)}')
        for f in args:
            f_path = Path(f)
            if f_path.exists():
                f_name = f_path.name
                copyfile(str(f_path), str(tmp_path / f_name))
        command.append('*.cs')
        try:
            chdir(str(tmp_path))
            return_code = run_process(command, log_func=log_func)
            if return_code == 0:
                if out is not None:
                    out_path = tmp_path / out
                    if out_path.exists():
                        move(str(out_path), str(cwd_path / out))
                if doc is not None:
                    doc_path = tmp_path / doc
                    if doc_path.exists():
                        move(str(doc_path), str(cwd_path / doc))
        finally:
            chdir(str(cwd_path))
            rmtree(str(tmp_path), ignore_errors=True)

        return return_code