Index: build/toolchain/gcc_toolchain.gni |
diff --git a/build/toolchain/gcc_toolchain.gni b/build/toolchain/gcc_toolchain.gni |
index 3960acb1f342de9437a7cb4fedfa688ddf49f996..6746f5e0db9ffe5bd5c804553d99c2ad20aadce4 100644 |
--- a/build/toolchain/gcc_toolchain.gni |
+++ b/build/toolchain/gcc_toolchain.gni |
@@ -214,7 +214,11 @@ template("gcc_toolchain") { |
root_build_dir) |
arflags = "--plugin $gold_plugin_path" |
} |
- command = "rm -f {{output}} && $ar rcs $arflags {{output}} @$rspfile" |
+ |
+ # This needs a Python script to avoid using simple sh features in this |
+ # command, in case the host does not use a POSIX shell (e.g. Windows). |
+ ar_wrapper = rebase_path("//build/toolchain/gcc_ar_wrapper.py") |
+ command = "$python_path $ar_wrapper --output={{output}} --ar=$ar $arflags rcs @$rspfile" |
description = "AR {{output}}" |
rspfile_content = "{{inputs}}" |
outputs = [ |
@@ -237,25 +241,27 @@ template("gcc_toolchain") { |
unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$soname" |
} |
- # 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. |
+ # 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 (3) if the extracted list differs from the existing |
+ # .TOC file, overwrite it, otherwise, don't change it. |
tocfile = sofile + ".TOC" |
- temporary_tocname = sofile + ".tmp" |
link_command = "$ld -shared {{ldflags}} -o $unstripped_sofile -Wl,-soname=$soname @$rspfile" |
+ |
assert(defined(readelf), "to solink you must have a readelf") |
assert(defined(nm), "to solink you must have an nm") |
- toc_command = "{ $readelf -d $unstripped_sofile | grep SONAME ; $nm -gD -f p $unstripped_sofile | cut -f1-2 -d' '; } > $temporary_tocname" |
- replace_command = "if ! cmp -s $temporary_tocname $tocfile; then mv $temporary_tocname $tocfile; fi" |
- |
- command = "$link_command && $toc_command && $replace_command" |
+ strip_switch = "" |
if (defined(invoker.strip)) { |
- strip_command = |
- "${invoker.strip} --strip-unneeded -o $sofile $unstripped_sofile" |
- command += " && " + strip_command |
+ strip_switch = "--strip=${invoker.strip}" |
} |
+ |
+ # This needs a Python script to avoid using a complex shell command |
+ # requiring sh control structures, pipelines, and POSIX utilities. |
+ # The host might not have a POSIX shell and utilities (e.g. Windows). |
+ solink_wrapper = rebase_path("//build/toolchain/gcc_solink_wrapper.py") |
+ command = "$python_path $solink_wrapper --readelf=$readelf --nm=$nm $strip_switch --sofile=$unstripped_sofile --tocfile=$tocfile --output=$sofile -- $link_command" |
+ |
rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" |
description = "SOLINK $sofile" |