From 6dc8c42960905868ed492f0d4a6181c7a2e71bcb Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sat, 2 Jun 2018 09:07:09 +0200 Subject: [PATCH] Bazel: Replace native {http,git}_archive with Skylark rules Future Bazel versions will discontinue support for native http rules and replace them with Skylark equivalents: [1]. Prepare the Gerit build tool chain for that move. The replacements depend on this PR in rules_closure project: [2], that wasn't merged yet. For now we can apply "patch on import", thanks Skylark's http rules patch support. When [2] is merged, and new version of rules_clsoure is released, we can remove the patching procedure. One side effect of this change is that Skylark version of http_file lost the ability to save the downloaded artifact under its real name and is using a generic download file name. The rule closure tool chain stumbles on this, and rejects to accept polymer_closure artifact without ".js" suffix. To rectify add intermediate rule and renamed "download" file to one with js suffix "polymer_closure_renamed.js": [3]. [1] https://groups.google.com/d/topic/bazel-discuss/dO2MHQLwJF0/discussion [2] https://github.com/bazelbuild/rules_closure/pull/270 [3] http://paste.openstack.org/show/722557 Inspired-By: "Klaus Aehlig" Feature: Issue 9151 Change-Id: I44ca2ecfea67d2f4434a4743e7a6f8a3645e96a8 --- ...http-git-_archive-with-Skylark-rules.patch | 133 ++++++++++++++++++ WORKSPACE | 5 +- lib/polymer_externs/BUILD | 9 +- 3 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 0001-Replace-native-http-git-_archive-with-Skylark-rules.patch diff --git a/0001-Replace-native-http-git-_archive-with-Skylark-rules.patch b/0001-Replace-native-http-git-_archive-with-Skylark-rules.patch new file mode 100644 index 0000000000..3ccf5cdd02 --- /dev/null +++ b/0001-Replace-native-http-git-_archive-with-Skylark-rules.patch @@ -0,0 +1,133 @@ +Date: Wed, 30 May 2018 21:22:18 +0200 +Subject: [PATCH] Replace native {http,git}_archive with Skylark rules + +See [1] for more details. + +Test Plan: + +* Apply this CL on Bazel master: [2] and build bazel +* Run with this custom built bazel version: + + $ bazel test //javatests/... + $ bazel test //closure/... + +[1] https://groups.google.com/d/topic/bazel-discuss/dO2MHQLwJF0/discussion +[2] https://bazel-review.googlesource.com/#/c/bazel/+/55932/ +--- + closure/repositories.bzl | 23 ++++++++++++----------- + 1 file changed, 12 insertions(+), 11 deletions(-) + +diff --git a/closure/repositories.bzl b/closure/repositories.bzl +index 9b84a72..2816fb6 100644 +--- closure/repositories.bzl ++++ closure/repositories.bzl +@@ -14,6 +14,7 @@ + + """External dependencies for Closure Rules.""" + ++load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") + load("//closure/private:java_import_external.bzl", "java_import_external") + load("//closure/private:platform_http_file.bzl", "platform_http_file") + load("//closure:filegroup_external.bzl", "filegroup_external") +@@ -405,7 +406,7 @@ def com_google_common_html_types(): + ) + + def com_google_common_html_types_html_proto(): +- native.http_file( ++ http_file( + name = "com_google_common_html_types_html_proto", + sha256 = "6ece202f11574e37d0c31d9cf2e9e11a0dbc9218766d50d211059ebd495b49c3", + urls = [ +@@ -633,7 +634,7 @@ def com_google_javascript_closure_compiler(): + + def com_google_javascript_closure_library(): + # After updating: bazel run //closure/library:regenerate -- "$PWD" +- native.new_http_archive( ++ http_archive( + name = "com_google_javascript_closure_library", + urls = [ + "https://mirror.bazel.build/github.com/google/closure-library/archive/v20180405.tar.gz", +@@ -658,7 +659,7 @@ def com_google_jsinterop_annotations(): + + def com_google_protobuf(): + # Note: Protobuf 3.6.0+ is going to use C++11 +- native.http_archive( ++ http_archive( + name = "com_google_protobuf", + strip_prefix = "protobuf-3.5.1", + sha256 = "826425182ee43990731217b917c5c3ea7190cfda141af4869e6d4ad9085a740f", +@@ -669,7 +670,7 @@ def com_google_protobuf(): + ) + + def com_google_protobuf_js(): +- native.new_http_archive( ++ http_archive( + name = "com_google_protobuf_js", + urls = [ + "https://mirror.bazel.build/github.com/google/protobuf/archive/v3.5.1.tar.gz", +@@ -722,7 +723,7 @@ def com_google_template_soy(): + ) + + def com_google_template_soy_jssrc(): +- native.new_http_archive( ++ http_archive( + name = "com_google_template_soy_jssrc", + sha256 = "c76ab4cb6e46a7c76336640b3c40d6897b420209a6c0905cdcd32533dda8126a", + urls = [ +@@ -757,7 +758,7 @@ def com_squareup_javapoet(): + ) + + def fonts_noto_hinted_deb(): +- native.http_file( ++ http_file( + name = "fonts_noto_hinted_deb", + urls = [ + "https://mirror.bazel.build/http.us.debian.org/debian/pool/main/f/fonts-noto/fonts-noto-hinted_20161116-1_all.deb", +@@ -767,7 +768,7 @@ def fonts_noto_hinted_deb(): + ) + + def fonts_noto_mono_deb(): +- native.http_file( ++ http_file( + name = "fonts_noto_mono_deb", + urls = [ + "https://mirror.bazel.build/http.us.debian.org/debian/pool/main/f/fonts-noto/fonts-noto-mono_20161116-1_all.deb", +@@ -801,7 +802,7 @@ def javax_inject(): + ) + + def libexpat_amd64_deb(): +- native.http_file( ++ http_file( + name = "libexpat_amd64_deb", + urls = [ + "https://mirror.bazel.build/http.us.debian.org/debian/pool/main/e/expat/libexpat1_2.1.0-6+deb8u3_amd64.deb", +@@ -811,7 +812,7 @@ def libexpat_amd64_deb(): + ) + + def libfontconfig_amd64_deb(): +- native.http_file( ++ http_file( + name = "libfontconfig_amd64_deb", + urls = [ + "https://mirror.bazel.build/http.us.debian.org/debian/pool/main/f/fontconfig/libfontconfig1_2.11.0-6.3+deb8u1_amd64.deb", +@@ -821,7 +822,7 @@ def libfontconfig_amd64_deb(): + ) + + def libfreetype_amd64_deb(): +- native.http_file( ++ http_file( + name = "libfreetype_amd64_deb", + urls = [ + "https://mirror.bazel.build/http.us.debian.org/debian/pool/main/f/freetype/libfreetype6_2.5.2-3+deb8u1_amd64.deb", +@@ -831,7 +832,7 @@ def libfreetype_amd64_deb(): + ) + + def libpng_amd64_deb(): +- native.http_file( ++ http_file( + name = "libpng_amd64_deb", + urls = [ + "https://mirror.bazel.build/http.us.debian.org/debian/pool/main/libp/libpng/libpng12-0_1.2.50-2+deb8u2_amd64.deb", +-- +2.16.3 + diff --git a/WORKSPACE b/WORKSPACE index 73469a400a..786b9ce584 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,5 +1,6 @@ workspace(name = "gerrit") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") load("//tools/bzl:maven_jar.bzl", "maven_jar", "GERRIT", "MAVEN_LOCAL") load("//lib/codemirror:cm.bzl", "CM_VERSION", "DIFF_MATCH_PATCH_VERSION") load("//plugins:external_plugin_deps.bzl", "external_plugin_deps") @@ -13,6 +14,8 @@ http_archive( http_archive( name = "io_bazel_rules_closure", + build_file_content = "exports_files([\"0001-Replace-native-http-git-_archive-with-Skylark-rules.patch\"])", + patches = ["//:0001-Replace-native-http-git-_archive-with-Skylark-rules.patch"], sha256 = "a80acb69c63d5f6437b099c111480a4493bad4592015af2127a2f49fb7512d8d", strip_prefix = "rules_closure-0.7.0", url = "https://github.com/bazelbuild/rules_closure/archive/0.7.0.tar.gz", @@ -24,7 +27,7 @@ http_archive( http_file( name = "polymer_closure", sha256 = "5a589bdba674e1fec7188e9251c8624ebf2d4d969beb6635f9148f420d1e08b1", - url = "https://raw.githubusercontent.com/google/closure-compiler/775609aad61e14aef289ebec4bfc09ad88877f9e/contrib/externs/polymer-1.0.js", + urls = ["https://raw.githubusercontent.com/google/closure-compiler/775609aad61e14aef289ebec4bfc09ad88877f9e/contrib/externs/polymer-1.0.js"], ) load("@bazel_skylib//:lib.bzl", "versions") diff --git a/lib/polymer_externs/BUILD b/lib/polymer_externs/BUILD index 2f1bdbded2..ae8f9c0ffe 100644 --- a/lib/polymer_externs/BUILD +++ b/lib/polymer_externs/BUILD @@ -18,9 +18,16 @@ package( load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library") +genrule( + name = "polymer_closure_renamed", + srcs = ["@polymer_closure//file"], + outs = ["polymer_closure_renamed.js"], + cmd = "cp $< $@", +) + closure_js_library( name = "polymer_closure", - srcs = ["@polymer_closure//file"], + srcs = [":polymer_closure_renamed"], data = ["//lib:LICENSE-Apache2.0"], no_closure_library = True, )