From 30610130c13a1f89916e4b4db53feef29d53e124 Mon Sep 17 00:00:00 2001 From: James O'Kane Date: Sat, 10 Mar 2018 20:50:40 -0800 Subject: [PATCH 1/9] Move/rename files to make java files prefixed with java to allow naming consistency with python files. --- appengine/{ => java}/appengine_deploy.sh.template | 0 appengine/{ => java}/appengine_runner.sh.template | 0 appengine/{appengine.bzl => java_appengine.bzl} | 0 appengine/{pysdk.BUILD => py/sdk.BUILD} | 0 examples/{ => java}/BUILD | 0 examples/{ => java}/src/App.java | 0 examples/{ => java}/src/BUILD | 0 examples/{ => java}/webapp/BUILD | 0 examples/{ => java}/webapp/WEB-INF/appengine-web.xml | 0 examples/{ => java}/webapp/WEB-INF/web.xml | 0 test/{ => java}/BUILD | 0 test/{ => java}/WEB-INF/appengine-web.xml | 0 test/{ => java}/WEB-INF/logging.properties | 0 test/{ => java}/WEB-INF/web.xml | 0 test/{ => java}/check_war.sh | 0 test/{ => java}/data/BUILD | 0 test/{ => java}/data/welcome.jsp | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename appengine/{ => java}/appengine_deploy.sh.template (100%) rename appengine/{ => java}/appengine_runner.sh.template (100%) rename appengine/{appengine.bzl => java_appengine.bzl} (100%) rename appengine/{pysdk.BUILD => py/sdk.BUILD} (100%) rename examples/{ => java}/BUILD (100%) rename examples/{ => java}/src/App.java (100%) rename examples/{ => java}/src/BUILD (100%) rename examples/{ => java}/webapp/BUILD (100%) rename examples/{ => java}/webapp/WEB-INF/appengine-web.xml (100%) rename examples/{ => java}/webapp/WEB-INF/web.xml (100%) rename test/{ => java}/BUILD (100%) rename test/{ => java}/WEB-INF/appengine-web.xml (100%) rename test/{ => java}/WEB-INF/logging.properties (100%) rename test/{ => java}/WEB-INF/web.xml (100%) rename test/{ => java}/check_war.sh (100%) rename test/{ => java}/data/BUILD (100%) rename test/{ => java}/data/welcome.jsp (100%) diff --git a/appengine/appengine_deploy.sh.template b/appengine/java/appengine_deploy.sh.template similarity index 100% rename from appengine/appengine_deploy.sh.template rename to appengine/java/appengine_deploy.sh.template diff --git a/appengine/appengine_runner.sh.template b/appengine/java/appengine_runner.sh.template similarity index 100% rename from appengine/appengine_runner.sh.template rename to appengine/java/appengine_runner.sh.template diff --git a/appengine/appengine.bzl b/appengine/java_appengine.bzl similarity index 100% rename from appengine/appengine.bzl rename to appengine/java_appengine.bzl diff --git a/appengine/pysdk.BUILD b/appengine/py/sdk.BUILD similarity index 100% rename from appengine/pysdk.BUILD rename to appengine/py/sdk.BUILD diff --git a/examples/BUILD b/examples/java/BUILD similarity index 100% rename from examples/BUILD rename to examples/java/BUILD diff --git a/examples/src/App.java b/examples/java/src/App.java similarity index 100% rename from examples/src/App.java rename to examples/java/src/App.java diff --git a/examples/src/BUILD b/examples/java/src/BUILD similarity index 100% rename from examples/src/BUILD rename to examples/java/src/BUILD diff --git a/examples/webapp/BUILD b/examples/java/webapp/BUILD similarity index 100% rename from examples/webapp/BUILD rename to examples/java/webapp/BUILD diff --git a/examples/webapp/WEB-INF/appengine-web.xml b/examples/java/webapp/WEB-INF/appengine-web.xml similarity index 100% rename from examples/webapp/WEB-INF/appengine-web.xml rename to examples/java/webapp/WEB-INF/appengine-web.xml diff --git a/examples/webapp/WEB-INF/web.xml b/examples/java/webapp/WEB-INF/web.xml similarity index 100% rename from examples/webapp/WEB-INF/web.xml rename to examples/java/webapp/WEB-INF/web.xml diff --git a/test/BUILD b/test/java/BUILD similarity index 100% rename from test/BUILD rename to test/java/BUILD diff --git a/test/WEB-INF/appengine-web.xml b/test/java/WEB-INF/appengine-web.xml similarity index 100% rename from test/WEB-INF/appengine-web.xml rename to test/java/WEB-INF/appengine-web.xml diff --git a/test/WEB-INF/logging.properties b/test/java/WEB-INF/logging.properties similarity index 100% rename from test/WEB-INF/logging.properties rename to test/java/WEB-INF/logging.properties diff --git a/test/WEB-INF/web.xml b/test/java/WEB-INF/web.xml similarity index 100% rename from test/WEB-INF/web.xml rename to test/java/WEB-INF/web.xml diff --git a/test/check_war.sh b/test/java/check_war.sh similarity index 100% rename from test/check_war.sh rename to test/java/check_war.sh diff --git a/test/data/BUILD b/test/java/data/BUILD similarity index 100% rename from test/data/BUILD rename to test/java/data/BUILD diff --git a/test/data/welcome.jsp b/test/java/data/welcome.jsp similarity index 100% rename from test/data/welcome.jsp rename to test/java/data/welcome.jsp From 39266aedde387c80ce69bc65886030ee1d304f4d Mon Sep 17 00:00:00 2001 From: James O'Kane Date: Sat, 10 Mar 2018 21:19:07 -0800 Subject: [PATCH 2/9] Update pathnames within files to match the file moves. --- WORKSPACE | 4 ++-- appengine/BUILD | 12 ------------ appengine/java/BUILD | 11 +++++++++++ appengine/java_appengine.bzl | 6 +++--- examples/java/BUILD | 8 ++++---- examples/java/src/BUILD | 2 +- examples/java/webapp/BUILD | 2 +- test/java/BUILD | 8 ++++---- test/java/check_war.sh | 2 +- test/java/data/BUILD | 2 +- 10 files changed, 28 insertions(+), 29 deletions(-) create mode 100644 appengine/java/BUILD diff --git a/WORKSPACE b/WORKSPACE index 9847985..1f5a955 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,4 +1,4 @@ workspace(name = "io_bazel_rules_appengine") -load("//appengine:appengine.bzl", "appengine_repositories") -appengine_repositories() +load("//appengine:java_appengine.bzl", "java_appengine_repositories") +java_appengine_repositories() diff --git a/appengine/BUILD b/appengine/BUILD index 0dbb26d..ab8250b 100644 --- a/appengine/BUILD +++ b/appengine/BUILD @@ -6,18 +6,6 @@ java_library( exports = ["@javax_servlet_api//jar:jar"], ) -filegroup( - name = "runner_template", - srcs = ["appengine_runner.sh.template"], - visibility = ["//visibility:public"], -) - -filegroup( - name = "deploy_template", - srcs = ["appengine_deploy.sh.template"], - visibility = ["//visibility:public"], -) - filegroup( name = "srcs", srcs = glob(["**"]), diff --git a/appengine/java/BUILD b/appengine/java/BUILD new file mode 100644 index 0000000..dcd229a --- /dev/null +++ b/appengine/java/BUILD @@ -0,0 +1,11 @@ +filegroup( + name = "runner_template", + srcs = ["appengine_runner.sh.template"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "deploy_template", + srcs = ["appengine_deploy.sh.template"], + visibility = ["//visibility:public"], +) diff --git a/appengine/java_appengine.bzl b/appengine/java_appengine.bzl index f17c12e..aefce2b 100644 --- a/appengine/java_appengine.bzl +++ b/appengine/java_appengine.bzl @@ -213,11 +213,11 @@ appengine_war_base = rule( single_file = True, ), "_runner_template": attr.label( - default = Label("//appengine:runner_template"), + default = Label("//appengine/java:runner_template"), single_file = True, ), "_deploy_template": attr.label( - default = Label("//appengine:deploy_template"), + default = Label("//appengine/java:deploy_template"), single_file = True, ), "_appengine_sdk": attr.label( @@ -305,7 +305,7 @@ filegroup( ) """ -def appengine_repositories(): +def java_appengine_repositories(): native.new_http_archive( name = "com_google_appengine_java", url = "http://central.maven.org/maven2/com/google/appengine/appengine-java-sdk/%s/%s.zip" % (APPENGINE_VERSION, APPENGINE_DIR), diff --git a/examples/java/BUILD b/examples/java/BUILD index a926e49..d555a4f 100644 --- a/examples/java/BUILD +++ b/examples/java/BUILD @@ -1,8 +1,8 @@ -load("//appengine:appengine.bzl", "appengine_war") +load("//appengine:java_appengine.bzl", "appengine_war") appengine_war( name = "examples", - data = ["//examples/webapp"], - data_path = "/examples/webapp", - jars = ["//examples/src:src_deploy.jar"], + data = ["//examples/java/webapp"], + data_path = "/examples/java/webapp", + jars = ["//examples/java/src:src_deploy.jar"], ) diff --git a/examples/java/src/BUILD b/examples/java/src/BUILD index 3b72f69..20deb10 100644 --- a/examples/java/src/BUILD +++ b/examples/java/src/BUILD @@ -1,7 +1,7 @@ java_binary( name = "src", srcs = ["App.java"], - visibility = ["//examples:__pkg__"], + visibility = ["//examples/java:__pkg__"], deps = [ "//appengine:javax.servlet.api", "@com_google_appengine_java//:api", diff --git a/examples/java/webapp/BUILD b/examples/java/webapp/BUILD index eb3cd55..4c0471a 100644 --- a/examples/java/webapp/BUILD +++ b/examples/java/webapp/BUILD @@ -1,5 +1,5 @@ filegroup( name = "webapp", srcs = glob(["**"]), - visibility = ["//examples:__pkg__"], + visibility = ["//examples/java:__pkg__"], ) diff --git a/test/java/BUILD b/test/java/BUILD index 98880d6..ca75d17 100644 --- a/test/java/BUILD +++ b/test/java/BUILD @@ -1,13 +1,13 @@ -load("//appengine:appengine.bzl", "appengine_war") +load("//appengine:java_appengine.bzl", "appengine_war") appengine_war( name = "test-war", data = [ ":web-inf", - "//test/data:gen-data", - "//test/data:test-data", + "//test/java/data:gen-data", + "//test/java/data:test-data", ], - data_path = "/test", + data_path = "/test/java", jars = [":app_deploy.jar"], testonly = 1, ) diff --git a/test/java/check_war.sh b/test/java/check_war.sh index c5554d7..40820cb 100755 --- a/test/java/check_war.sh +++ b/test/java/check_war.sh @@ -6,7 +6,7 @@ RUNFILES="$TEST_SRCDIR" if [ -d "${TEST_SRCDIR}/io_bazel_rules_appengine" ]; then RUNFILES="${TEST_SRCDIR}/io_bazel_rules_appengine" fi -TEST_WAR="${RUNFILES}/test/test-war.war" +TEST_WAR="${RUNFILES}/test/java/test-war.war" JAR="${TEST_SRCDIR}/local_jdk/bin/jar" function assert_war_contains() { diff --git a/test/java/data/BUILD b/test/java/data/BUILD index 8695e8b..0043952 100644 --- a/test/java/data/BUILD +++ b/test/java/data/BUILD @@ -1,5 +1,5 @@ package( - default_visibility = ["//test:__pkg__"], + default_visibility = ["//test/java:__pkg__"], default_testonly = 1, ) From 5f3f0d419214a17e72fb162af9702442ff2324d3 Mon Sep 17 00:00:00 2001 From: James O'Kane Date: Sat, 10 Mar 2018 21:29:36 -0800 Subject: [PATCH 3/9] Run buildifier on WORKSPACE, BUILD, and *.bzl files. --- WORKSPACE | 1 + appengine/BUILD | 2 +- appengine/java_appengine.bzl | 1 - appengine/py/sdk.BUILD | 8 +++++--- appengine/py_appengine.bzl | 15 ++++++--------- test/java/BUILD | 4 ++-- test/java/data/BUILD | 4 ++-- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 1f5a955..90d72ad 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,4 +1,5 @@ workspace(name = "io_bazel_rules_appengine") load("//appengine:java_appengine.bzl", "java_appengine_repositories") + java_appengine_repositories() diff --git a/appengine/BUILD b/appengine/BUILD index ab8250b..ba8dc73 100644 --- a/appengine/BUILD +++ b/appengine/BUILD @@ -3,7 +3,7 @@ java_library( name = "javax.servlet.api", neverlink = 1, visibility = ["//visibility:public"], - exports = ["@javax_servlet_api//jar:jar"], + exports = ["@javax_servlet_api//jar"], ) filegroup( diff --git a/appengine/java_appengine.bzl b/appengine/java_appengine.bzl index aefce2b..daee39f 100644 --- a/appengine/java_appengine.bzl +++ b/appengine/java_appengine.bzl @@ -268,7 +268,6 @@ def appengine_war(name, jars, data, data_path, testonly = 0): testonly = testonly, ) - APPENGINE_VERSION = "1.9.57" APPENGINE_DIR = "appengine-java-sdk-" + APPENGINE_VERSION diff --git a/appengine/py/sdk.BUILD b/appengine/py/sdk.BUILD index 3bdef5f..d94c7b0 100755 --- a/appengine/py/sdk.BUILD +++ b/appengine/py/sdk.BUILD @@ -18,7 +18,10 @@ package(default_visibility = ["//visibility:public"]) py_library( name = "appengine", srcs = glob(["**/*.py"]), - data = glob(["**/*"], exclude=["**/*.py"]), + data = glob( + ["**/*"], + exclude = ["**/*.py"], + ), ) py_binary( @@ -91,8 +94,8 @@ py_library( py_library( name = "webapp2-2.5.2", srcs = glob(["lib/webapp2-2.5.2/**/*.py"]), - deps = [":webob-1.2.3"], imports = ["lib/webapp2-2.5.2"], + deps = [":webob-1.2.3"], ) py_library( @@ -113,7 +116,6 @@ py_library( imports = ["lib/yaml-3.10"], ) - py_library( name = "endpoints-latest", deps = [":endpoints-1.0"], diff --git a/appengine/py_appengine.bzl b/appengine/py_appengine.bzl index 216fb3a..6c6be20 100644 --- a/appengine/py_appengine.bzl +++ b/appengine/py_appengine.bzl @@ -57,17 +57,14 @@ def _find_locally_or_download_impl(repository_ctx): stripPrefix="google_appengine") repository_ctx.template("BUILD", Label("//appengine:pysdk.BUILD")) - _find_locally_or_download = repository_rule( local = False, implementation = _find_locally_or_download_impl, ) - def py_appengine_repositories(): _find_locally_or_download(name = "com_google_appengine_python") - def py_appengine_test(name, srcs, deps=[], data=[], libraries={}, size=None): """A variant of py_test that sets up an App Engine environment.""" extra_deps = ["@com_google_appengine_python//:appengine"] @@ -81,7 +78,6 @@ def py_appengine_test(name, srcs, deps=[], data=[], libraries={}, size=None): size=size, ) - def _py_appengine_binary_base_impl(ctx): """Implementation of the rule that creates - the script to run locally @@ -201,14 +197,16 @@ exit $ret_code return struct(runfiles=runfiles, py=ctx.attr.binary.py) - py_appengine_binary_base = rule( _py_appengine_binary_base_impl, attrs = { "binary": attr.label(), - "devappserver": attr.label(default=Label("@com_google_appengine_python//:dev_appserver")), - "appcfg": attr.label(default=Label("@com_google_appengine_python//:appcfg")), - "configs": attr.label_list(allow_files=FileType([".yaml", ".py"])), + "devappserver": attr.label(default = Label("@com_google_appengine_python//:dev_appserver")), + "appcfg": attr.label(default = Label("@com_google_appengine_python//:appcfg")), + "configs": attr.label_list(allow_files = FileType([ + ".yaml", + ".py", + ])), }, executable = True, outputs = { @@ -216,7 +214,6 @@ py_appengine_binary_base = rule( }, ) - def py_appengine_binary(name, srcs, configs, deps=[], data=[]): """Convenience macro that builds the app and offers an executable target to deploy on Google app engine. diff --git a/test/java/BUILD b/test/java/BUILD index ca75d17..cb93f97 100644 --- a/test/java/BUILD +++ b/test/java/BUILD @@ -2,6 +2,7 @@ load("//appengine:java_appengine.bzl", "appengine_war") appengine_war( name = "test-war", + testonly = 1, data = [ ":web-inf", "//test/java/data:gen-data", @@ -9,7 +10,6 @@ appengine_war( ], data_path = "/test/java", jars = [":app_deploy.jar"], - testonly = 1, ) java_binary( @@ -21,9 +21,9 @@ sh_test( name = "check_war", srcs = ["check_war.sh"], data = [ + ":test-war", "@local_jdk//:jar", "@local_jdk//:jdk-default", - ":test-war", ], ) diff --git a/test/java/data/BUILD b/test/java/data/BUILD index 0043952..80ff454 100644 --- a/test/java/data/BUILD +++ b/test/java/data/BUILD @@ -1,6 +1,6 @@ package( - default_visibility = ["//test/java:__pkg__"], default_testonly = 1, + default_visibility = ["//test/java:__pkg__"], ) filegroup( @@ -10,6 +10,6 @@ filegroup( genrule( name = "gen-data", - cmd = "echo hi > $@", outs = ["gen-data.out"], + cmd = "echo hi > $@", ) From dc2842c64ad915e62d9c5413665fb150243b24b8 Mon Sep 17 00:00:00 2001 From: James O'Kane Date: Sun, 11 Mar 2018 00:28:29 -0800 Subject: [PATCH 4/9] Disable the SDK update check to match the use of --skip_sdk_update_check for python. --- appengine/java/appengine_runner.sh.template | 1 + 1 file changed, 1 insertion(+) diff --git a/appengine/java/appengine_runner.sh.template b/appengine/java/appengine_runner.sh.template index 4f796f5..787f609 100644 --- a/appengine/java/appengine_runner.sh.template +++ b/appengine/java/appengine_runner.sh.template @@ -78,6 +78,7 @@ ARGS=( "${JVM_FLAGS_CMDLINE[@]}" "-Dappengine.sdk.root=${APP_ENGINE_ROOT}" ${main_class} + "--disable_update_check" "${ARGS[@]}" . ) From d14e825e093a5ac1c64418393a196161aeaeddf1 Mon Sep 17 00:00:00 2001 From: James O'Kane Date: Sun, 11 Mar 2018 14:18:46 -0700 Subject: [PATCH 5/9] Extract inline files from the .bzl files and add a python example to test the python rules. --- WORKSPACE | 4 + appengine/java/BUILD | 6 ++ appengine/java/sdk.BUILD | 29 ++++++ appengine/java_appengine.bzl | 43 ++------ appengine/py/BUILD | 17 +++ appengine/py/appengine_deploy.sh.template | 55 ++++++++++ appengine/py/appengine_runner.sh.template | 25 +++++ appengine/py_appengine.bzl | 120 ++++++++-------------- examples/py/hello_world/BUILD | 12 +++ examples/py/hello_world/app.yaml | 7 ++ examples/py/hello_world/main.py | 26 +++++ 11 files changed, 227 insertions(+), 117 deletions(-) create mode 100644 appengine/java/sdk.BUILD create mode 100644 appengine/py/BUILD create mode 100644 appengine/py/appengine_deploy.sh.template create mode 100644 appengine/py/appengine_runner.sh.template create mode 100644 examples/py/hello_world/BUILD create mode 100644 examples/py/hello_world/app.yaml create mode 100644 examples/py/hello_world/main.py diff --git a/WORKSPACE b/WORKSPACE index 90d72ad..04dc46c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,3 +3,7 @@ workspace(name = "io_bazel_rules_appengine") load("//appengine:java_appengine.bzl", "java_appengine_repositories") java_appengine_repositories() + +load("//appengine:py_appengine.bzl", "py_appengine_repositories") + +py_appengine_repositories() diff --git a/appengine/java/BUILD b/appengine/java/BUILD index dcd229a..223ce5f 100644 --- a/appengine/java/BUILD +++ b/appengine/java/BUILD @@ -9,3 +9,9 @@ filegroup( srcs = ["appengine_deploy.sh.template"], visibility = ["//visibility:public"], ) + +filegroup( + name = "sdk_build_file", + srcs = ["sdk.BUILD"], + visibility = ["//visibility:public"], +) diff --git a/appengine/java/sdk.BUILD b/appengine/java/sdk.BUILD new file mode 100644 index 0000000..1b89dc6 --- /dev/null +++ b/appengine/java/sdk.BUILD @@ -0,0 +1,29 @@ +# BUILD file to use the Java AppEngine SDK with a remote repository. +java_import( + name = "jars", + jars = glob(["lib/**/*.jar"]), + visibility = ["//visibility:public"], +) + +java_import( + name = "user", + jars = glob(["lib/user/*.jar"]), + visibility = ["//visibility:public"], +) + +java_import( + name = "api", + jars = [ + "lib/agent/appengine-agent.jar", + "lib/appengine-tools-api.jar", + "lib/impl/appengine-api.jar", + ], + neverlink = 1, + visibility = ["//visibility:public"], +) + +filegroup( + name = "sdk", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) diff --git a/appengine/java_appengine.bzl b/appengine/java_appengine.bzl index daee39f..8e2a980 100644 --- a/appengine/java_appengine.bzl +++ b/appengine/java_appengine.bzl @@ -184,15 +184,16 @@ def _war_impl(ctxt): "%{data_path}": data_path } - ctxt.template_action( + ctxt.actions.expand_template( output = executable, template = ctxt.file._runner_template, substitutions = substitutions, - executable = True) - ctxt.template_action( + is_executable = True) + ctxt.actions.expand_template( output = ctxt.outputs.deploy_sh, template = ctxt.file._deploy_template, - substitutions = substitutions) + substitutions = substitutions, + is_executable = True) runfiles = ctxt.runfiles(files = [war, executable] + list(transitive_deps) @@ -272,44 +273,12 @@ APPENGINE_VERSION = "1.9.57" APPENGINE_DIR = "appengine-java-sdk-" + APPENGINE_VERSION -APPENGINE_BUILD_FILE = """ -# BUILD file to use the Java AppEngine SDK with a remote repository. -java_import( - name = "jars", - jars = glob(["lib/**/*.jar"]), - visibility = ["//visibility:public"], -) - -java_import( - name = "user", - jars = glob(["lib/user/*.jar"]), - visibility = ["//visibility:public"], -) - -java_import( - name = "api", - jars = [ - "lib/agent/appengine-agent.jar", - "lib/appengine-tools-api.jar", - "lib/impl/appengine-api.jar", - ], - visibility = ["//visibility:public"], - neverlink = 1, -) - -filegroup( - name = "sdk", - srcs = glob(["**"]), - visibility = ["//visibility:public"], -) -""" - def java_appengine_repositories(): native.new_http_archive( name = "com_google_appengine_java", url = "http://central.maven.org/maven2/com/google/appengine/appengine-java-sdk/%s/%s.zip" % (APPENGINE_VERSION, APPENGINE_DIR), sha256 = "63f89be498d1e7462c03fe2b66d7773a9e5dd04ffb71e3b59a5fa74a7b810997", - build_file_content = APPENGINE_BUILD_FILE, + build_file = "appengine/java/sdk.BUILD", strip_prefix = APPENGINE_DIR, ) diff --git a/appengine/py/BUILD b/appengine/py/BUILD new file mode 100644 index 0000000..223ce5f --- /dev/null +++ b/appengine/py/BUILD @@ -0,0 +1,17 @@ +filegroup( + name = "runner_template", + srcs = ["appengine_runner.sh.template"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "deploy_template", + srcs = ["appengine_deploy.sh.template"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "sdk_build_file", + srcs = ["sdk.BUILD"], + visibility = ["//visibility:public"], +) diff --git a/appengine/py/appengine_deploy.sh.template b/appengine/py/appengine_deploy.sh.template new file mode 100644 index 0000000..5cd3ed7 --- /dev/null +++ b/appengine/py/appengine_deploy.sh.template @@ -0,0 +1,55 @@ +#!/bin/bash +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +case "$0" in +/*) self="$0" ;; +*) self="$PWD/$0";; +esac +if [[ -e "$self.runfiles/%{workspace_name}" ]]; then + RUNFILES="$self.runfiles/%{workspace_name}" + cd $RUNFILES +fi + +ROOT=$PWD +tmp_dir=$(mktemp -d ${{TMPDIR:-/tmp}}/war.XXXXXXXX) +cp -R $ROOT $tmp_dir +trap "{{ cd ${{root_path}}; rm -rf $tmp_dir; }}" EXIT +rm -Rf $tmp_dir/%{workspace_name}/external/com_google_appengine_py +if [ -n "${{1-}}" ]; then + has_app_yaml=$(echo ${{@:2}} | grep -E "^([^ ]+ +)*app.yaml") + other_mod_cfgs=$(echo ${{@:2}} | xargs printf "%s\n" | grep -v "^app\.yaml$" | xargs echo) + ret_code=0 + # Secondary modules need to be uploaded first because if any of them are + # referenced in dispatch.yaml, App Engine must have a version of that module + # prior to the app.yaml upload. + if [ -n "$other_mod_cfgs" ]; then + (cd $tmp_dir/%{workspace_name} && $ROOT/%{appcfg} -A "$1" update $other_mod_cfgs) + ret_code=$? + fi + if [ $ret_code -eq 0 ] && [ -n "$has_app_yaml" ] || [ -z "$other_mod_cfgs" ]; then + $ROOT/%{appcfg} -A "$1" update $tmp_dir/%{workspace_name} + ret_code=$? + fi + +else + echo "\033[1;31mERROR:\033[0m Application ID must be provided as first argument + USAGE: bazel run path/to/my/gae_binary_target.deploy -- my-project-id [module.yaml files ...]" + ret_code=-1 +fi + +rm -Rf $tmp_dir +trap - EXIT + +exit $ret_code diff --git a/appengine/py/appengine_runner.sh.template b/appengine/py/appengine_runner.sh.template new file mode 100644 index 0000000..14014f6 --- /dev/null +++ b/appengine/py/appengine_runner.sh.template @@ -0,0 +1,25 @@ +#!/bin/bash +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +case "$0" in +/*) self="$0" ;; +*) self="$PWD/$0";; +esac +if [[ -e "$self.runfiles/%{workspace_name}" ]]; then + RUNFILES="$self.runfiles/%{workspace_name}" + cd $RUNFILES +fi + +%{devappserver} --skip_sdk_update_check 1 app.yaml diff --git a/appengine/py_appengine.bzl b/appengine/py_appengine.bzl index 6c6be20..0b877f2 100644 --- a/appengine/py_appengine.bzl +++ b/appengine/py_appengine.bzl @@ -55,7 +55,7 @@ def _find_locally_or_download_impl(repository_ctx): output=".", sha256="65f2092e671ae80b316ac8f70b14df687f91959cc8926bd4eb4c26b780ea0af5", stripPrefix="google_appengine") - repository_ctx.template("BUILD", Label("//appengine:pysdk.BUILD")) + repository_ctx.template("BUILD", Label("//appengine/py:sdk.BUILD")) _find_locally_or_download = repository_rule( local = False, @@ -63,19 +63,19 @@ _find_locally_or_download = repository_rule( ) def py_appengine_repositories(): - _find_locally_or_download(name = "com_google_appengine_python") + _find_locally_or_download(name = "com_google_appengine_py") def py_appengine_test(name, srcs, deps=[], data=[], libraries={}, size=None): """A variant of py_test that sets up an App Engine environment.""" - extra_deps = ["@com_google_appengine_python//:appengine"] + extra_deps = ["@com_google_appengine_py//:appengine"] for l in libraries: - extra_deps.append("@com_google_appengine_python//:{0}-{1}".format(l, libraries[l])) + extra_deps.append("@com_google_appengine_py//:{0}-{1}".format(l, libraries[l])) native.py_test( - name=name, - deps=deps + extra_deps, - srcs=srcs, - data=data, - size=size, + name = name, + deps = deps + extra_deps, + srcs = srcs, + data = data, + size = size, ) def _py_appengine_binary_base_impl(ctx): @@ -127,73 +127,24 @@ sys.path.extend([d for d in repo_dirs if os.path.isdir(d)]) symlinks=symlinks, ).merge(ctx.attr.binary.data_runfiles).merge(ctx.attr.appcfg.data_runfiles) - ctx.actions.write( - output=ctx.outputs.executable, - content=""" -#!/bin/bash - -case "$0" in -/*) self="$0" ;; -*) self="$PWD/$0";; -esac -if [[ -e "$self.runfiles/{1}" ]]; then - RUNFILES="$self.runfiles/{1}" - cd $RUNFILES -fi - -{0} --skip_sdk_update_check 1 app.yaml -""".format(ctx.attr.devappserver.files_to_run.executable.short_path, ctx.workspace_name), - is_executable=True, - ) + substitutions = { + "%{appcfg}": ctx.attr.appcfg.files_to_run.executable.short_path, + "%{devappserver}": + ctx.attr.devappserver.files_to_run.executable.short_path, + "%{workspace_name}": ctx.workspace_name, + } - ctx.actions.write( - output=ctx.outputs.deploy_sh, - content=""" -#!/bin/bash - -case "$0" in -/*) self="$0" ;; -*) self="$PWD/$0";; -esac -if [[ -e "$self.runfiles/{1}" ]]; then - RUNFILES="$self.runfiles/{1}" - cd $RUNFILES -fi - -ROOT=$PWD -tmp_dir=$(mktemp -d ${{TMPDIR:-/tmp}}/war.XXXXXXXX) -cp -R $ROOT $tmp_dir -trap "{{ cd ${{root_path}}; rm -rf $tmp_dir; }}" EXIT -rm -Rf $tmp_dir/{1}/external/com_google_appengine_python -if [ -n "${{1-}}" ]; then - has_app_yaml=$(echo ${{@:2}} | grep -E "^([^ ]+ +)*app.yaml") - other_mod_cfgs=$(echo ${{@:2}} | xargs printf "%s\n" | grep -v "^app\.yaml$" | xargs echo) - ret_code=0 - # Secondary modules need to be uploaded first because if any of them are - # referenced in dispatch.yaml, App Engine must have a version of that module - # prior to the app.yaml upload. - if [ -n "$other_mod_cfgs" ]; then - (cd $tmp_dir/{1} && $ROOT/{0} -A "$1" update $other_mod_cfgs) - ret_code=$? - fi - if [ $ret_code -eq 0 ] && [ -n "$has_app_yaml" ] || [ -z "$other_mod_cfgs" ]; then - $ROOT/{0} -A "$1" update $tmp_dir/{1} - ret_code=$? - fi - -else - echo "\033[1;31mERROR:\033[0m Application ID must be provided as first argument - USAGE: bazel run path/to/my/gae_binary_target.deploy -- my-project-id [module.yaml files ...]" - ret_code=-1 -fi - -rm -Rf $tmp_dir -trap - EXIT - -exit $ret_code -""".format(ctx.attr.appcfg.files_to_run.executable.short_path, ctx.workspace_name), - is_executable=True, - ) + ctx.actions.expand_template( + output = ctx.outputs.executable, + template = ctx.file._runner_template, + substitutions = substitutions, + is_executable = True) + + ctx.actions.expand_template( + output = ctx.outputs.deploy_sh, + template = ctx.file._deploy_template, + substitutions = substitutions, + is_executable = True) return struct(runfiles=runfiles, py=ctx.attr.binary.py) @@ -201,12 +152,20 @@ py_appengine_binary_base = rule( _py_appengine_binary_base_impl, attrs = { "binary": attr.label(), - "devappserver": attr.label(default = Label("@com_google_appengine_python//:dev_appserver")), - "appcfg": attr.label(default = Label("@com_google_appengine_python//:appcfg")), + "devappserver": attr.label(default = Label("@com_google_appengine_py//:dev_appserver")), + "appcfg": attr.label(default = Label("@com_google_appengine_py//:appcfg")), "configs": attr.label_list(allow_files = FileType([ ".yaml", ".py", ])), + "_deploy_template": attr.label( + default = Label("//appengine/py:deploy_template"), + single_file = True, + ), + "_runner_template": attr.label( + default = Label("//appengine/py:runner_template"), + single_file = True, + ), }, executable = True, outputs = { @@ -222,10 +181,11 @@ def py_appengine_binary(name, srcs, configs, deps=[], data=[]): fail("srcs should not be empty.") # uses py_binary because it generates __init__.py files native.py_binary( - name="_py_appengine_" + name, + name = "_py_appengine_" + name, srcs = srcs, - deps=deps, - main=srcs[0], # no entry point, use arbitrary source file + deps = deps, + data = data, + main = srcs[0], # no entry point, use arbitrary source file ) py_appengine_binary_base( name=name, diff --git a/examples/py/hello_world/BUILD b/examples/py/hello_world/BUILD new file mode 100644 index 0000000..805981f --- /dev/null +++ b/examples/py/hello_world/BUILD @@ -0,0 +1,12 @@ +""" +Example taken from the official App Engine examples: +https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/hello_world +""" + +load("//appengine:py_appengine.bzl", "py_appengine_binary") + +py_appengine_binary( + name = "main", + srcs = ["main.py"], + configs = ["app.yaml"], +) diff --git a/examples/py/hello_world/app.yaml b/examples/py/hello_world/app.yaml new file mode 100644 index 0000000..f041d38 --- /dev/null +++ b/examples/py/hello_world/app.yaml @@ -0,0 +1,7 @@ +runtime: python27 +api_version: 1 +threadsafe: true + +handlers: +- url: /.* + script: main.app diff --git a/examples/py/hello_world/main.py b/examples/py/hello_world/main.py new file mode 100644 index 0000000..c26ad7a --- /dev/null +++ b/examples/py/hello_world/main.py @@ -0,0 +1,26 @@ +# Copyright 2016 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import webapp2 + + +class MainPage(webapp2.RequestHandler): + def get(self): + self.response.headers['Content-Type'] = 'text/plain' + self.response.write('Hello, World!') + + +app = webapp2.WSGIApplication([ + ('/', MainPage), +], debug=True) From b172debfa4ed5ee583c174c8668f05f6307a3d86 Mon Sep 17 00:00:00 2001 From: James O'Kane Date: Sun, 11 Mar 2018 14:57:40 -0700 Subject: [PATCH 6/9] Extract find_local_or_download into another bzl file and have {java,py}_appengine.bzl use it. --- appengine/java_appengine.bzl | 23 ++++++------ appengine/py_appengine.bzl | 34 +++++++----------- appengine/sdk.bzl | 70 ++++++++++++++++++++++++++++++++++++ appengine/variables.bzl | 15 ++++++++ 4 files changed, 110 insertions(+), 32 deletions(-) create mode 100644 appengine/sdk.bzl create mode 100644 appengine/variables.bzl diff --git a/appengine/java_appengine.bzl b/appengine/java_appengine.bzl index 8e2a980..d749c16 100644 --- a/appengine/java_appengine.bzl +++ b/appengine/java_appengine.bzl @@ -69,6 +69,9 @@ APP_ID. If not specified, it uses the default APP_ID provided in the application web.xml. """ +load(":variables.bzl", "JAVA_SDK_VERSION", "JAVA_SDK_SHA256") +load(":sdk.bzl", "find_locally_or_download") + jar_filetype = FileType([".jar"]) def _add_file(in_file, output, path = None): @@ -269,17 +272,15 @@ def appengine_war(name, jars, data, data_path, testonly = 0): testonly = testonly, ) -APPENGINE_VERSION = "1.9.57" - -APPENGINE_DIR = "appengine-java-sdk-" + APPENGINE_VERSION - -def java_appengine_repositories(): - native.new_http_archive( - name = "com_google_appengine_java", - url = "http://central.maven.org/maven2/com/google/appengine/appengine-java-sdk/%s/%s.zip" % (APPENGINE_VERSION, APPENGINE_DIR), - sha256 = "63f89be498d1e7462c03fe2b66d7773a9e5dd04ffb71e3b59a5fa74a7b810997", - build_file = "appengine/java/sdk.BUILD", - strip_prefix = APPENGINE_DIR, +def java_appengine_repositories(version=JAVA_SDK_VERSION, + sha256=JAVA_SDK_SHA256): + find_locally_or_download( + name = "com_google_appengine_java", + lang = "java", + sha256 = sha256, + version = version, + filename_pattern = "appengine-java-sdk-{version}.zip", + strip_prefix_pattern = "appengine-java-sdk-{version}", ) native.maven_jar( diff --git a/appengine/py_appengine.bzl b/appengine/py_appengine.bzl index 0b877f2..04c1a1c 100644 --- a/appengine/py_appengine.bzl +++ b/appengine/py_appengine.bzl @@ -43,27 +43,19 @@ project ID as the first argument and takes 0 or more module YAML files. If no YAML files are specified, only "app.yaml", the main module, will be deployed. """ -def _find_locally_or_download_impl(repository_ctx): - if 'PY_APPENGINE_SDK_PATH' in repository_ctx.os.environ: - path = repository_ctx.os.environ['PY_APPENGINE_SDK_PATH'] - if path == "": - fail("PY_APPENGINE_SDK_PATH set, but empty") - repository_ctx.symlink(path, ".") - else: - repository_ctx.download_and_extract( - url="https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.61.zip", - output=".", - sha256="65f2092e671ae80b316ac8f70b14df687f91959cc8926bd4eb4c26b780ea0af5", - stripPrefix="google_appengine") - repository_ctx.template("BUILD", Label("//appengine/py:sdk.BUILD")) - -_find_locally_or_download = repository_rule( - local = False, - implementation = _find_locally_or_download_impl, -) - -def py_appengine_repositories(): - _find_locally_or_download(name = "com_google_appengine_py") +load(":variables.bzl", "PY_SDK_VERSION", "PY_SDK_SHA256") +load(":sdk.bzl", "find_locally_or_download") + +def py_appengine_repositories(version=PY_SDK_VERSION, + sha256=PY_SDK_SHA256): + find_locally_or_download( + name = "com_google_appengine_py", + lang = 'py', + sha256 = sha256, + version = version, + filename_pattern = "google_appengine_{version}.zip", + strip_prefix_pattern = "google_appengine", + ) def py_appengine_test(name, srcs, deps=[], data=[], libraries={}, size=None): """A variant of py_test that sets up an App Engine environment.""" diff --git a/appengine/sdk.bzl b/appengine/sdk.bzl new file mode 100644 index 0000000..08d2aa9 --- /dev/null +++ b/appengine/sdk.bzl @@ -0,0 +1,70 @@ +# Copyright 2018 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Language agnostic utility functions for use in the other .bzl files. +""" + +load(":variables.bzl", "SDK_URL_PREFIX") + +def _find_locally_or_download_impl(repository_ctx): + lang = repository_ctx.attr.lang + env_var = lang.upper() + "_APPENGINE_SDK_PATH" + if env_var in repository_ctx.os.environ: + path = repository_ctx.os.environ[env_var] + if path == "": + fail(env_var + " set, but empty") + repository_ctx.symlink(path, ".") + else: + substitutions = { + 'version': repository_ctx.attr.version, + } + repository_ctx.download_and_extract( + url="{}/{}".format( + SDK_URL_PREFIX, + repository_ctx.attr.filename_pattern.format(**substitutions)), + output=".", + sha256=repository_ctx.attr.sha256, + stripPrefix=repository_ctx.attr.strip_prefix_pattern.format( + **substitutions)) + repository_ctx.template( + "BUILD", Label("//appengine:{}/sdk.BUILD".format(lang.lower()))) + +find_locally_or_download = repository_rule( + attrs = { + "lang": attr.string( + mandatory = True, + doc = "The language of the SDK to download.", + values = ["java", "py"], + ), + "sha256": attr.string( + mandatory = True, + doc = "The sha256sum of the sdk zip file.", + ), + "version": attr.string( + mandatory = True, + doc = "The SDK version to download. Usually of the form 1.9.57.", + ), + "strip_prefix_pattern": attr.string( + default = "google_appengine", + mandatory = True, + doc = "When the zip file is extracted, remove this prefix from all paths. If it includes '{version}', it will be replaced with the version.", + ), + "filename_pattern": attr.string( + default = "google_appengine_{version}.zip", + mandatory = True, + doc = "The filename of the SDK zip file to download. If it includes '{version}', it will be replaced with the version.", + ), + }, + local = False, + implementation = _find_locally_or_download_impl, +) diff --git a/appengine/variables.bzl b/appengine/variables.bzl new file mode 100644 index 0000000..bee09e7 --- /dev/null +++ b/appengine/variables.bzl @@ -0,0 +1,15 @@ +"""This file is a central location for configuring new SDK versions. +""" +# Not all languages are released for every SDK version. Whenever possible, set +# ${LANG}_SDK_VERSION = APPENGINE_VERSION. +APPENGINE_VERSION = "1.9.57" + +SDK_URL_PREFIX = "https://storage.googleapis.com/appengine-sdks/featured" + +JAVA_SDK_SHA256 = "63f89be498d1e7462c03fe2b66d7773a9e5dd04ffb71e3b59a5fa74a7b810997" + +JAVA_SDK_VERSION = APPENGINE_VERSION + +PY_SDK_SHA256 = "d5c4fad8afa2ce9005481575c01558248a0fbe0b4554c6de060e925899cfbf66" + +PY_SDK_VERSION = APPENGINE_VERSION From c91d8ba752ed144d3a33e2ab0f7107bb6cf109c8 Mon Sep 17 00:00:00 2001 From: James O'Kane Date: Sun, 11 Mar 2018 15:05:09 -0700 Subject: [PATCH 7/9] Add hooks in appengine.bzl for backward compatibility --- appengine/appengine.bzl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 appengine/appengine.bzl diff --git a/appengine/appengine.bzl b/appengine/appengine.bzl new file mode 100644 index 0000000..dd35d9f --- /dev/null +++ b/appengine/appengine.bzl @@ -0,0 +1,35 @@ +# Copyright 2015 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +Use of this file is deprecated. Use the functions in java_appengine.bzl directly. +""" + +load( + ":java_appengine.bzl", + _appengine_war = "appengine_war", + _appengine_war_base = "appengine_war_base", + _jar_filetype = "jar_filetype", + _java_appengine_repositories = "java_appengine_repositories", + _java_war = "java_war", +) + +appengine_war = _appengine_war + +appengine_war_base = _appengine_war_base + +jar_filetype = _jar_filetype + +java_appengine_repositories = _java_appengine_repositories + +java_war = _java_war From 1c62bf041ff97a3606983c6121296df929c3dc96 Mon Sep 17 00:00:00 2001 From: James O'Kane Date: Sun, 11 Mar 2018 15:07:40 -0700 Subject: [PATCH 8/9] Update documentation for the restructured bzl files. --- CONTRIBUTORS | 1 + README.md | 97 +++++++++++++++++++++++++++++----------------------- 2 files changed, 56 insertions(+), 42 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 1d8a5fa..8579f85 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -13,5 +13,6 @@ Alex Humesky Damien Martin-Guillerez David Chen Erik Kuefler +James O'Kane Kristina Chodorow Lukacs Berki diff --git a/README.md b/README.md index 3f2a1f1..dc9c4a5 100644 --- a/README.md +++ b/README.md @@ -24,36 +24,71 @@ support but can be easily modified to handle a standard web application. ## Setup -To be able to use the Java App Engine rules, you must make the App Engine SDK -available to Bazel. The easiest way to do so is by adding the following to your +To be able to use the rules, you must make the App Engine SDK available to +Bazel. The easiest way to do so is by adding the following to your `WORKSPACE` file: +Note: The `${LANG}_appengine_repository()` lines are only needed for the languages you plan to use. + ```python git_repository( name = "io_bazel_rules_appengine", remote = "https://github.com/bazelbuild/rules_appengine.git", # Check https://github.com/bazelbuild/rules_appengine/releases for the latest version. - tag = "0.0.4", + tag = "0.0.7", ) # Java -load("@io_bazel_rules_appengine//appengine:appengine.bzl", "appengine_repositories") -appengine_repositories() +load( + "@io_bazel_rules_appengine//appengine:java_appengine.bzl", + "java_appengine_repositories", +) + +java_appengine_repositories() + # Python -load("@io_bazel_rules_appengine//appengine:py_appengine.bzl", "py_appengine_repositories") +load( + "@io_bazel_rules_appengine//appengine:py_appengine.bzl", + "py_appengine_repositories", +) + py_appengine_repositories() ``` -The AppEngine rules download the AppEngine SDK, which is a few hundred megabytes -in size. To avoid downloading this multiple times for multiple projects or -inadvertently re-downloading it, you might want to add the following line to -your `$HOME/.bazelrc` file: +The App Engine rules download the App Engine SDK, which is a few hundred +megabytes in size. To avoid downloading this multiple times for multiple +projects or inadvertently re-downloading it, you might want to add the +following lines to your `$HOME/.bazelrc` file: ``` build --experimental_repository_cache=/home/user/.bazel/cache +fetch --experimental_repository_cache=/home/user/.bazel/cache +``` + +### Requesting a specific App Engine SDK + +All ${LANG}_appengine_repository macros accept optional arguments `version` +and `sha256`. + +```python +py_appengine_repositories( + version = '1.9.67', + sha256 = 'f9f45150643424cb164185d9134b86511c2bec3001499247ef9027f1605ef8a3', +) +``` + +### Using a predownloaded SDK version + +You can, optionally, specify the environment variable +`${LANG}_APPENGINE_SDK_PATH` to use an SDK that is unzipped on your filesystem +(instead of downloading a new one). + +``` +PY_APPENGINE_SDK_PATH=/path/to/google_appengine bazel build //whatever +JAVA_APPENGINE_SDK_PATH=/path/to/appengine-java-sdk-1.9.50 bazel build //whatever ``` -## Basic Example +## Basic Java Example Suppose you have the following directory structure for a simple App Engine application: @@ -77,7 +112,7 @@ application: Then, to build your webapp, your `hello_app/BUILD` can look like: ```python -load("@io_bazel_rules_appengine//appengine:appengine.bzl", "appengine_war") +load("@io_bazel_rules_appengine//appengine:java_appengine.bzl", "appengine_war") java_library( name = "mylib", @@ -100,7 +135,7 @@ For simplicity, you can use the `java_war` rule to build an app from source. Your `hello_app/BUILD` file would then look like: ```python -load("@io_bazel_rules_appengine//appengine:appengine.bzl", "java_war") +load("@io_bazel_rules_appengine//appengine:java_appengine.bzl", "java_war") java_war( name = "myapp", @@ -135,7 +170,7 @@ Another target `//hello_app:myapp.deploy` allows you to deploy your application to App Engine. It takes an optional argument: the `APP_ID`. If not specified, it uses the default `APP_ID` provided in the application. This target needs to open a browser to authenticate -with AppEngine, then have you copy-paste a "key" from the browser in +with App Engine, then have you copy-paste a "key" from the browser in the terminal. Since Bazel closes standard input, you can only input this by building the target and then running: @@ -148,14 +183,16 @@ App Engine so you can just do a normal `bazel run //hello_app:myapp.deploy -- APP_ID` to deploy next versions of your application. -*Note:* AppEngine uses Java 7. If you are using a more recent version of Java, +## Java specific details + +*Note:* App Engine uses Java 7. If you are using a more recent version of Java, you will get the following error message when you try to deploy: ``` java.lang.IllegalArgumentException: Class file is Java 8 but max supported is Java 7 ``` -To build with Java 7, use the toolchain bundled with these AppEngine rules: +To build with Java 7, use the toolchain bundled with these App Engine rules: ``` $ bazel build --java_toolchain=@io_bazel_rules_appengine//appengine:jdk7 //my-project @@ -292,6 +329,8 @@ java_war(name, data, data_path, **kwargs) +## Python specific details + ## py_appengine_binary ```python @@ -399,29 +438,3 @@ py_appengine_test(name, srcs, deps=[], data=[], libraries={}) - -## Using a local AppEngine SDK - -### Java - -If you already have a local copy of the AppEngine SDK, you can specify the path to -that in your WORKSPACE file (instead of Bazel downloading another copy): - -``` -load('@io_bazel_rules_appengine//appengine:appengine.bzl', 'APPENGINE_BUILD_FILE') -new_local_repository( - name = 'com_google_appengine_java', - path = '/path/to/appengine-java-sdk-version', - build_file_content = APPENGINE_BUILD_FILE, -) -``` - - -### Python - -You can, optionally, specify the environment variable PY_APPENGINE_SDK_PATH to use -an SDK that is on your filesystem (instead of downloading a new one). - -``` -PY_APPENGINE_SDK_PATH=/path/to/appengine-python-sdk-1.9.50 bazel build //whatever -``` From 1a30c050a939831ce6dfd2af79874220b5fe3d17 Mon Sep 17 00:00:00 2001 From: James O'Kane Date: Tue, 20 Mar 2018 10:29:05 -0700 Subject: [PATCH 9/9] Group loads together at the beginning of the file. --- WORKSPACE | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 04dc46c..69ffad7 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,9 +1,8 @@ workspace(name = "io_bazel_rules_appengine") load("//appengine:java_appengine.bzl", "java_appengine_repositories") +load("//appengine:py_appengine.bzl", "py_appengine_repositories") java_appengine_repositories() -load("//appengine:py_appengine.bzl", "py_appengine_repositories") - py_appengine_repositories()