clang-tools  10.0.0
CompileCommands.h
Go to the documentation of this file.
1 //===--- CompileCommands.h - Manipulation of compile flags -------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILECOMMANDS_H
9 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILECOMMANDS_H
10 
11 #include "clang/Tooling/ArgumentsAdjusters.h"
12 #include "clang/Tooling/CompilationDatabase.h"
13 #include <string>
14 #include <vector>
15 
16 namespace clang {
17 namespace clangd {
18 
19 // CommandMangler transforms compile commands from some external source
20 // for use in clangd. This means:
21 // - running the frontend only, stripping args regarding output files etc
22 // - forcing the use of clangd's builtin headers rather than clang's
23 // - resolving argv0 as cc1 expects
24 // - injecting -isysroot flags on mac as the system clang does
26  // Absolute path to clang.
27  llvm::Optional<std::string> ClangPath;
28  // Directory containing builtin headers.
29  llvm::Optional<std::string> ResourceDir;
30  // Root for searching for standard library (passed to -isysroot).
31  llvm::Optional<std::string> Sysroot;
32 
33  // A command-mangler that doesn't know anything about the system.
34  // This is hermetic for unit-tests, but won't work well in production.
35  static CommandMangler forTests();
36  // Probe the system and build a command-mangler that knows the toolchain.
37  // - try to find clang on $PATH, otherwise fake a path near clangd
38  // - find the resource directory installed near clangd
39  // - on mac, find clang and isysroot by querying the `xcrun` launcher
40  static CommandMangler detect();
41 
42  void adjust(std::vector<std::string> &Cmd) const;
43  explicit operator clang::tooling::ArgumentsAdjuster();
44 
45 private:
46  CommandMangler() = default;
47 };
48 
49 } // namespace clangd
50 } // namespace clang
51 
52 #endif
void adjust(std::vector< std::string > &Cmd) const
llvm::Optional< std::string > ClangPath
static CommandMangler forTests()
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< std::string > Sysroot
static CommandMangler detect()
llvm::Optional< std::string > ResourceDir