Ray Milkey
Committed by Gerrit Code Review

remove unused files from buck-tools

Change-Id: Ia0858a89a47b338c1593a8806b17d291f1897ea3
python_binary(
name = 'download_file',
main = 'download_file.py',
deps = [':util'],
visibility = ['PUBLIC'],
)
python_binary(
name = 'onos-app-writer',
main = 'onos_app.py',
deps = [],
......@@ -33,22 +26,6 @@ python_binary(
visibility = ['PUBLIC'],
)
python_binary(
name = 'pack_war',
main = 'pack_war.py',
deps = [':util'],
visibility = ['PUBLIC'],
)
python_library(
name = 'util',
srcs = [
'util.py',
'__init__.py'
],
visibility = ['PUBLIC'],
)
def shquote(s):
return s.replace("'", "'\\''")
......
This diff is collapsed. Click to expand it.
#!/usr/bin/env python
# Copyright (C) 2013 The Android Open Source Project
#
# 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.
from optparse import OptionParser
import re
from subprocess import check_call, CalledProcessError, Popen, PIPE
MAIN = ['//buck-tools/eclipse:classpath']
PAT = re.compile(r'"(//.*?)" -> "//buck-tools:download_file"')
# TODO(davido): Remove this hack when Buck bugs are fixed:
# https://github.com/facebook/buck/issues/656
# https://github.com/facebook/buck/issues/658
JGIT = re.compile(r'//org.eclipse.jgit.*')
CELL = '//lib/jgit'
opts = OptionParser()
opts.add_option('--src', action='store_true')
args, _ = opts.parse_args()
targets = set()
p = Popen(['buck', 'audit', 'classpath', '--dot'] + MAIN, stdout = PIPE)
for line in p.stdout:
m = PAT.search(line)
if m:
n = m.group(1)
if JGIT.match(n):
n = CELL + n[1:]
if args.src and n.endswith('__download_bin'):
n = n[:-13] + 'src'
targets.add(n)
r = p.wait()
if r != 0:
exit(r)
try:
check_call(['buck', 'build'] + sorted(targets))
except CalledProcessError as err:
exit(1)
#!/usr/bin/env python
# Copyright (C) 2013 The Android Open Source Project
#
# 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.
from __future__ import print_function
from hashlib import sha1
from optparse import OptionParser
from os import link, makedirs, path, remove
import shutil
from subprocess import check_call, CalledProcessError
from sys import stderr
from util import hash_file, resolve_url
from zipfile import ZipFile, BadZipfile, LargeZipFile
GERRIT_HOME = path.expanduser('~/.gerritcodereview')
CACHE_DIR = path.join(GERRIT_HOME, 'buck-cache', 'downloaded-artifacts')
# LEGACY_CACHE_DIR is only used to allow existing workspaces to move already
# downloaded files to the new cache directory.
# Please remove after 3 months (2015-10-07).
LEGACY_CACHE_DIR = path.join(GERRIT_HOME, 'buck-cache')
LOCAL_PROPERTIES = 'local.properties'
def safe_mkdirs(d):
if path.isdir(d):
return
try:
makedirs(d)
except OSError as err:
if not path.isdir(d):
raise err
def download_properties(root_dir):
""" Get the download properties.
First tries to find the properties file in the given root directory,
and if not found there, tries in the Gerrit settings folder in the
user's home directory.
Returns a set of download properties, which may be empty.
"""
p = {}
local_prop = path.join(root_dir, LOCAL_PROPERTIES)
if not path.isfile(local_prop):
local_prop = path.join(GERRIT_HOME, LOCAL_PROPERTIES)
if path.isfile(local_prop):
try:
with open(local_prop) as fd:
for line in fd:
if line.startswith('download.'):
d = [e.strip() for e in line.split('=', 1)]
name, url = d[0], d[1]
p[name[len('download.'):]] = url
except OSError:
pass
return p
def cache_entry(args):
if args.v:
h = args.v
else:
h = sha1(args.u.encode('utf-8')).hexdigest()
name = '%s-%s' % (path.basename(args.o), h)
return path.join(CACHE_DIR, name)
# Please remove after 3 months (2015-10-07). See LEGACY_CACHE_DIR above.
def legacy_cache_entry(args):
if args.v:
h = args.v
else:
h = sha1(args.u.encode('utf-8')).hexdigest()
name = '%s-%s' % (path.basename(args.o), h)
return path.join(LEGACY_CACHE_DIR, name)
opts = OptionParser()
opts.add_option('-o', help='local output file')
opts.add_option('-u', help='URL to download')
opts.add_option('-v', help='expected content SHA-1')
opts.add_option('-x', action='append', help='file to delete from ZIP')
opts.add_option('--exclude_java_sources', action='store_true')
opts.add_option('--unsign', action='store_true')
args, _ = opts.parse_args()
root_dir = args.o
while root_dir:
root_dir, n = path.split(root_dir)
if n == 'buck-out':
break
redirects = download_properties(root_dir)
cache_ent = cache_entry(args)
legacy_cache_ent = legacy_cache_entry(args)
src_url = resolve_url(args.u, redirects)
# Please remove after 3 months (2015-10-07). See LEGACY_CACHE_DIR above.
if not path.exists(cache_ent) and path.exists(legacy_cache_ent):
try:
safe_mkdirs(path.dirname(cache_ent))
except OSError as err:
print('error creating directory %s: %s' %
(path.dirname(cache_ent), err), file=stderr)
exit(1)
shutil.move(legacy_cache_ent, cache_ent)
if not path.exists(cache_ent):
try:
safe_mkdirs(path.dirname(cache_ent))
except OSError as err:
print('error creating directory %s: %s' %
(path.dirname(cache_ent), err), file=stderr)
exit(1)
print('Download %s' % src_url, file=stderr)
try:
check_call(['curl', '--proxy-anyauth', '-ksfo', cache_ent, src_url])
except OSError as err:
print('could not invoke curl: %s\nis curl installed?' % err, file=stderr)
exit(1)
except CalledProcessError as err:
print('error using curl: %s' % err, file=stderr)
exit(1)
if args.v:
have = hash_file(sha1(), cache_ent).hexdigest()
if args.v != have:
print((
'%s:\n' +
'expected %s\n' +
'received %s\n') % (src_url, args.v, have), file=stderr)
try:
remove(cache_ent)
except OSError as err:
if path.exists(cache_ent):
print('error removing %s: %s' % (cache_ent, err), file=stderr)
exit(1)
exclude = []
if args.x:
exclude += args.x
if args.exclude_java_sources:
try:
with ZipFile(cache_ent, 'r') as zf:
for n in zf.namelist():
if n.endswith('.java'):
exclude.append(n)
except (BadZipfile, LargeZipFile) as err:
print('error opening %s: %s' % (cache_ent, err), file=stderr)
exit(1)
if args.unsign:
try:
with ZipFile(cache_ent, 'r') as zf:
for n in zf.namelist():
if (n.endswith('.RSA')
or n.endswith('.SF')
or n.endswith('.LIST')):
exclude.append(n)
except (BadZipfile, LargeZipFile) as err:
print('error opening %s: %s' % (cache_ent, err), file=stderr)
exit(1)
safe_mkdirs(path.dirname(args.o))
if exclude:
try:
shutil.copyfile(cache_ent, args.o)
except (shutil.Error, IOError) as err:
print('error copying to %s: %s' % (args.o, err), file=stderr)
exit(1)
try:
check_call(['zip', '-d', args.o] + exclude)
except CalledProcessError as err:
print('error removing files from zip: %s' % err, file=stderr)
exit(1)
else:
try:
link(cache_ent, args.o)
except OSError as err:
try:
shutil.copyfile(cache_ent, args.o)
except (shutil.Error, IOError) as err:
print('error copying to %s: %s' % (args.o, err), file=stderr)
exit(1)
def java_doc(
name,
title,
pkgs,
paths,
srcs = [],
deps = [],
visibility = [],
do_it_wrong = False,
):
if do_it_wrong:
sourcepath = paths
else:
sourcepath = ['$SRCDIR/' + n for n in paths]
genrule(
name = name,
cmd = ' '.join([
'while ! test -f .buckconfig; do cd ..; done;',
'javadoc',
'-quiet',
'-protected',
'-encoding UTF-8',
'-charset UTF-8',
'-notimestamp',
'-windowtitle "' + title + '"',
'-link http://docs.oracle.com/javase/7/docs/api',
'-subpackages ',
':'.join(pkgs),
'-sourcepath ',
':'.join(sourcepath),
' -classpath ',
':'.join(['$(classpath %s)' % n for n in deps]),
'-d $TMP',
]) + ';jar cf $OUT -C $TMP .',
srcs = srcs,
out = name + '.jar',
visibility = visibility,
)
#!/usr/bin/env python
# Copyright (C) 2013 The Android Open Source Project
#
# 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.
from __future__ import print_function
from optparse import OptionParser
from os import makedirs, path, symlink
from subprocess import check_call
import sys
opts = OptionParser()
opts.add_option('-o', help='path to write WAR to')
opts.add_option('--lib', action='append', help='target for WEB-INF/lib')
opts.add_option('--pgmlib', action='append', help='target for WEB-INF/pgm-lib')
opts.add_option('--tmp', help='temporary directory')
args, ctx = opts.parse_args()
war = args.tmp
jars = set()
basenames = set()
def prune(l):
return [j for e in l for j in e.split(':')]
def link_jars(libs, directory):
makedirs(directory)
for j in libs:
if j not in jars:
# When jgit is consumed from its own cell,
# potential duplicates should be filtered.
# e.g. jsch.jar will be reached through:
# 1. /home/username/projects/gerrit/buck-out/gen/lib/jsch.jar
# 2. /home/username/projects/jgit/buck-out/gen/lib/jsch.jar
if (j.find('jgit/buck-out/gen/lib') > 0
and path.basename(j) in basenames):
continue
jars.add(j)
n = path.basename(j)
if j.find('buck-out/gen/gerrit-') > 0:
n = j[j.find('buck-out'):].split('/')[2] + '-' + n
basenames.add(n)
symlink(j, path.join(directory, n))
if args.lib:
link_jars(prune(args.lib), path.join(war, 'WEB-INF', 'lib'))
if args.pgmlib:
link_jars(prune(args.pgmlib), path.join(war, 'WEB-INF', 'pgm-lib'))
try:
for s in ctx:
check_call(['unzip', '-q', '-d', war, s])
check_call(['zip', '-9qr', args.o, '.'], cwd=war)
except KeyboardInterrupt:
print('Interrupted by user', file=sys.stderr)
exit(1)
# Copyright (C) 2013 The Android Open Source Project
#
# 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 os
from os import path
REPO_ROOTS = {
'GERRIT': 'http://gerrit-maven.storage.googleapis.com',
'GERRIT_API': 'https://gerrit-api.commondatastorage.googleapis.com/release',
'MAVEN_CENTRAL': 'http://repo1.maven.org/maven2',
'MAVEN_LOCAL': 'file://' + path.expanduser('~/.m2/repository'),
}
def resolve_url(url, redirects):
""" Resolve URL of a Maven artifact.
prefix:path is passed as URL. prefix identifies known or custom
repositories that can be rewritten in redirects set, passed as
second arguments.
A special case is supported, when prefix neither exists in
REPO_ROOTS, no in redirects set: the url is returned as is.
This enables plugins to pass custom maven_repository URL as is
directly to maven_jar().
Returns a resolved path for Maven artifact.
"""
s = url.find(':')
if s < 0:
return url
scheme, rest = url[:s], url[s+1:]
if scheme in redirects:
root = redirects[scheme]
elif scheme in REPO_ROOTS:
root = REPO_ROOTS[scheme]
else:
return url
root = root.rstrip('/')
rest = rest.lstrip('/')
return '/'.join([root, rest])
def hash_file(hash_obj, path):
"""Hash the contents of a file.
Args:
hash_obj: an open hash object, e.g. hashlib.sha1().
path: path to the file to hash.
Returns:
The passed-in hash_obj.
"""
with open(path, 'rb') as f:
while True:
b = f.read(8192)
if not b:
break
hash_obj.update(b)
return hash_obj
def hash_bower_component(hash_obj, path):
"""Hash the contents of a bower component directory.
This is a stable hash of a directory downloaded with `bower install`, minus
the .bower.json file, which is autogenerated each time by bower. Used in lieu
of hashing a zipfile of the contents, since zipfiles are difficult to hash in
a stable manner.
Args:
hash_obj: an open hash object, e.g. hashlib.sha1().
path: path to the directory to hash.
Returns:
The passed-in hash_obj.
"""
if not os.path.isdir(path):
raise ValueError('Not a directory: %s' % path)
path = os.path.abspath(path)
for root, dirs, files in os.walk(path):
dirs.sort()
for f in sorted(files):
if f == '.bower.json':
continue
p = os.path.join(root, f)
hash_obj.update(p[len(path)+1:])
hash_file(hash_obj, p)
return hash_obj