def gn_host_tools(ctx: PresubmitContext): build.gn_gen(ctx.repo_root, ctx.output_dir, pw_target_config='"//targets/host/target_config.gni"', pw_target_toolchain='"//pw_toolchain:host_clang_os"', pw_build_host_tools='true') build.ninja(ctx.output_dir, 'host_tools')
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 oss_fuzz_build(ctx: PresubmitContext): build.gn_gen(ctx.repo_root, ctx.output_dir, oss_fuzz_enabled='true', pw_target_toolchain='"//pw_toolchain:host_clang_og"', pw_sanitizer='"address"') build.ninja(ctx.output_dir)
def python_checks(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) build.ninja( ctx.output_dir, ':python.lint', ':python.tests', ':target_support_packages.lint', ':target_support_packages.tests', )
def gn_teensy_build(ctx: PresubmitContext): build.install_package(ctx.package_root, 'teensy') build.gn_gen(ctx.root, ctx.output_dir, pw_arduino_build_CORE_PATH='"{}"'.format(str( ctx.package_root)), pw_arduino_build_CORE_NAME='teensy', pw_arduino_build_PACKAGE_NAME='teensy/avr', pw_arduino_build_BOARD='teensy40') build.ninja(ctx.output_dir, *_at_all_optimization_levels('arduino'))
def gn_quick_build_check(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) # TODO(pwbug/255): Switch to optimized GCC builds when this is fixed. # See comment in _at_all_optimization_levels() above for details. optimization_level = 'size_optimized' if _HOST_COMPILER == 'gcc': optimization_level = 'debug' build.ninja(ctx.output_dir, f'host_{_HOST_COMPILER}_{optimization_level}', 'stm32f429i_size_optimized', 'python.tests', 'python.lint')
def gn_gcc_build(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) # Skip optimized host GCC builds for now, since GCC sometimes emits spurious # warnings. # # -02: GCC 9.3 emits spurious maybe-uninitialized warnings # -0s: GCC 8.1 (Mingw-w64) emits a spurious nonnull warning # # TODO(pwbug/255): Enable optimized GCC builds when this is fixed. build.ninja(ctx.output_dir, 'host_gcc_debug')
def gn_nanopb_build(ctx: PresubmitContext): build.install_package(ctx.package_root, 'nanopb') build.gn_gen(ctx.root, ctx.output_dir, dir_pw_third_party_nanopb='"{}"'.format(ctx.package_root / 'nanopb')) build.ninja( ctx.output_dir, *_at_all_optimization_levels('stm32f429i'), *_at_all_optimization_levels('host_clang'), )
def clang_tidy(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir, '--export-compile-commands') build.ninja(ctx.output_dir) build.ninja(ctx.output_dir, '-t', 'compdb', 'objcxx', 'cxx') run_clang_tidy = None for var in ('PW_PIGWEED_CIPD_INSTALL_DIR', 'PW_CIPD_INSTALL_DIR'): if var in os.environ: possibility = os.path.join(os.environ[var], 'share/clang/run-clang-tidy.py') if os.path.isfile(possibility): run_clang_tidy = possibility break checks = ','.join(_CLANG_TIDY_CHECKS) call( run_clang_tidy, f'-p={ctx.output_dir}', f'-checks={checks}', # TODO(pwbug/45) not sure if this is needed. # f'-extra-arg-before=-warnings-as-errors={checks}', *ctx.paths)
def source_is_in_build_files(ctx: PresubmitContext): """Checks that source files are in the GN and Bazel builds.""" gn_gens_to_run = ( (ctx.output_dir.joinpath('arm'), _ARM_GEN_ARGS), (ctx.output_dir.joinpath('clang'), _CLANG_GEN_ARGS), (ctx.output_dir.joinpath('docs'), _DOCS_GEN_ARGS), (ctx.output_dir.joinpath('qemu'), _QEMU_GEN_ARGS), ) for directory, args in gn_gens_to_run: build.gn_gen(ctx.repo_root, directory, args) missing = build.check_builds_for_files(_SOURCES_IN_BUILD, ctx.paths, bazel_dirs=[ctx.repo_root], gn_dirs=[ (ctx.repo_root, path) for path, _ in gn_gens_to_run ]) if missing: _LOG.warning( 'All source files must appear in BUILD and BUILD.gn files') raise PresubmitFailure
def gn_gcc_build(ctx: PresubmitContext): build.gn_gen( ctx.repo_root, ctx.output_dir, build.gn_args(pw_target_config='"//targets/host/target_config.gni"', pw_target_toolchain='"//pw_toolchain:host_gcc_os"')) build.ninja(ctx.output_dir)
def oss_fuzz_build(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir, pw_toolchain_OSS_FUZZ_ENABLED=True, pw_toolchain_SANITIZER="address") build.ninja(ctx.output_dir, "host_clang")
def gn_host_tools(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir, pw_build_HOST_TOOLS=True) build.ninja(ctx.output_dir)
def gn_docs_build(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) build.ninja(ctx.output_dir, 'docs')
def gn_arm_build(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) build.ninja(ctx.output_dir, *_at_all_optimization_levels('stm32f429i'))
def oss_fuzz_build(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir, pw_toolchain_OSS_FUZZ_ENABLED=True) build.ninja(ctx.output_dir, "fuzzers")
def gn_host_build(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) build.ninja(ctx.output_dir, *_at_all_optimization_levels(f'host_{_HOST_COMPILER}'))
def gn_gcc_build(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) build.ninja(ctx.output_dir, "host_gcc")
def gn_qemu_build(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) build.ninja(ctx.output_dir, *_at_all_optimization_levels('qemu_gcc'))
def gn_quick_build_check(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) build.ninja(ctx.output_dir, 'host_clang_size_optimized', 'stm32f429i_size_optimized', 'python.tests', 'python.lint')
def gn_clang_build(ctx: PresubmitContext): build.gn_gen(ctx.repo_root, ctx.output_dir, _CLANG_GEN_ARGS) build.ninja(ctx.output_dir)
def gn_arm_build(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) build.ninja(ctx.output_dir, "stm32f429i")
def gn_qemu_build(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) build.ninja(ctx.output_dir, "qemu")
def gn_clang_build(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) build.ninja(ctx.output_dir, *_at_all_optimization_levels('host_clang'))
def gn_arm_build(ctx: PresubmitContext): build.gn_gen(ctx.repo_root, ctx.output_dir, _ARM_GEN_ARGS) build.ninja(ctx.output_dir)
def gn_docs_build(ctx: PresubmitContext): build.gn_gen(ctx.repo_root, ctx.output_dir, _DOCS_GEN_ARGS) build.ninja(ctx.output_dir, 'docs:docs')
def gn_full_build_check(ctx: PresubmitContext): build.gn_gen(ctx.root, ctx.output_dir) build.ninja(ctx.output_dir, *_at_all_optimization_levels('stm32f429i'), *_at_all_optimization_levels(f'host_{_HOST_COMPILER}'), 'python.tests', 'python.lint', 'docs')