Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05c0db7

Browse files
authored
[TableGen] Emit the primary input file in -d depfile output (#197061)
This fixes a bug where old, but still supported, versions of CMake and ninja perpetually consider zero-include tablegen files to be out of date. It also matches what Clang and GCC do for regular C compilations. When a .td input has no `include` directives, the depfile produced by `-d` contains only `<output>:` followed by zero dependencies. My version (3.27) of CMake's `cmake_transform_depfile` step then writes a 0-byte file, which old versions of ninja treat as a missing depfile and re-run the rule on every incremental build (e.g. Attributes.td, ValueTypes.td). Here's the effect on Attributes.inc.d: ``` $ cat ./build/include/llvm/IR/Attributes.inc.d Attributes.inc: # switch branches and rebuild... $ cat ./build/include/llvm/IR/Attributes.inc.d Attributes.inc: /work/llvm-project/llvm/include/llvm/IR/Attributes.td ``` An LLM was used to help create this change.
1 parent 6709926 commit 05c0db7

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

llvm/lib/TableGen/Main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ static int createDependencyFile(const TGParser &Parser, const char *argv0) {
9797
return reportError(argv0, "error opening " + DependFilename + ":" +
9898
EC.message() + "\n");
9999
DepOut.os() << OutputFilename << ":";
100+
101+
// Emit the primary input file as a dependency. This matches C compilers like
102+
// Clang and GCC. Without it, a .td file with no `include` directives would
103+
// produce a depfile listing zero dependencies. CMake's
104+
// `cmake_transform_depfile` then collapses that to a 0-byte file, which Ninja
105+
// treats as a missing depfile and re-runs the rule on every incremental
106+
// build.
107+
if (InputFilename != "-")
108+
DepOut.os() << ' ' << InputFilename;
109+
100110
for (const auto &Dep : Parser.getDependencies()) {
101111
DepOut.os() << ' ' << Dep;
102112
}

llvm/test/TableGen/depfile.td

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Verify that `-d` emits a non-empty depfile that always names the primary
2+
// input file, even when the input has no `include` directives. A depfile
3+
// containing only `<output>:` (no deps) round-trips through CMake's
4+
// `cmake_transform_depfile` step to a 0-byte file, which Ninja treats as a
5+
// missing depfile and unconditionally re-runs the edge.
6+
7+
// RUN: llvm-tblgen -print-records %s -o %t.out -d %t.d
8+
// RUN: FileCheck %s --input-file=%t.d
9+
10+
// CHECK: {{.*}}depfile.td.tmp.out: {{.*}}depfile.td
11+
12+
// When the input is stdin (`-`), there is no input path to emit, so the
13+
// depfile lists only the output target with no dependencies.
14+
// RUN: llvm-tblgen -print-records - -o %t.stdin.out -d %t.stdin.d < %s
15+
// RUN: FileCheck %s --check-prefix=STDIN --input-file=%t.stdin.d
16+
17+
// STDIN: {{.*}}depfile.td.tmp.stdin.out:{{$}}
18+
19+
def Empty;

0 commit comments

Comments
 (0)