Script for publishing WebRTC AAR on Bintray.
Bintray is a service for hosting repositories. It is widely used to serve precompiled Android binaries because of the integration with JCenter. This script uploads a precompiled WebRTC Android library to a Bintray repository. Bug: webrtc:8182 Change-Id: I7be04cea59827e28470acd934f6e09fc3abe2a72 Reviewed-on: https://webrtc-review.googlesource.com/4441 Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Patrik Höglund <phoglund@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20168}
This commit is contained in:
parent
e2d6a06fa8
commit
dbb15a7ce2
0
tools_webrtc/android/__init__.py
Normal file
0
tools_webrtc/android/__init__.py
Normal file
@ -171,26 +171,33 @@ def GenerateLicenses(output_dir, build_dir, archs):
|
||||
builder.GenerateLicenseText(output_dir)
|
||||
|
||||
|
||||
def BuildAar(archs, output_file, use_goma=False, extra_gn_args=None,
|
||||
ext_build_dir=None):
|
||||
extra_gn_args = extra_gn_args or []
|
||||
build_dir = ext_build_dir if ext_build_dir else tempfile.mkdtemp()
|
||||
|
||||
for arch in archs:
|
||||
Build(build_dir, arch, use_goma, extra_gn_args)
|
||||
|
||||
with zipfile.ZipFile(output_file, 'w') as aar_file:
|
||||
# Architecture doesn't matter here, arbitrarily using the first one.
|
||||
CollectCommon(aar_file, build_dir, archs[0])
|
||||
for arch in archs:
|
||||
Collect(aar_file, build_dir, arch)
|
||||
|
||||
license_dir = os.path.dirname(os.path.realpath(output_file))
|
||||
GenerateLicenses(license_dir, build_dir, archs)
|
||||
|
||||
if not ext_build_dir:
|
||||
shutil.rmtree(build_dir, True)
|
||||
|
||||
|
||||
def main():
|
||||
args = _ParseArgs()
|
||||
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
|
||||
|
||||
build_dir = args.build_dir if args.build_dir else tempfile.mkdtemp()
|
||||
|
||||
for arch in args.arch:
|
||||
Build(build_dir, arch, args.use_goma, args.extra_gn_args)
|
||||
|
||||
with zipfile.ZipFile(args.output, 'w') as aar_file:
|
||||
# Architecture doesn't matter here, arbitrarily using the first one.
|
||||
CollectCommon(aar_file, build_dir, args.arch[0])
|
||||
for arch in args.arch:
|
||||
Collect(aar_file, build_dir, arch)
|
||||
|
||||
license_dir = os.path.dirname(os.path.realpath(args.output))
|
||||
GenerateLicenses(license_dir, build_dir, args.arch)
|
||||
|
||||
if not args.build_dir:
|
||||
shutil.rmtree(build_dir, True)
|
||||
BuildAar(args.arch, args.output, args.use_goma, args.extra_gn_args,
|
||||
args.build_dir)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
160
tools_webrtc/android/release_aar.py
Normal file
160
tools_webrtc/android/release_aar.py
Normal file
@ -0,0 +1,160 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
||||
#
|
||||
# Use of this source code is governed by a BSD-style license
|
||||
# that can be found in the LICENSE file in the root of the source
|
||||
# tree. An additional intellectual property rights grant can be found
|
||||
# in the file PATENTS. All contributing project authors may
|
||||
# be found in the AUTHORS file in the root of the source tree.
|
||||
|
||||
"""Script for publishing WebRTC AAR on Bintray.
|
||||
|
||||
Set BINTRAY_USER and BINTRAY_API_KEY environment variables before running
|
||||
this script for authentication.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
|
||||
SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
|
||||
CHECKOUT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir))
|
||||
|
||||
sys.path.append(os.path.join(CHECKOUT_ROOT, 'third_party'))
|
||||
import requests
|
||||
import jinja2
|
||||
|
||||
sys.path.append(os.path.join(CHECKOUT_ROOT, 'tools_webrtc'))
|
||||
from android.build_aar import BuildAar
|
||||
|
||||
|
||||
ARCHS = ['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64']
|
||||
REPOSITORY_API = 'https://api.bintray.com/content/google/webrtc/google-webrtc'
|
||||
GROUP_ID = 'org/webrtc'
|
||||
ARTIFACT_ID = 'google-webrtc'
|
||||
COMMIT_POSITION_REGEX = r'^Cr-Commit-Position: refs/heads/master@{#(\d+)}$'
|
||||
UPLOAD_TIMEOUT_SECONDS = 10.0
|
||||
UPLOAD_TRIES = 3
|
||||
# The sleep time is increased exponentially.
|
||||
UPLOAD_RETRY_BASE_SLEEP_SECONDS = 2.0
|
||||
|
||||
|
||||
def _ParseArgs():
|
||||
parser = argparse.ArgumentParser(description='Releases WebRTC on Bintray.')
|
||||
parser.add_argument('--use-goma', action='store_true', default=False,
|
||||
help='Use goma.')
|
||||
parser.add_argument('--verbose', action='store_true', default=False,
|
||||
help='Debug logging.')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def _GetCommitHash():
|
||||
commit_hash = subprocess.check_output(
|
||||
['git', 'rev-parse', 'HEAD'], cwd=CHECKOUT_ROOT).strip()
|
||||
return commit_hash
|
||||
|
||||
|
||||
def _GetCommitPos():
|
||||
commit_message = subprocess.check_output(
|
||||
['git', 'rev-list', '--format=%B', '--max-count=1', 'HEAD'],
|
||||
cwd=CHECKOUT_ROOT)
|
||||
commit_pos_match = re.search(
|
||||
COMMIT_POSITION_REGEX, commit_message, re.MULTILINE)
|
||||
if not commit_pos_match:
|
||||
raise Exception('Commit position not found in the commit message: %s'
|
||||
% commit_message)
|
||||
return commit_pos_match.group(1)
|
||||
|
||||
|
||||
def _UploadFile(user, password, filename, version, target_file):
|
||||
# URL is of format:
|
||||
# <repository_api>/<version>/<group_id>/<artifact_id>/<version>/<target_file>
|
||||
# Example:
|
||||
# https://api.bintray.com/content/google/webrtc/google-webrtc/1.0.19742/org/webrtc/google-webrtc/1.0.19742/google-webrtc-1.0.19742.aar
|
||||
|
||||
target_dir = version + '/' + GROUP_ID + '/' + ARTIFACT_ID + '/' + version
|
||||
target_path = target_dir + '/' + target_file
|
||||
url = REPOSITORY_API + '/' + target_path
|
||||
|
||||
logging.info('Uploading %s to %s', filename, url)
|
||||
with open(filename) as fh:
|
||||
file_data = fh.read()
|
||||
|
||||
for attempt in xrange(UPLOAD_TRIES):
|
||||
try:
|
||||
response = requests.put(url, data=file_data, auth=(user, password),
|
||||
timeout=UPLOAD_TIMEOUT_SECONDS)
|
||||
break
|
||||
except requests.exceptions.Timeout as e:
|
||||
logging.warning('Timeout while uploading: %s', e)
|
||||
time.sleep(UPLOAD_RETRY_BASE_SLEEP_SECONDS ** attempt)
|
||||
else:
|
||||
raise Exception('Failed to upload %s' % filename)
|
||||
|
||||
if not response.ok:
|
||||
raise Exception('Failed to upload %s. Response: %s' % (filename, response))
|
||||
logging.info('Uploaded %s: %s', filename, response)
|
||||
|
||||
|
||||
def _GeneratePom(target_file, version, commit):
|
||||
env = jinja2.Environment(
|
||||
loader=jinja2.PackageLoader('release_aar'),
|
||||
)
|
||||
template = env.get_template('pom.jinja')
|
||||
pom = template.render(version=version, commit=commit)
|
||||
with open(target_file, 'w') as fh:
|
||||
fh.write(pom)
|
||||
|
||||
|
||||
def ReleaseAar(use_goma):
|
||||
version = '1.0.' + _GetCommitPos()
|
||||
commit = _GetCommitHash()
|
||||
logging.info('Releasing AAR version %s with hash %s', version, commit)
|
||||
|
||||
user = os.environ.get('BINTRAY_USER', None)
|
||||
api_key = os.environ.get('BINTRAY_API_KEY', None)
|
||||
if not user or not api_key:
|
||||
raise Exception('Environment variables BINTRAY_USER and BINTRAY_API_KEY '
|
||||
'must be defined.')
|
||||
|
||||
tmp_dir = tempfile.mkdtemp()
|
||||
|
||||
try:
|
||||
base_name = ARTIFACT_ID + '-' + version
|
||||
aar_file = os.path.join(tmp_dir, base_name + '.aar')
|
||||
third_party_licenses_file = os.path.join(tmp_dir, 'LICENSE.md')
|
||||
pom_file = os.path.join(tmp_dir, base_name + '.pom')
|
||||
|
||||
logging.info('Building at %s', tmp_dir)
|
||||
BuildAar(ARCHS, aar_file,
|
||||
use_goma=use_goma,
|
||||
ext_build_dir=os.path.join(tmp_dir, 'aar-build'))
|
||||
_GeneratePom(pom_file, version, commit)
|
||||
|
||||
_UploadFile(user, api_key, aar_file, version, base_name + '.aar')
|
||||
_UploadFile(user, api_key, third_party_licenses_file, version,
|
||||
'THIRD_PARTY_LICENSES.md')
|
||||
_UploadFile(user, api_key, pom_file, version, base_name + '.pom')
|
||||
finally:
|
||||
shutil.rmtree(tmp_dir, True)
|
||||
|
||||
logging.info('Library successfully uploaded. Please test and publish it on '
|
||||
'Bintray.')
|
||||
|
||||
|
||||
def main():
|
||||
args = _ParseArgs()
|
||||
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
|
||||
ReleaseAar(args.use_goma)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
18
tools_webrtc/android/templates/pom.jinja
Normal file
18
tools_webrtc/android/templates/pom.jinja
Normal file
@ -0,0 +1,18 @@
|
||||
<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.webrtc</groupId>
|
||||
<artifactId>google-webrtc</artifactId>
|
||||
<version>{{ version }}</version>
|
||||
<packaging>aar</packaging>
|
||||
|
||||
<name>Google's WebRTC Android library</name>
|
||||
<url>https://webrtc.org/</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.build.commitid>{{ commit }}</project.build.commitid>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
Loading…
x
Reference in New Issue
Block a user