def static_analysis(ctx: PresubmitContext): """Check that files pass static analyzer checks.""" build.gn_gen(ctx.root, ctx.output_dir, '--export-compile-commands=host_clang_debug') build.ninja(ctx.output_dir, 'host_clang_debug') compile_commands = ctx.output_dir.joinpath('compile_commands.json') analyzer_output = ctx.output_dir.joinpath('analyze-build-output') if analyzer_output.exists(): shutil.rmtree(analyzer_output) call('analyze-build', '--cdb', compile_commands, '--exclude', 'third_party', '--output', analyzer_output, cwd=ctx.root, env=build.env_with_clang_vars()) # Search for reports under output directory. reports = list(analyzer_output.glob('*/report*')) if len(reports) != 0: archive = shutil.make_archive(str(analyzer_output), 'zip', reports[0].parent) _LOG.error('Static analyzer found errors: %s', archive) _LOG.error('To view report, open: %s', Path(reports[0]).parent.joinpath('index.html')) raise PresubmitFailure
def cmake_tests(ctx: PresubmitContext): toolchain = ctx.root / 'pw_toolchain' / 'host_clang' / 'toolchain.cmake' build.cmake(ctx.root, ctx.output_dir, f'-DCMAKE_TOOLCHAIN_FILE={toolchain}', env=build.env_with_clang_vars()) build.ninja(ctx.output_dir, 'pw_run_tests.modules')
def _run_cmake(ctx: PresubmitContext) -> None: build.install_package(ctx.package_root, 'nanopb') toolchain = ctx.root / 'pw_toolchain' / 'host_clang' / 'toolchain.cmake' build.cmake(ctx.root, ctx.output_dir, f'-DCMAKE_TOOLCHAIN_FILE={toolchain}', '-DCMAKE_EXPORT_COMPILE_COMMANDS=1', f'-Ddir_pw_third_party_nanopb={ctx.package_root / "nanopb"}', env=build.env_with_clang_vars())
def bazel_build(ctx: PresubmitContext): """Runs Bazel build on each Bazel compatible module""" try: call('bazel', 'build', *_MODULES_THAT_WORK_WITH_BAZEL, '--verbose_failures', '--verbose_explanations', '--worker_verbose', cwd=ctx.root, env=build.env_with_clang_vars()) except: _LOG.info('If the Bazel build inexplicably fails while the ' 'other builds are passing, try deleting the Bazel cache:\n' ' rm -rf ~/.cache/bazel') raise
def bazel_test(ctx: PresubmitContext): try: call('bazel', 'test', '//...', '--verbose_failures', '--verbose_explanations', '--worker_verbose', '--symlink_prefix', ctx.output_dir.joinpath('bazel-'), cwd=ctx.root, env=build.env_with_clang_vars()) except: _LOG.info('If the Bazel build inexplicably fails while the ' 'other builds are passing, try deleting the Bazel cache:\n' ' rm -rf ~/.cache/bazel') raise
def cmake_tests(ctx: PresubmitContext): build.cmake(ctx.repo_root, ctx.output_dir, env=build.env_with_clang_vars()) build.ninja(ctx.output_dir, 'pw_run_tests.modules')