Esempio n. 1
0
def build(spinner: Spinner, dirty: bool = False) -> None:
    env = os.environ.copy()
    env['SCONS_PROGRESS'] = "1"
    nproc = os.cpu_count()
    j_flag = "" if nproc is None else f"-j{nproc - 1}"

    for retry in [False]:
        scons: subprocess.Popen = subprocess.Popen(
            ["scons", j_flag, "--cache-populate"],
            cwd=BASEDIR,
            env=env,
            stderr=subprocess.PIPE)
        assert scons.stderr is not None

        compile_output = []

        # Read progress from stderr and update spinner
        while scons.poll() is None:
            try:
                line = scons.stderr.readline()
                if line is None:
                    continue
                line = line.rstrip()

                prefix = b'progress: '
                if line.startswith(prefix):
                    i = int(line[len(prefix):])
                    spinner.update_progress(
                        MAX_BUILD_PROGRESS * min(1., i / TOTAL_SCONS_NODES),
                        100.)
                elif len(line):
                    compile_output.append(line)
                    print(line.decode('utf8', 'replace'))
            except Exception:
                pass

        if scons.returncode != 0:
            # Read remaining output
            r = scons.stderr.read().split(b'\n')
            compile_output += r

            if retry and (not dirty):
                if not os.getenv("CI"):
                    print("scons build failed, cleaning in")
                    for i in range(3, -1, -1):
                        print("....%d" % i)
                        time.sleep(1)
                    subprocess.check_call(["scons", "-c"],
                                          cwd=BASEDIR,
                                          env=env)
                else:
                    print("scons build failed after retry")
                    sys.exit(1)
            else:
                # Build failed log errors
                errors = [
                    line.decode('utf8', 'replace') for line in compile_output
                    if any(err in line for err in
                           [b'error: ', b'not found, needed by target'])
                ]
                error_s = "\n".join(errors)
                add_file_handler(cloudlog)
                cloudlog.error("scons build failed\n" + error_s)

                # Show TextWindow
                spinner.close()
                if not os.getenv("CI"):
                    error_s = "\n \n".join("\n".join(textwrap.wrap(e, 65))
                                           for e in errors)
                    with TextWindow("openpilot failed to build\n \n" +
                                    error_s) as t:
                        t.wait_for_exit()
                exit(1)
        else:
            break

    # enforce max cache size
    cache_files = [f for f in CACHE_DIR.rglob('*') if f.is_file()]
    cache_files.sort(key=lambda f: f.stat().st_mtime)
    cache_size = sum(f.stat().st_size for f in cache_files)
    for f in cache_files:
        if cache_size < MAX_CACHE_SIZE:
            break
        cache_size -= f.stat().st_size
        f.unlink()
Esempio n. 2
0
    # install pip from git
    package = 'git+https://github.com/move-fast/opspline.git@master'
    pip = subprocess.Popen([sys.executable, "-m", "pip", "install", "-v", package], stdout=subprocess.PIPE)

  # Read progress from pip and update spinner
  steps = 0
  while True:
    output = pip.stdout.readline()
    if pip.poll() is not None:
      break
    if output:
      steps += 1
      spinner.update_progress(MAX_BUILD_PROGRESS * min(1., steps / TOTAL_PIP_STEPS), 100.)
      print(output.decode('utf8', 'replace'))
  if TICI:
    shutil.rmtree(TMP_DIR)
    os.unsetenv('TMPDIR')

    # remove numpy installed to PYEXTRA_DIR since numpy is already present in the AGNOS image
    if OPSPLINE_SPEC is None:
      for directory in glob(f'{PYEXTRA_DIR}/numpy*'):
        shutil.rmtree(directory)
      shutil.rmtree(f'{PYEXTRA_DIR}/bin')


if __name__ == "__main__" and (OPSPLINE_SPEC is None or OVERPY_SPEC is None):
  spinner = Spinner()
  spinner.update_progress(0, 100)
  install_dep(spinner)
Esempio n. 3
0
        manager_thread(spinner)
    except Exception:
        traceback.print_exc()
        crash.capture_exception()
    finally:
        manager_cleanup()

    if Params().get("DoUninstall", encoding='utf8') == "1":
        cloudlog.warning("uninstalling")
        HARDWARE.uninstall()


if __name__ == "__main__":
    unblock_stdout()
    spinner = Spinner()
    spinner.update_progress(MAX_BUILD_PROGRESS, 100)

    try:
        main(spinner)
    except Exception:
        add_logentries_handler(cloudlog)
        cloudlog.exception("Manager failed to start")

        # Show last 3 lines of traceback
        error = traceback.format_exc(-3)
        error = "Manager failed to start\n\n" + error
        spinner.close()
        with TextWindow(error) as t:
            t.wait_for_exit()

        raise