Skip to content

Commit

Permalink
Pull new GN, update toolchain definitions
Browse files Browse the repository at this point in the history
This pulls buildtools to get GN 290714 and updates to the new style of toolchain definitions in that revision.

Unfortunately, this new version doesn't support getting the outputs of excutables, which made the android unit test template a bit less automatic. We can consider how to best fix this in the future.

R=jamesr@chromium.org

Review URL: https://codereview.chromium.org/485833003

Cr-Commit-Position: refs/heads/master@{#290894}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290894 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
brettw@chromium.org committed Aug 20, 2014
1 parent f77ddef commit 5e5d93d
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 210 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ vars = {
# Three lines of non-changing comments so that
# the commit queue can handle CLs rolling build tools
# and whatever else without interference from each other.
"buildtools_revision": "48edf30c463fc41fb9fb0926f8466b473cb177fa",
"buildtools_revision": "f79f8ef8691cb0c91ecf36392f6defabd824af60",
# Three lines of non-changing comments so that
# the commit queue can handle CLs rolling PDFIum
# and whatever else without interference from each other.
Expand Down
17 changes: 16 additions & 1 deletion build/config/android/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -595,22 +595,37 @@ template("android_apk") {
# resource dependencies of the apk.
# unittests_dep: This should be the label of the gtest native target. This
# target must be defined previously in the same file.
# unittests_binary: The name of the binary produced by the unittests_dep
# target, relative to the root build directory. If unspecified, it assumes
# the name of the unittests_dep target (which will be correct unless that
# target specifies an "output_name".
# TODO(brettw) make this automatic by allowing get_target_outputs to
# support executables.
#
# Example
# unittest_apk("foo_unittests_apk") {
# deps = [ ":foo_java", ":foo_resources" ]
# unittests_dep = ":foo_unittests"
# }
template("unittest_apk") {
assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")

test_suite_name = get_label_info(invoker.unittests_dep, "name")

if (defined(invoker.unittests_binary)) {
unittests_binary = root_out_dir + "/" + invoker.unittests_binary
} else {
unittests_binary = root_out_dir + "/" + test_suite_name
}

android_apk(target_name) {
apk_name = test_suite_name
final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
java_files = [
"//testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java"
]
android_manifest = "//testing/android/java/AndroidManifest.xml"
unittests_outputs = get_target_outputs(invoker.unittests_dep)
unittests_outputs = [ unittests_binary ]
native_libs = [unittests_outputs[0]]
if (defined(invoker.deps)) {
deps = invoker.deps
Expand Down
11 changes: 9 additions & 2 deletions build/toolchain/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ template("android_gcc_toolchain") {
toolchain_os = "android"
toolchain_cpu_arch = invoker.toolchain_cpu_arch

# We make the assumption that the gcc_toolchain will produce a soname with
# the following definition.
soname = "{{target_output_name}}{{output_extension}}"

stripped_soname = "lib.stripped/${soname}.tmp"
temp_stripped_soname = "${stripped_soname}.tmp"

android_strip = "${tool_prefix}strip"
mkdir_command = "mkdir -p lib.stripped"
strip_command = "$android_strip --strip-unneeded -o lib.stripped/\$soname.tmp \$lib"
replace_command = "if ! cmp -s lib.stripped/\${soname}.tmp lib.stripped/\${soname}; then mv lib.stripped/\${soname}.tmp lib.stripped/\${soname}; fi"
strip_command = "$android_strip --strip-unneeded -o $temp_stripped_soname $soname"
replace_command = "if ! cmp -s $temp_stripped_soname $stripped_soname; then mv $temp_stripped_soname $stripped_soname; fi"
postsolink = "$mkdir_command && $strip_command && $replace_command"
}
}
Expand Down
120 changes: 85 additions & 35 deletions build/toolchain/gcc_toolchain.gni
Original file line number Diff line number Diff line change
Expand Up @@ -75,64 +75,114 @@ template("gcc_toolchain") {
solink_libs_section_postfix = ""
}

# Make these apply to all tools below.
lib_prefix = "-l"
lib_dir_prefix="-L"
# These library switches can apply to all tools below.
lib_switch = "-l"
lib_dir_switch = "-L"

tool("cc") {
# cflags_pch_c
command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c -c \$in -o \$out"
description = "CC \$out"
depfile = "\$out.d"
depfile = "{{output}}.d"
command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CC {{output}}"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
}

tool("cxx") {
# cflags_pch_cc
command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc -c \$in -o \$out"
description = "CXX \$out"
depfile = "\$out.d"
depfile = "{{output}}.d"
command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CXX {{output}}"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
}

tool("asm") {
# For GCC we can just use the C compiler to compile assembly.
depfile = "{{output}}.d"
command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "ASM {{output}}"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
}

tool("alink") {
command = "rm -f \$out && $ar rcs \$out @\$rspfile"
description = "AR \$out"
rspfile = "\$out.rsp"
rspfile_content = "\$in"
rspfile = "{{output}}.rsp"
command = "rm -f {{output}} && $ar rcs {{output}} @$rspfile"
description = "AR {{output}}"
rspfile_content = "{{inputs}}"
outputs = [
"{{target_out_dir}}/{{target_output_name}}{{output_extension}}"
]
default_output_extension = ".a"
output_prefix = "lib"
}

tool("solink") {
rspfile = "\$out.rsp"
rspfile_content = "-Wl,--whole-archive \$in \$solibs -Wl,--no-whole-archive $solink_libs_section_prefix \$libs $solink_libs_section_postfix"
soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so".
rspfile = soname + ".rsp"

# TODO(cjhopman): There needs to be a way for gn to correctly figure out
# the outputs of a solink command.
# These variables are not built into GN but are helpers that implement
# (1) linking to produce a .so, (2) extracting the symbols from that file
# to a temporary file, (3) if the temporary file has differences from the
# existing .TOC file, overwrite it, otherwise, don't change it.
tocname = soname + ".TOC"
temporary_tocname = soname + ".tmp"
link_command = "$ld -shared {{ldflags}} -o $soname -Wl,-soname=$soname @$rspfile"
toc_command = "{ readelf -d $soname | grep SONAME ; nm -gD -f p $soname | cut -f1-2 -d' '; } > $temporary_tocname"
replace_command = "if ! cmp -s $temporary_tocname $tocname; then mv $temporary_tocname $tocname; fi"

link_command = "$ld -shared \$ldflags -o \$lib -Wl,-soname=\$soname @\$rspfile"
toc_command = "{ readelf -d \${lib} | grep SONAME ; nm -gD -f p \${lib} | cut -f1-2 -d' '; } > \${lib}.tmp"
replace_command = "if ! cmp -s \${lib}.tmp \${lib}.TOC; then mv \${lib}.tmp \${lib}.TOC; fi"
command = "$link_command && $toc_command && $replace_command"

if (defined(invoker.postsolink)) {
command += " && " + invoker.postsolink
}
rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix"

description = "SOLINK \$lib"
#pool = "link_pool"
restat = "1"
description = "SOLINK $soname"

# Use this for {{output_extension}} expansions unless a target manually
# overrides it (in which case {{output_extension}} will be what the target
# specifies).
default_output_extension = ".so"

output_prefix = "lib"

# Since the above commands only updates the .TOC file when it changes, ask
# Ninja to check if the timestamp actually changed to know if downstream
# dependencies should be recompiled.
restat = true

# Tell GN about the output files. It will link to the soname but use the
# tocname for dependency management.
outputs = [
soname,
tocname,
]
link_output = soname
depend_output = tocname
}

tool("link") {
command = "$ld \$ldflags -o \$out -Wl,--start-group @\$rspfile \$solibs -Wl,--end-group $libs_section_prefix \$libs $libs_section_postfix"
description = "LINK \$out"
rspfile = "\$out.rsp"
rspfile_content = "\$in"
#pool = "link_pool"
outfile = "{{target_output_name}}{{output_extension}}"
rspfile = "$outfile.rsp"
command = "$ld {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_section_postfix"
description = "LINK $outfile"
rspfile_content = "{{inputs}}"
outputs = [ outfile ]
}

tool("stamp") {
command = "\${postbuilds}touch \$out"
description = "STAMP \$out"
command = "touch {{output}}"
description = "STAMP {{output}}"
}

tool("copy") {
command = "ln -f \$in \$out 2>/dev/null || (rm -rf \$out && cp -af \$in \$out)"
description = "COPY \$in \$out"
command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
description = "COPY {{source}} {{output}}"
}

# When invoking this toolchain not as the default one, these args will be
Expand Down
150 changes: 107 additions & 43 deletions build/toolchain/mac/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,71 +52,135 @@ template("mac_clang_toolchain") {
ld = invoker.ld

# Make these apply to all tools below.
lib_prefix = "-l"
lib_dir_prefix="-L"
lib_switch = "-l"
lib_dir_switch = "-L"

tool("cc") {
command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c \$cflags_pch_c -c \$in -o \$out"
description = "CC \$out"
depfile = "\$out.d"
depfile = "{{output}}.d"
command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CC {{output}}"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
}

tool("cxx") {
command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc \$cflags_pch_cc -c \$in -o \$out"
description = "CXX \$out"
depfile = "\$out.d"
depfile = "{{output}}.d"
command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CXX {{output}}"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
}

tool("asm") {
# For GCC we can just use the C compiler to compile assembly.
depfile = "{{output}}.d"
command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "ASM {{output}}"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
}

tool("objc") {
command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c \$cflags_objc \$cflags_pch_objc -c \$in -o \$out"
description = "OBJC \$out"
depfile = "\$out.d"
depfile = "{{output}}.d"
command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} {{cflags_objc}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "OBJC {{output}}"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
}

tool("objcxx") {
command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc \$cflags_objcc \$cflags_pch_objcc -c \$in -o \$out"
description = "OBJCXX \$out"
depfile = "\$out.d"
depfile = "{{output}}.d"
command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "OBJCXX {{output}}"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
}

tool("alink") {
command = "rm -f \$out && ./gyp-mac-tool filter-libtool libtool \$libtool_flags -static -o \$out \$in \$postbuilds"
description = "LIBTOOL-STATIC \$out"
command = "rm -f {{output}} && ./gyp-mac-tool filter-libtool libtool -static -o {{output}} {{inputs}}"
description = "LIBTOOL-STATIC {{output}}"
outputs = [
"{{target_out_dir}}/{{target_output_name}}{{output_extension}}"
]
default_output_extension = ".a"
output_prefix = "lib"
}

tool("solink") {
command = "if [ ! -e \$lib -o ! -e \${lib}.TOC ] || otool -l \$lib | grep -q LC_REEXPORT_DYLIB ; then $ld -shared \$ldflags -o \$lib -Wl,-filelist,\$rspfile \$solibs \$libs \$postbuilds && { otool -l \$lib | grep LC_ID_DYLIB -A 5; nm -gP \$lib | cut -f1-2 -d' ' | grep -v U\$\$; true; } > \${lib}.TOC; else $ld -shared \$ldflags -o \$lib \$in \$solibs \$libs \$postbuilds && { otool -l \$lib | grep LC_ID_DYLIB -A 5; nm -gP \$lib | cut -f1-2 -d' ' | grep -v U\$\$; true; } > \${lib}.tmp && if ! cmp -s \${lib}.tmp \${lib}.TOC; then mv \${lib}.tmp \${lib}.TOC ; fi; fi"
description = "SOLINK \$lib"
rspfile = "\$out.rsp"
rspfile_content = "\$in_newline"
#pool = "link_pool"
restat = "1"
dylib = "{{target_output_name}}{{output_extension}}" # eg "libfoo.dylib"
rspfile = dylib + ".rsp"

# These variables are not build into GN but are helpers that implement
# (1) linking to produce a .so, (2) extracting the symbols from that file
# to a temporary file, (3) if the temporary file has differences from the
# existing .TOC file, overwrite it, oterwise, don't change it.
#
# As a special case, if the library reexports symbols from other dynamic
# libraries, we always update the .TOC and skip the temporary file and
# diffing steps, since that library always needs to be re-linked.
tocname = dylib + ".TOC"
temporary_tocname = dylib + ".tmp"

does_reexport_command = "[ ! -e $dylib -o ! -e $tocname ] || otool -l $dylib | grep -q LC_REEXPORT_DYLIB"
link_command = "$ld -shared {{ldflags}} -o $dylib -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
replace_command = "if ! cmp -s $temporary_tocname $tocname; then mv $temporary_tocname $tocname"
extract_toc_command = "{ otool -l $dylib | grep LC_ID_DYLIB -A 5; nm -gP $dylib | cut -f1-2 -d' ' | grep -v U\$\$; true; }"

command = "if $does_reexport_command ; then $link_command && $extract_toc_command > $tocname; else $link_command && $extract_toc_command > $temporary_tocname && $replace_command ; fi; fi"

rspfile_content = "{{inputs_newline}}"

description = "SOLINK {{output}}"

# Use this for {{output_extension}} expansions unless a target manually
# overrides it (in which case {{output_extension}} will be what the target
# specifies).
default_output_extension = ".dylib"

output_prefix = "lib"

# Since the above commands only updates the .TOC file when it changes, ask
# Ninja to check if the timestamp actually changed to know if downstream
# dependencies should be recompiled.
restat = true

# Tell GN about the output files. It will link to the dylib but use the
# tocname for dependency management.
outputs = [
dylib,
tocname,
]
link_output = dylib
depend_output = tocname
}

tool("link") {
command = "$ld \$ldflags -o \$out -Wl,-filelist,\$rspfile \$solibs \$libs \$postbuilds"
description = "LINK \$out"
rspfile = "\$out.rsp"
rspfile_content = "\$in_newline"
#pool = "link_pool"
outfile = "{{target_output_name}}{{output_extension}}"
rspfile = "$outfile.rsp"
command = "$ld {{ldflags}} -o $outfile -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
description = "LINK $outfile"
rspfile_content = "{{inputs_newline}}"
outputs = [ outfile ]
}
#tool("infoplist") {
# command = "$cc -E -P -Wno-trigraphs -x c \$defines \$in -o \$out && plutil -convert xml1 \$out \$out"
# description = "INFOPLIST \$out"
#}
#tool("mac_tool") {
# command = "\$env ./gyp-mac-tool \$mactool_cmd \$in \$out"
# description = "MACTOOL \$mactool_cmd \$in"
#}
#tool("package_framework") {
# command = "./gyp-mac-tool package-framework \$out \$version \$postbuilds && touch \$out"
# description = "PACKAGE FRAMEWORK \$out, POSTBUILDS"
#}

tool("stamp") {
command = "\${postbuilds}touch \$out"
description = "STAMP \$out"
command = "touch {{output}}"
description = "STAMP {{output}}"
}

tool("copy") {
command = "ln -f \$in \$out 2>/dev/null || (rm -rf \$out && cp -af \$in \$out)"
description = "COPY \$in \$out"
command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
description = "COPY {{source}} {{output}}"
}

toolchain_args() {
Expand Down
Loading

0 comments on commit 5e5d93d

Please sign in to comment.