mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:40:10 +01:00
This patches bazel_clang_tidy handling of headers. I found an equivalent change at https://github.com/erenon/bazel_clang_tidy/pull/13, but that was [already rejected](https://github.com/erenon/bazel_clang_tidy/pull/13#issuecomment-1047007424). Per the criticism, this will result in redundant processing of headers. The project instead uses `HeaderFilterRegex: ".*"`, but that results in two problems: 1. When running with `-k`, errors are repeated when a header is included more than once, which is common. 2. clang-tidy including errors from headers that are included from other modules (e.g., abseil-cpp); filtering correctly is difficult. Given the trade-offs and options (including forking), I thought patching was preferable so long as it remains narrow.
46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_COMMON_INIT_LLVM_H_
|
|
#define CARBON_COMMON_INIT_LLVM_H_
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/Support/InitLLVM.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// A RAII class to handle initializing LLVM and shutting it down. An instance of
|
|
// this class should be created in the `main` function of each Carbon binary
|
|
// that interacts with LLVM, before `argc` and `argv` are first inspected.
|
|
class InitLLVM {
|
|
public:
|
|
// Initializes LLVM for use by a Carbon binary. On Windows, `argc` and `argv`
|
|
// are updated to refer to properly-encoded UTF-8 versions of the command line
|
|
// arguments.
|
|
explicit InitLLVM(int& argc, char**& argv);
|
|
|
|
// Shuts down LLVM.
|
|
~InitLLVM() = default;
|
|
|
|
private:
|
|
using InitializeTargetsFn = auto() -> void;
|
|
|
|
llvm::InitLLVM init_llvm_;
|
|
llvm::SmallVector<char*> args_;
|
|
|
|
// A pointer to the LLVM target initialization function, if :all_llvm_targets
|
|
// is linked in. Otherwise nullptr.
|
|
// NOLINTNEXTLINE(readability-identifier-naming): Constant after static init.
|
|
static InitializeTargetsFn* InitializeTargets;
|
|
|
|
// The initializer of this static data member populates `InitializeTargets`.
|
|
// Defined only if :all_llvm_targets is linked in. This is a member so that
|
|
// it has access to `InitializeTargets`.
|
|
static const char RegisterTargets;
|
|
};
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // CARBON_COMMON_INIT_LLVM_H_
|