Skip to content

Commit

Permalink
Quick fix for shipping the android tools in the Bazel binary
Browse files Browse the repository at this point in the history
This is not really nice, there are several hacks there. This
repository will get removed in the future and linked to a
remote one instead. I tested it against the tutorial and
it works like a charm. mobile-install seems like to work,
maybe that's also fixing the last issue reported in bazelbuild#392.

Known issue: Java compilation output errors about files being
modified in the future.

--
MOS_MIGRATED_REVID=102282979
  • Loading branch information
damienmg authored and davidzchen committed Sep 3, 2015
1 parent ae0f8b0 commit 1299767
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 12 deletions.
4 changes: 0 additions & 4 deletions examples/android/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
In order to build these examples, add the following two rules to the top-level `WORKSPACE` file (two directories above this file):

```python
android_local_tools_repository(
name="android_tools",
path="<full path to the source tree of Bazel>")

android_sdk_repository(
name="androidsdk",
path="<full path to your Android SDK>",
Expand Down
49 changes: 42 additions & 7 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ genrule(
"//src/main/tools:process-wrapper",
"//src/main/tools:namespace-sandbox",
"//src/main/tools:build_interface_so",
":android_tools_repository_zip",
],
outs = ["install_base_key"],
cmd = select({
Expand Down Expand Up @@ -60,12 +61,37 @@ genrule(
""",
)

genrule(
name = "android_tools_repository_zip",
srcs = [
"//tools:srcs",
"//third_party:srcs",
"//src/tools/android/java/com/google/devtools/build/android:srcs",
"//src/tools/android/java/com/google/devtools/build/android/incrementaldeployment:srcs",
"//src/tools/android/java/com/google/devtools/build/android/ziputils:srcs",
"//src/main/protobuf:srcs",
"//src/main/java:options-srcs",
],
outs = ["android_tools_repository.zip"],
cmd = "\n".join([
"mkdir -p $(@D)/android-tools-zip",
"for i in $(SRCS); do",
" mkdir -p $$(dirname $(@D)/android-tools-zip/$$i)",
" cp $$i $$(dirname $(@D)/android-tools-zip/$$i)",
"done",
"touch $(@D)/android-tools-zip/WORKSPACE",
"mv $(@D)/android-tools-zip/src/main/java/options.BUILD" +
" $(@D)/android-tools-zip/src/main/java/BUILD",
"find $(@D)/android-tools-zip -exec touch -t 198001010000.00 '{}' ';'",
"P=$$PWD; (cd $(@D)/android-tools-zip && zip -qrD $$P/$@ *)",
"rm -fr $(@D)/android-tools-zip",
]),
)

genrule(
name = "package-zip",
srcs = [
"//src/main/java:bazel-main_deploy.jar",
# The jar must the first in the zip file because the client launcher
# looks for the first entry in the zip file for the java server.
"//src/main/cpp:client",
":libunix",
"//src/main/tools:build-runfiles",
Expand All @@ -75,14 +101,23 @@ genrule(
"//src/main/tools:build_interface_so",
"install_base_key",
":java-version",
":android_tools_repository_zip",
],
outs = ["package.zip"],
# Terrible hack to remove timestamps in the zip file
cmd = "mkdir -p $(@D)/package-zip && " +
"cp $(SRCS) $(@D)/package-zip && " +
"touch -t 198001010000.00 $(@D)/package-zip/* && " +
"zip -qj $@ $(@D)/package-zip/* && " +
"rm -fr $(@D)/package-zip",
cmd = "\n".join([
"mkdir -p $(@D)/package-zip",
"cp $(SRCS) $(@D)/package-zip",
# TODO(dmarting): we should change the client to connect to server.jar
# instead of the first binary in the list.
"mv $(@D)/package-zip/bazel-main_deploy.jar $(@D)/package-zip/A-server.jar",
"touch -t 198001010000.00 $(@D)/package-zip/*",
"mkdir $(@D)/package-zip/android_tools",
"(cd $(@D)/package-zip/android_tools && unzip -q ../android_tools_repository.zip)",
"rm $(@D)/package-zip/android_tools_repository.zip",
"P=$$PWD; (cd $(@D)/package-zip && zip -qrD $$P/$@ *)",
"rm -fr $(@D)/package-zip",
]),
)

genrule(
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/blaze.cc
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ static void ExtractData(const string &self_path) {
}
// Check that the timestamp is in the future. A past timestamp would indicate
// that the file has been tampered with. See ActuallyExtractData().
if (buf.st_mtime <= time_now) {
if (!S_ISDIR(buf.st_mode) && buf.st_mtime <= time_now) {
die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
"Error: corrupt installation: file '%s' "
"modified. Please remove '%s' and try again.",
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ java_library(
],
)

filegroup(
name = "options-srcs",
srcs = glob([
"com/google/devtools/common/options/*.java",
]) + ["options.BUILD"],
visibility = ["//src:__subpackages__"],
)

java_library(
name = "packages",
srcs = glob([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
android_local_tools_repository(name = "default_android_tools", path = __embedded_dir__ + "/android_tools")

# bind(name = "android/proguard_whitelister", actual = "//tools/android:proguard_whitelister")
# bind(name = "android/merge_manifests", actual = "//tools/android:merge_manifests")
# bind(name = "android/build_incremental_dexmanifest", actual = "//tools/android:build_incremental_dexmanifest")
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/options.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# TODO(dmarting): to make clearer, instead of doing that, we should
# move every target of the BUILD file into there java package.
java_library(
name = "options",
srcs = glob([
"com/google/devtools/common/options/*.java",
]),
visibility = ["//visibility:public"],
deps = [
"//third_party:guava",
"//third_party:jsr305",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ package(
default_visibility = ["//visibility:public"],
)

filegroup(
name = "srcs",
srcs = glob(["**"]),
)

java_library(
name = "ziputils_lib",
srcs = glob(
Expand Down

0 comments on commit 1299767

Please sign in to comment.