diff options
author | 2017-08-01 17:44:35 -0700 | |
---|---|---|
committer | 2017-08-01 18:00:48 -0700 | |
commit | 4a4b6f7b3e43a176e26ac586340f6af798df5447 (patch) | |
tree | 2006abf19b28290eb187bb230221670dd2194c33 /tensorflow/java/maven | |
parent | 40b2946a57945a4be15feaf25b89db6b52b33806 (diff) |
Merged commit includes the following changes:
163914294 by annarev:
Refactors build target for gradients_impl to allow code to depend on the gradient generation but not the gradients themselves.
--
163913011 by A. Unique TensorFlower:
Use an LLVM-IR version of vector hyperbolic tangent.
This lets us:
- Inline routine where it is called, eliminated call overhead.
- Use AVX instructions in JITed code even if Tensorflow was not built with -mavx.
--
163909534 by A. Unique TensorFlower:
Add tensorflow-android to standard TF maven artifacts.
--
163908704 by A. Unique TensorFlower:
Go: Update generated wrapper functions for TensorFlow ops.
--
163907709 by A. Unique TensorFlower:
Update ops-related pbtxt files.
--
163907497 by A. Unique TensorFlower:
Remove old TensorFlow Serving landing page in prepartion for new TF
Serving landing page. Fix bad leftnav.
--
163906225 by alive:
Refactors build target for gradients_impl to allow code to depend on the gradient generation but not the gradients themselves.
--
PiperOrigin-RevId: 163914294
Diffstat (limited to 'tensorflow/java/maven')
-rw-r--r-- | tensorflow/java/maven/run_inside_container.sh | 45 | ||||
-rw-r--r-- | tensorflow/java/maven/tensorflow-android/pom-android.xml.template | 29 | ||||
-rw-r--r-- | tensorflow/java/maven/tensorflow-android/update.py | 139 |
3 files changed, 206 insertions, 7 deletions
diff --git a/tensorflow/java/maven/run_inside_container.sh b/tensorflow/java/maven/run_inside_container.sh index 302ed96c12..6b4d5d7032 100644 --- a/tensorflow/java/maven/run_inside_container.sh +++ b/tensorflow/java/maven/run_inside_container.sh @@ -32,7 +32,7 @@ clean() { # (though if run inside a clean docker container, there won't be any dirty # artifacts lying around) mvn -q clean - rm -rf libtensorflow_jni/src libtensorflow_jni/target libtensorflow/src libtensorflow/target + rm -rf libtensorflow_jni/src libtensorflow_jni/target libtensorflow/src libtensorflow/target tensorflow-android/target } update_version_in_pom() { @@ -52,6 +52,17 @@ download_libtensorflow() { cd "${DIR}" } +# Fetch the android aar artifact from the CI build system, and update +# its associated pom file. +update_tensorflow_android() { + TARGET_DIR="${DIR}/tensorflow-android/target" + mkdir -p "${TARGET_DIR}" + python "${DIR}/tensorflow-android/update.py" \ + --version "${TF_VERSION}" \ + --template "${DIR}/tensorflow-android/pom-android.xml.template" \ + --dir "${TARGET_DIR}" +} + download_libtensorflow_jni() { NATIVE_DIR="${DIR}/libtensorflow_jni/src/main/resources/org/tensorflow/native" mkdir -p "${NATIVE_DIR}" @@ -126,6 +137,29 @@ generate_java_protos() { rm -rf "${DIR}/proto/tmp" } +# If successfully built, try to deploy. +# If successfully deployed, clean. +# If deployment fails, debug with +# ./release.sh ${TF_VERSION} ${SETTINGS_XML} bash +# To get a shell to poke around the maven artifacts with. +deploy_artifacts() { + # This deploys the non-android pieces + mvn deploy + + # Sign and deploy the previously downloaded aar file as a single + # maven artifact. + if [[ "${IS_SNAPSHOT}" == "true" ]]; then + REPO="https://oss.sonatype.org/content/repositories/snapshots" + else + REPO="https://oss.sonatype.org/service/local/staging/deploy/maven2/" + fi + mvn gpg:sign-and-deploy-file -Dfile="${DIR}/tensorflow-android/target/tensorflow.aar" -DpomFile="${DIR}/tensorflow-android/target/pom-android.xml" -Durl=${REPO} -DrepositoryId=ossrh + + # Clean up when everything works + clean +} + + if [ -z "${TF_VERSION}" ] then echo "Must set the TF_VERSION environment variable" @@ -144,15 +178,12 @@ clean update_version_in_pom download_libtensorflow download_libtensorflow_jni +update_tensorflow_android generate_java_protos # Build the release artifacts mvn verify -# If successfully built, try to deploy. -# If successfully deployed, clean. -# If deployment fails, debug with -# ./release.sh ${TF_VERSION} ${SETTINGS_XML} bash -# To get a shell to poke around the maven artifacts with. -mvn deploy && clean +# Push artifacts to repository +deploy_artifacts set +ex if [[ "${IS_SNAPSHOT}" == "false" ]]; then diff --git a/tensorflow/java/maven/tensorflow-android/pom-android.xml.template b/tensorflow/java/maven/tensorflow-android/pom-android.xml.template new file mode 100644 index 0000000000..5cbd0c898d --- /dev/null +++ b/tensorflow/java/maven/tensorflow-android/pom-android.xml.template @@ -0,0 +1,29 @@ +<project + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.tensorflow</groupId> + <artifactId>tensorflow-android</artifactId> + <version>${version}</version> + <packaging>aar</packaging> + + <name>TensorFlow AAR for Android Inference Library and Java API</name> + <url>https://github.com/tensorflow/tensorflow/</url> + <parent> + <groupId>org.tensorflow</groupId> + <artifactId>parentpom</artifactId> + <version>${version}</version> + <relativePath>../</relativePath> + </parent> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.build.number>${build_number}</project.build.number> + <project.build.commitid>${build_commit_id}</project.build.commitid> + <project.build.type>${build_type}</project.build.type> + <project.build.url>${build_url}</project.build.url> + </properties> + +</project> diff --git a/tensorflow/java/maven/tensorflow-android/update.py b/tensorflow/java/maven/tensorflow-android/update.py new file mode 100644 index 0000000000..bd97a08948 --- /dev/null +++ b/tensorflow/java/maven/tensorflow-android/update.py @@ -0,0 +1,139 @@ +# Copyright 2017 The TensorFlow 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. +"""Fetch android artifacts and update pom properties.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import argparse +import json +import string +import sys +import urllib2 + + +def get_args(): + """Parse command line args.""" + parser = argparse.ArgumentParser() + parser.add_argument( + '--version', required=True, help='Version for the artifact.') + parser.add_argument( + '--dir', + required=True, + help='Directory where the pom and aar artifact will be written.') + parser.add_argument( + '--template', required=True, help='Path to pom template file.') + return parser.parse_args() + + +def get_json(url): + """Load the contents of the URL as a json object.""" + return json.load(urllib2.urlopen(url)) + + +def get_commit_id(build_info): + """Fetch the git commit id from the build info json object.""" + actions = build_info.get('actions') + build_data = next( + a for a in actions + if a.get('_class') == 'hudson.plugins.git.util.BuildData') + if not build_data: + raise ValueError('Missing BuildData: %s' % build_info) + revision_info = build_data.get('lastBuiltRevision') + if not revision_info: + raise ValueError('Missing lastBuiltRevision: %s' % build_info) + return revision_info.get('SHA1') + + +def get_aar_url(build_info): + """Given the json build info, find the URL to the tensorflow.aar artifact.""" + base_url = build_info.get('url') + if not base_url: + raise ValueError('Missing url: %s' % build_info) + build_class = build_info.get('_class') + if (build_class == 'hudson.model.FreeStyleBuild' or + build_class == 'hudson.matrix.MatrixRun'): + aar_info = next( + a for a in build_info.get('artifacts') + if a.get('fileName') == 'tensorflow.aar') + if not aar_info: + raise ValueError('Missing aar artifact: %s' % build_info) + return '%s/artifact/%s' % (base_url, aar_info.get('relativePath')) + + raise ValueError('Unknown build_type %s' % build_info) + + +def read_template(path): + with open(path) as f: + return string.Template(f.read()) + + +def main(): + args = get_args() + + # Artifacts are downloaded from the ci build. A SNAPSHOT release is + # associated with artifacts from the last successful nightly build. Otherwise, + # it comes from the officially blessed release artifacts. + if args.version.endswith('SNAPSHOT'): + info_url = ('https://ci.tensorflow.org/view/Nightly/job/nightly-android' + '/lastSuccessfulBuild/api/json') + aar_url = None + build_type = 'nightly-android' + else: + release_prefix = 'https://storage.googleapis.com/tensorflow/libtensorflow' + info_url = '/%s/android_buildinfo-%s.json' % (release_prefix, args.version) + aar_url = '/%s/tensorflow-%s.aar' % (release_prefix, args.version) + build_type = 'release-matrix-android' + + # Retrieve build information + build_info = get_json(info_url) + + # Check all required build info is present + if build_info.get('result') != 'SUCCESS': + raise ValueError('Invalid json: %s' % build_info) + build_url = build_info.get('url') + if not build_url: + raise ValueError('Missing url: %s' % build_info) + build_number = build_info.get('number') + if not build_number: + raise ValueError('Missing build number: %s' % build_info) + build_commit_id = get_commit_id(build_info) + if not build_commit_id: + raise ValueError('Missing commit id: %s' % build_info) + + # Write the pom file updated with build attributes. + template = read_template(args.template) + with open('%s/pom-android.xml' % args.dir, 'w') as f: + f.write( + template.substitute({ + 'build_commit_id': build_commit_id, + 'build_number': build_number, + 'build_type': build_type, + 'build_url': build_url, + 'version': args.version + })) + + # Retrieve the aar location if needed. + if not aar_url: + aar_url = get_aar_url(build_info) + + # And download the aar to the desired location. + with open('%s/tensorflow.aar' % args.dir, 'w') as f: + aar = urllib2.urlopen(aar_url) + f.write(aar.read()) + + +if __name__ == '__main__': + sys.exit(main()) |