Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Make the java and python setup more consistent (#71)
Browse files Browse the repository at this point in the history
* Move/rename files to make java files prefixed with java to allow naming
consistency with python files.

* Update pathnames within files to match the file moves.

* Run buildifier on WORKSPACE, BUILD, and *.bzl files.

* Disable the SDK update check to match the use of --skip_sdk_update_check for
python.

* Extract inline files from the .bzl files and add a python example to test
the python rules.

* Extract find_local_or_download into another bzl file and have
{java,py}_appengine.bzl use it.

* Add hooks in appengine.bzl for backward compatibility

* Update documentation for the restructured bzl files.

* Group loads together at the beginning of the file.
  • Loading branch information
jo2y authored and pmbethe09 committed Mar 21, 2018
1 parent af4e06b commit d25d495
Show file tree
Hide file tree
Showing 34 changed files with 719 additions and 484 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Alex Humesky <[email protected]>
Damien Martin-Guillerez <[email protected]>
David Chen <[email protected]>
Erik Kuefler <[email protected]>
James O'Kane <[email protected]>
Kristina Chodorow <[email protected]>
Lukacs Berki <[email protected]>
97 changes: 55 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,71 @@ support but can be easily modified to handle a standard web application.
<a name="setup"></a>
## 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
```

<a name="basic-example"></a>
## Basic Example
## Basic Java Example

Suppose you have the following directory structure for a simple App Engine
application:
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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:

Expand All @@ -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
Expand Down Expand Up @@ -292,6 +329,8 @@ java_war(name, data, data_path, **kwargs)
</tbody>
</table>

## Python specific details

<a name="py_appengine_binary"></a>
## py_appengine_binary
```python
Expand Down Expand Up @@ -399,29 +438,3 @@ py_appengine_test(name, srcs, deps=[], data=[], libraries={})
</tr>
</tbody>
</table>

## 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
```
8 changes: 6 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
workspace(name = "io_bazel_rules_appengine")

load("//appengine:appengine.bzl", "appengine_repositories")
appengine_repositories()
load("//appengine:java_appengine.bzl", "java_appengine_repositories")
load("//appengine:py_appengine.bzl", "py_appengine_repositories")

java_appengine_repositories()

py_appengine_repositories()
14 changes: 1 addition & 13 deletions appengine/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@ java_library(
name = "javax.servlet.api",
neverlink = 1,
visibility = ["//visibility:public"],
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"],
exports = ["@javax_servlet_api//jar"],
)

filegroup(
Expand Down
Loading

0 comments on commit d25d495

Please sign in to comment.