From 82364bae1690d0f4421afa0116441d99ce35b92a Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Mon, 24 Oct 2016 16:49:15 -0400 Subject: [PATCH] Build for Android from Windows, work in progress. Pretty vanilla stuff here, mostly just making the gcc-like toolchain Windows friendly. I was having trouble getting rm -r {{output}} && $ar rcs {{output}} @$rspfile to work without deleting my ar.exe, so I chickened out the usual way by adding gn/ar.py. I've also updated bin/droid to work with Git Bash on Windows. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3751 Change-Id: I04c34ccc91e6a291c11ac4e7a7a0ffe41d879fe6 Reviewed-on: https://skia-review.googlesource.com/3751 Reviewed-by: Brian Osman Commit-Queue: Mike Klein --- bin/droid | 7 ++++--- gn/BUILD.gn | 31 ++++++++++++++++++++++++++----- gn/BUILDCONFIG.gn | 2 ++ gn/ar.py | 18 ++++++++++++++++++ 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 gn/ar.py diff --git a/bin/droid b/bin/droid index b1644c6..c633181 100755 --- a/bin/droid +++ b/bin/droid @@ -16,6 +16,7 @@ args=$@ set -e set -x -adb push $path /data/local/tmp/ -adb push resources /data/local/tmp/ -adb shell "cd /data/local/tmp; ./$name $args" +adb push $path //data/local/tmp/ +adb push resources //data/local/tmp/ +adb shell "chmod +x //data/local/tmp/$name" +adb shell "cd //data/local/tmp; ./$name $args" diff --git a/gn/BUILD.gn b/gn/BUILD.gn index bd5ce7f..8451b9f 100644 --- a/gn/BUILD.gn +++ b/gn/BUILD.gn @@ -12,6 +12,11 @@ declare_args() { ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar" cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang" cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++" + if (host_os == "win") { + ar = ar + ".exe" + cc = cc + ".exe" + cxx = cxx + ".exe" + } } windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0" @@ -24,6 +29,14 @@ declare_args() { cc_wrapper = "" } +if (host_os == "win") { + python = "python.bat" + stamp = "cmd.exe /c echo >" +} else { + python = "python" + stamp = "touch" +} + if (!is_win) { is_clang = exec_script("is_clang.py", [ @@ -465,13 +478,13 @@ toolchain("msvc") { } tool("stamp") { - command = "cmd.exe /c echo > {{output}}" + command = "$stamp {{output}}" description = "stamp {{output}}" } tool("copy") { cp_py = rebase_path("cp.py") - command = "python.bat $cp_py {{source}} {{output}}" + command = "$python $cp_py {{source}} {{output}}" description = "copy {{source}} {{output}}" } } @@ -531,7 +544,15 @@ toolchain("gcc_like") { } tool("alink") { - command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}" + if (host_os == "win") { + rspfile = "{{output}}.rsp" + rspfile_content = "{{inputs}}" + ar_py = rebase_path("ar.py") + command = "$python $ar_py $ar {{output}} $rspfile" + } else { + # We'd use ar.py all the time, but Mac ar doesn't support @rspfile syntax. :( + command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}" + } outputs = [ "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", ] @@ -566,13 +587,13 @@ toolchain("gcc_like") { } tool("stamp") { - command = "touch {{output}}" + command = "$stamp {{output}}" description = "stamp {{output}}" } tool("copy") { cp_py = rebase_path("cp.py") - command = "python $cp_py {{source}} {{output}}" + command = "$python $cp_py {{source}} {{output}}" description = "copy {{source}} {{output}}" } } diff --git a/gn/BUILDCONFIG.gn b/gn/BUILDCONFIG.gn index d997ec5..12df69d 100644 --- a/gn/BUILDCONFIG.gn +++ b/gn/BUILDCONFIG.gn @@ -59,6 +59,8 @@ if (is_android) { ndk_host = "linux-x86_64" } else if (host_os == "mac") { ndk_host = "darwin-x86_64" + } else if (host_os == "win") { + ndk_host = "windows-x86_64" } if (target_cpu == "arm64") { diff --git a/gn/ar.py b/gn/ar.py new file mode 100644 index 0000000..dc3ae8d --- /dev/null +++ b/gn/ar.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +# +# Copyright 2016 Google Inc. +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import subprocess +import sys + +# Equivalent to: rm -f $2 && $1 rcs $2 @$3 + +ar, output, rspfile = sys.argv[1:] + +if os.path.exists(output): + os.remove(output) +sys.exit(subprocess.call([ar, "rcs", output, "@" + rspfile])) -- 2.7.4