Repository: envoyproxy/envoy
File: tools/gen_compilation_database.py (Python)

Code before:
        if args.include_all:
            return True
        if not args.include_headers:
            return False

    if filename.startswith("bazel-out/"):
        if args.include_all:
            return True
        if not args.include_genfiles:
            return False

    if filename.startswith("external/"):
        if args.include_all:
            return True
        if not args.include_external:
            return False

    return True


def modify_compile_command(target, args, output_base):
    cc, options = target["command"].split(" ", 1)

    # cc_wrapper.sh is a script of llvm_toolchain to wrap clang/clang++. Make sure to
    # use the one from output_base.
    if cc.endswith("cc_wrapper.sh"):
        cc = os.path.join(output_base, cc)

    # Workaround for bazel added C++11 options, those doesn't affect build itself but
    # clang-tidy will misinterpret them.
    options = options.replace("-std=c++0x ", "")
    options = options.replace("-std=c++11 ", "")

    if args.vscode:
        # Visual Studio Code doesn't seem to like "-iquote". Replace it with
        # old-style "-I".
        options = options.replace("-iquote ", "-I ")

    if is_header(target["file"]):
        options += " -Wno-pragma-once-outside-header -Wno-unused-const-variable"
        options += " -Wno-unused-function"
        # By treating external/envoy* as C++ files we are able to use this script from subrepos that
        # depend on Envoy targets.
        if not target["file"].startswith("external/") or target["file"].startswith(
                "external/envoy"):
            # *.h file is treated as C header by default while our headers files are all C++20.
            options = "-x c++ -std=c++20 -fexceptions " + options

    target["command"] = " ".join([cc, options])
    return target


Review comment (suggestion):
Get the correct binary full path so we can avoid the dependency to the soft link. This make sure this script could be useful even the dev container is not used.

Code after:
            return True
        if not args.include_headers:
            return False

    if filename.startswith("bazel-out/"):
        if args.include_all:
            return True
        if not args.include_genfiles:
            return False

    if filename.startswith("external/"):
        if args.include_all:
            return True
        if not args.include_external:
            return False

    return True


def modify_compile_command(target, args, output_base):
    cc, options = target["command"].split(" ", 1)

    # cc_wrapper.sh is a script of llvm_toolchain to wrap clang/clang++. Make sure to
    # use the one from output_base.
    if cc.endswith("cc_wrapper.sh"):
        cc = os.path.join(output_base, cc)

    # Workaround for bazel added C++11 options, those doesn't affect build itself but
    # clang-tidy will misinterpret them.
    options = options.replace("-std=c++0x ", "")
    options = options.replace("-std=c++11 ", "")

    if args.vscode:
        # Visual Studio Code doesn't seem to like "-iquote". Replace it with
        # old-style "-I".
        options = options.replace("-iquote ", "-I ")

    if is_header(target["file"]):
        options += " -Wno-pragma-once-outside-header -Wno-unused-const-variable"
        options += " -Wno-unused-function"
        # By treating external/envoy* as C++ files we are able to use this script from subrepos that
        # depend on Envoy targets.
        if not target["file"].startswith("external/") or target["file"].startswith(
                "external/envoy"):
            # *.h file is treated as C header by default while our headers files are all C++20.
            options = "-x c++ -std=c++20 -fexceptions " + options

    target["command"] = " ".join([cc, options])
    return target