コード例 #1
0
def GenerateCompileCommands(options):
    gn_result = generate_buildfiles.RunGn(options)
    if (gn_result != 0):
        return gn_result

    out_folder = utils.GetBuildRoot(HOST_OS, mode="debug", arch="x64")

    if (not os.path.isdir(out_folder)):
        return 1

    command_set = json.loads(
        subprocess.check_output(
            ["ninja", "-C", out_folder, "-t", "compdb", "cxx", "cc", "h"]))

    commands = []
    for obj in command_set:
        command = obj["command"]

        # Skip precompiled mode, a lot of code is commented out in precompiled mode
        if ("-DDART_PRECOMPILED_RUNTIME" in command):
            continue

        # Remove warnings
        command = command.replace("-Werror", "")

        obj["command"] = command
        commands += [obj]

    json.dump(commands, open("compile_commands.json", "w"), indent=4)

    return 0
コード例 #2
0
def GenerateCompileCommands(options):
    """Generate compile_commands.json for the C++ analysis servers.

  compile_commands.json is used by the c++ clang and intellij language analysis
  servers used in IDEs such as Visual Studio Code and Emacs.

  Args:
    options: supported options include: verbose, force, dir

  Returns:
    success (0) or failure (non zero)
  """

    fname = os.path.join(options.dir, "compile_commands.json")

    if os.path.isfile(fname) and not options.force:
        print fname + " already exists, use --force to override"
        return

    gn_result = generate_buildfiles.RunGn(options)
    if gn_result != 0:
        return gn_result

    out_folder = utils.GetBuildRoot(HOST_OS,
                                    mode="debug",
                                    arch=options.arch,
                                    target_os=options.os)

    if not os.path.isdir(out_folder):
        return 1

    command_set = json.loads(
        subprocess.check_output(
            ["ninja", "-C", out_folder, "-t", "compdb", "cxx", "cc", "h"]))

    commands = []
    for obj in command_set:
        command = obj["command"]

        # Skip precompiled mode, a lot of code is commented out in precompiled mode
        if "-DDART_PRECOMPILED_RUNTIME" in command:
            continue

        # Remove warnings
        command = command.replace("-Werror", "")

        obj["command"] = command
        commands += [obj]

    with open(fname, "w") as f:
        json.dump(commands, f, indent=4)

    return 0