Skip to content

Commit 5a33d6a

Browse files
authored
Track toolchain headers to detect toolchain updates instead of macro. (flutter#302)
To detect and rebuild all TUs on toolchain updates, we inherited a rule from Chromium whereby the Git SHA of the //buildtools repo would be used to insert a preprocessor define in each TUs build invocation. But we don't use a //buildtools as a repo anymore. Instead buildtools comes from CIPD. So the script now picks the //buildroot revision instead. But we don't specify the toolchain revision in that repo either though. It is instead specified in the engine. So if the engine updates the toolchain, only the next (unrelated) //buildroot rev will ensure all old TUs are rebuilt unless the `out` directory is cleared on each invocation. This patch replaces the old buggy technique with one where the system headers (that include headers in buildtools) are tracked in addition to user headers. When the toolchain updates, these "system" header timestamps will be invalidated and the old artifacts invalidate. The simple change of just tracking the //flutter (where the toolchain SHA is present) would make it so that each engine change (frequent) would rebuild all TUs instead of just each buildtools change (rarer). Also, this technique would leave us susceptible to the kind of issue that led us in this situation in the first place. I also just searched and replaced all calls to track user dependencies with ones to track system + user dependencies. Not all toolchain are actually being used. We should clean these up in a separate patch.
1 parent 10b36e5 commit 5a33d6a

File tree

6 files changed

+16
-30
lines changed

6 files changed

+16
-30
lines changed

build/config/compiler/BUILD.gn

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,6 @@ config("compiler") {
6666
ldflags = []
6767
defines = []
6868

69-
# We want to force a recompile and relink of the world whenever our toolchain
70-
# changes since artifacts from an older version of the toolchain may or may
71-
# not be compatible with newer ones. To achieve this, we insert a synthetic
72-
# define into the compile line. We only do this for toolchains that we use
73-
# from buildtools.
74-
toolchain_version =
75-
exec_script("//build/util/lastchange.py",
76-
[
77-
"--source-dir=" + rebase_path("//buildtools"),
78-
"--revision-only",
79-
],
80-
"trim string")
81-
defines = [ "TOOLCHAIN_VERSION=$toolchain_version" ]
82-
8369
# In general, Windows is totally different, but all the other builds share
8470
# some common GCC configuration. This section sets up Windows and the common
8571
# GCC flags, and then we handle the other non-Windows platforms specifically

build/toolchain/custom/BUILD.gn

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ toolchain("custom") {
2929

3030
tool("cc") {
3131
depfile = "{{output}}.d"
32-
command = "$cc -MMD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
32+
command = "$cc -MD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
3333
depsformat = "gcc"
3434
description = "CC {{output}}"
3535
outputs = [
@@ -39,7 +39,7 @@ toolchain("custom") {
3939

4040
tool("cxx") {
4141
depfile = "{{output}}.d"
42-
command = "$cxx -MMD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
42+
command = "$cxx -MD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
4343
depsformat = "gcc"
4444
description = "CXX {{output}}"
4545
outputs = [
@@ -49,7 +49,7 @@ toolchain("custom") {
4949

5050
tool("asm") {
5151
depfile = "{{output}}.d"
52-
command = "$cc -MMD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
52+
command = "$cc -MD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
5353
depsformat = "gcc"
5454
description = "ASM {{output}}"
5555
outputs = [

build/toolchain/fuchsia/BUILD.gn

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ toolchain("fuchsia") {
4141

4242
tool("cc") {
4343
depfile = "{{output}}.d"
44-
command = "$goma_prefix $cc -MMD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
44+
command = "$goma_prefix $cc -MD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
4545
depsformat = "gcc"
4646
description = "CC {{output}}"
4747
outputs = [
@@ -51,7 +51,7 @@ toolchain("fuchsia") {
5151

5252
tool("cxx") {
5353
depfile = "{{output}}.d"
54-
command = "$goma_prefix $cxx -MMD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
54+
command = "$goma_prefix $cxx -MD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
5555
depsformat = "gcc"
5656
description = "CXX {{output}}"
5757
outputs = [
@@ -61,7 +61,7 @@ toolchain("fuchsia") {
6161

6262
tool("asm") {
6363
depfile = "{{output}}.d"
64-
command = "$goma_prefix $cc -MMD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
64+
command = "$goma_prefix $cc -MD -MF $depfile $target_triple_flags $sysroot_flags {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
6565
depsformat = "gcc"
6666
description = "ASM {{output}}"
6767
outputs = [

build/toolchain/gcc_toolchain.gni

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ template("gcc_toolchain") {
119119

120120
tool("cc") {
121121
depfile = "{{output}}.d"
122-
command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}"
122+
command = "$cc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}"
123123
depsformat = "gcc"
124124
description = "CC {{output}}"
125125
outputs = [
@@ -129,7 +129,7 @@ template("gcc_toolchain") {
129129

130130
tool("cxx") {
131131
depfile = "{{output}}.d"
132-
command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $coverage_flags -c {{source}} -o {{output}}"
132+
command = "$cxx -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $coverage_flags -c {{source}} -o {{output}}"
133133
depsformat = "gcc"
134134
description = "CXX {{output}}"
135135
outputs = [
@@ -140,7 +140,7 @@ template("gcc_toolchain") {
140140
tool("asm") {
141141
# For GCC we can just use the C compiler to compile assembly.
142142
depfile = "{{output}}.d"
143-
command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}"
143+
command = "$cc -MD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}"
144144
depsformat = "gcc"
145145
description = "ASM {{output}}"
146146
outputs = [

build/toolchain/mac/BUILD.gn

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ template("mac_toolchain") {
8282

8383
tool("cc") {
8484
depfile = "{{output}}.d"
85-
command = "$goma_prefix $cc -MMD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags $lto_flags {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}"
85+
command = "$goma_prefix $cc -MD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags $lto_flags {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}"
8686
depsformat = "gcc"
8787
description = "CC {{output}}"
8888
outputs = [
@@ -92,7 +92,7 @@ template("mac_toolchain") {
9292

9393
tool("cxx") {
9494
depfile = "{{output}}.d"
95-
command = "$goma_prefix $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags $lto_flags {{cflags}} {{cflags_cc}} $coverage_flags -c {{source}} -o {{output}}"
95+
command = "$goma_prefix $cxx -MD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags $lto_flags {{cflags}} {{cflags_cc}} $coverage_flags -c {{source}} -o {{output}}"
9696
depsformat = "gcc"
9797
description = "CXX {{output}}"
9898
outputs = [
@@ -103,7 +103,7 @@ template("mac_toolchain") {
103103
tool("asm") {
104104
# For GCC we can just use the C compiler to compile assembly.
105105
depfile = "{{output}}.d"
106-
command = "$goma_prefix $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} $sysroot_flags $lto_flags {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
106+
command = "$goma_prefix $cc -MD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} $sysroot_flags $lto_flags {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
107107
depsformat = "gcc"
108108
description = "ASM {{output}}"
109109
outputs = [
@@ -113,7 +113,7 @@ template("mac_toolchain") {
113113

114114
tool("objc") {
115115
depfile = "{{output}}.d"
116-
command = "$goma_prefix $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags $lto_flags {{cflags}} {{cflags_c}} {{cflags_objc}} $coverage_flags -c {{source}} -o {{output}}"
116+
command = "$goma_prefix $cxx -MD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags $lto_flags {{cflags}} {{cflags_c}} {{cflags_objc}} $coverage_flags -c {{source}} -o {{output}}"
117117
depsformat = "gcc"
118118
description = "OBJC {{output}}"
119119
outputs = [
@@ -123,7 +123,7 @@ template("mac_toolchain") {
123123

124124
tool("objcxx") {
125125
depfile = "{{output}}.d"
126-
command = "$goma_prefix $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags $lto_flags {{cflags}} {{cflags_cc}} {{cflags_objcc}} $coverage_flags -c {{source}} -o {{output}}"
126+
command = "$goma_prefix $cxx -MD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags $lto_flags {{cflags}} {{cflags_cc}} {{cflags_objcc}} $coverage_flags -c {{source}} -o {{output}}"
127127
depsformat = "gcc"
128128
description = "OBJCXX {{output}}"
129129
outputs = [

build/toolchain/nacl/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ toolchain("x86_newlib") {
99
ld = toolprefix + "g++"
1010

1111
tool("cc") {
12-
command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c -c \$in -o \$out"
12+
command = "$cc -MD -MF \$out.d \$defines \$includes \$cflags \$cflags_c -c \$in -o \$out"
1313
description = "CC(NaCl x86 Newlib) \$out"
1414
depfile = "\$out.d"
1515
depsformat = "gcc"
1616
}
1717
tool("cxx") {
1818
# cflags_pch_cc
19-
command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc -c \$in -o \$out"
19+
command = "$cxx -MD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc -c \$in -o \$out"
2020
description = "CXX(NaCl x86 Newlib) \$out"
2121
depfile = "\$out.d"
2222
depsformat = "gcc"

0 commit comments

Comments
 (0)