Skip to content

Commit

Permalink
Don't use sed to clean up depsfiles. Use -MMD instead. (#818)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanderso authored Jan 23, 2024
1 parent e75c1ca commit 5d969bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 42 deletions.
25 changes: 3 additions & 22 deletions build/toolchain/gcc_toolchain.gni
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ analyzer_wrapper =
rebase_path("//build/toolchain/clang_static_analyzer_wrapper.py",
root_build_dir) + " --mode=clang"

# Flag passed to sed to edit files in place
if (host_os == "mac") {
sed_in_place_flag = "-i ''"
} else {
sed_in_place_flag = "-i"
}

# This template defines a toolchain for something that works like gcc
# (including clang).
#
Expand Down Expand Up @@ -131,13 +124,7 @@ template("gcc_toolchain") {

tool("cc") {
depfile = "{{output}}.d"
command = "$cc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}"
if (use_rbe || use_goma) {
# The depfile generated on an RBE worker can contain absolute paths.
# This sed command strips off the prefix, and rewrites to be
# relative to the buildroot.
command += " && sed $sed_in_place_flag 's@/b/f/w@../..@g' $depfile"
}
command = "$cc -MMD -MF$depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CC {{output}}"
outputs =
Expand All @@ -146,10 +133,7 @@ template("gcc_toolchain") {

tool("cxx") {
depfile = "{{output}}.d"
command = "$cxx -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $coverage_flags -c {{source}} -o {{output}}"
if (use_rbe || use_goma) {
command += " && sed $sed_in_place_flag 's@/b/f/w@../..@g' $depfile"
}
command = "$cxx -MMD -MF$depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $coverage_flags -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CXX {{output}}"
outputs =
Expand All @@ -158,10 +142,7 @@ template("gcc_toolchain") {

tool("asm") {
depfile = "{{output}}.d"
command = "$asm -MD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}"
if (use_rbe || use_goma) {
command += " && sed $sed_in_place_flag 's@/b/f/w@../..@g' $depfile"
}
command = "$asm -MMD -MF$depfile {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "ASM {{output}}"
outputs =
Expand Down
25 changes: 5 additions & 20 deletions build/toolchain/mac/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ template("mac_toolchain") {

tool("cc") {
depfile = "{{output}}.d"
command = "$cc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}"
if (use_rbe || use_goma) {
command += " && sed -i '' -e 's@/b/f/w@../..@g' $depfile"
}
command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CC {{output}}"
outputs =
Expand All @@ -106,10 +103,7 @@ template("mac_toolchain") {

tool("cxx") {
depfile = "{{output}}.d"
command = "$cxx -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}"
if (use_rbe || use_goma) {
command += " && sed -i '' -e 's@/b/f/w@../..@g' $depfile"
}
command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CXX {{output}}"
outputs =
Expand All @@ -118,10 +112,7 @@ template("mac_toolchain") {

tool("asm") {
depfile = "{{output}}.d"
command = "$asm -MD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} $sysroot_flags -c {{source}} -o {{output}}"
if (use_rbe || use_goma) {
command += " && sed -i '' -e 's@/b/f/w@../..@g' $depfile"
}
command = "$asm -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} $sysroot_flags -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "ASM {{output}}"
outputs =
Expand All @@ -130,10 +121,7 @@ template("mac_toolchain") {

tool("objc") {
depfile = "{{output}}.d"
command = "$objc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} {{cflags_objc}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}"
if (use_rbe || use_goma) {
command += " && sed -i '' -e 's@/b/f/w@../..@g' $depfile"
}
command = "$objc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} {{cflags_objc}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "OBJC {{output}}"
outputs =
Expand All @@ -142,10 +130,7 @@ template("mac_toolchain") {

tool("objcxx") {
depfile = "{{output}}.d"
command = "$objc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}"
if (use_rbe || use_goma) {
command += " && sed -i '' -e 's@/b/f/w@../..@g' $depfile"
}
command = "$objc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "OBJCXX {{output}}"
outputs =
Expand Down

0 comments on commit 5d969bd

Please sign in to comment.