diff --git a/clang/tools/clang-scan-deps/CMakeLists.txt b/clang/tools/clang-scan-deps/CMakeLists.txt --- a/clang/tools/clang-scan-deps/CMakeLists.txt +++ b/clang/tools/clang-scan-deps/CMakeLists.txt @@ -14,6 +14,7 @@ DEPENDS ScanDepsOptsTableGen + GENERATE_DRIVER ) set(CLANG_SCAN_DEPS_LIB_DEPS diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp --- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -21,6 +21,7 @@ #include "llvm/Support/FileUtilities.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/JSON.h" +#include "llvm/Support/LLVMDriver.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" #include "llvm/Support/ThreadPool.h" @@ -657,9 +658,9 @@ // generating P1689 format, trying to generate the compilation database // form specified command line after the positional parameter "--". static std::unique_ptr -getCompilationDataBase(int argc, const char **argv, std::string &ErrorMessage) { +getCompilationDataBase(int argc, char **argv, std::string &ErrorMessage) { llvm::InitLLVM X(argc, argv); - ParseArgs(argc, const_cast(argv)); + ParseArgs(argc, argv); if (!CompilationDB.empty()) return tooling::JSONCompilationDatabase::loadFromFile( @@ -674,7 +675,7 @@ // Trying to get the input file, the output file and the command line options // from the positional parameter "--". - const char **DoubleDash = std::find(argv, argv + argc, StringRef("--")); + char **DoubleDash = std::find(argv, argv + argc, StringRef("--")); if (DoubleDash == argv + argc) { llvm::errs() << "The command line arguments is required after '--' in " "P1689 per file mode."; @@ -746,7 +747,7 @@ FEOpts.Inputs[0].getFile(), OutputFile, CommandLine); } -int main(int argc, const char **argv) { +int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) { std::string ErrorMessage; std::unique_ptr Compilations = getCompilationDataBase(argc, argv, ErrorMessage); diff --git a/llvm/utils/gn/secondary/clang/tools/clang-scan-deps/BUILD.gn b/llvm/utils/gn/secondary/clang/tools/clang-scan-deps/BUILD.gn --- a/llvm/utils/gn/secondary/clang/tools/clang-scan-deps/BUILD.gn +++ b/llvm/utils/gn/secondary/clang/tools/clang-scan-deps/BUILD.gn @@ -1,3 +1,4 @@ +import("//llvm/utils/gn/build/driver_executable.gni") import("//llvm/utils/TableGen/tablegen.gni") tablegen("Opts") { @@ -5,7 +6,7 @@ args = [ "-gen-opt-parser-defs" ] } -executable("clang-scan-deps") { +driver_executable("clang-scan-deps") { configs += [ "//llvm/utils/gn/build:clang_code" ] deps = [ ":Opts", diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel @@ -2251,9 +2251,18 @@ td_srcs = [ "//llvm:include/llvm/Option/OptParser.td" ], ) +expand_template( + name = "clang-scan-deps-main", + out = "clang-scan-deps-driver.cpp", + substitutions = { + "@TOOL_NAME@": "clang_scan_deps", + }, + template = "//llvm:cmake/modules/llvm-driver-template.cpp.in", +) + cc_binary( name = "clang-scan-deps", - srcs = glob(["tools/clang-scan-deps/*.cpp"]), + srcs = glob(["tools/clang-scan-deps/*.cpp"]) + ["clang-scan-deps-driver.cpp"], stamp = 0, deps = [ ":driver",