# 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_logentries_handler(cloudlog) cloudlog.error("scons build failed\n" + error_s) # Show TextWindow 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 import cereal import cereal.messaging as messaging from common.params import Params import selfdrive.crash as crash from selfdrive.registration import register from selfdrive.version import version, dirty from selfdrive.loggerd.config import ROOT from selfdrive.launcher import launcher
except Exception: traceback.print_exc() crash.capture_exception() finally: manager_cleanup() if Params().get_bool("DoUninstall"): cloudlog.warning("uninstalling") HARDWARE.uninstall() if __name__ == "__main__": unblock_stdout() try: main() except Exception: add_file_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 with TextWindow(error) as t: t.wait_for_exit() raise # manual exit because we are forked sys.exit(0)
def build(spinner, dirty=False): 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 [True, False]: scons = subprocess.Popen(["scons", j_flag, "--cache-populate"], cwd=BASEDIR, env=env, stderr=subprocess.PIPE) 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) try: result = subprocess.check_output(["ifconfig", "wlan0"], encoding='utf8') ip = re.findall(r"inet addr:((\d+\.){3}\d+)", result)[0][0] except: ip = 'N/A' # 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 (IP: %s)\n \n" % ip) + 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()
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_logentries_handler(cloudlog) cloudlog.error("scons build failed\n" + error_s) # Show TextWindow no_ui = __name__ != "__main__" or not ANDROID 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, noop=no_ui) as t: t.wait_for_exit() exit(1) else: break import cereal import cereal.messaging as messaging from common.params import Params import selfdrive.crash as crash from selfdrive.registration import register from selfdrive.version import version, dirty from selfdrive.loggerd.config import ROOT from selfdrive.launcher import launcher
def build(): env = os.environ.copy() env['SCONS_PROGRESS'] = "1" env['SCONS_CACHE'] = "1" nproc = os.cpu_count() j_flag = "" if nproc is None else f"-j{nproc - 1}" for retry in [True, False]: scons = subprocess.Popen(["scons", j_flag], cwd=BASEDIR, env=env, stderr=subprocess.PIPE) 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: 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) shutil.rmtree("/tmp/scons_cache", ignore_errors=True) shutil.rmtree("/data/scons_cache", ignore_errors=True) 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_logentries_handler(cloudlog) cloudlog.error("scons build failed\n" + error_s) # Show TextWindow spinner.close() 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
else: text = "Current run: FAIL\n" data['sensor-fail'] += 1 timestr = str(int(time.time())) with open('/tmp/dmesg-' + timestr + '.log', 'w') as dmesg_out: subprocess.call('dmesg', stdout=dmesg_out, shell=False) with open("/tmp/logcat-" + timestr + '.log', 'w') as logcat_out: subprocess.call(['logcat', '-d'], stdout=logcat_out, shell=False) text += "Sensor pass history: " + str(data['sensor-pass']) + "\n" text += "Sensor fail history: " + str(data['sensor-fail']) + "\n" print(text) with open('/tmp/sensor-test-results.json', 'w') as outfile: json.dump(data, outfile, indent=4) with TextWindow(text) as status: for _ in range(100): if status.get_status() == 1: with open(STARTUP_SCRIPT, 'w') as startup_script: startup_script.write( "#!/usr/bin/bash\n\ncd /data/openpilot\nexec ./launch_openpilot.sh\n" ) os.chmod(STARTUP_SCRIPT, stat.S_IRWXU) break time.sleep(0.1) subprocess.Popen("reboot")
add_logentries_handler(cloudlog) cloudlog.error("scons build failed\n" + error_s) try: result = subprocess.check_output(["ifconfig", "wlan0"], encoding='utf8') ip = re.findall(r"inet addr:((\d+\.){3}\d+)", result)[0][0] except: ip = 'N/A' # Show TextWindow no_ui = __name__ != "__main__" or not ANDROID error_s = "\n \n".join( ["\n".join(textwrap.wrap(e, 65)) for e in errors]) with TextWindow( ("openpilot failed to build (IP: %s)\n \n" % ip) + error_s, noop=no_ui) as t: t.wait_for_exit() exit(1) else: break import cereal import cereal.messaging as messaging from common.params import Params, put_nonblocking import selfdrive.crash as crash from selfdrive.registration import register from selfdrive.version import version, dirty from selfdrive.loggerd.config import ROOT
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}" 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 # 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) # 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()