Revert of Revert of [Android] JUnit runner + gyp changes. (patchset #1 id:1 of https://codereview.chromium.org/597123002/)

Reason for revert:
Didn't help. We probably got scheduled on other, flakier Android devices which caused tests to start flaking, or something else is the root cause.

Original issue's description:
> Revert of [Android] JUnit runner + gyp changes. (patchset #15 id:280001 of https://codereview.chromium.org/574433003/)
>
> Reason for revert:
> Speculative revert: Android test started flaking a ton after this landed. Affected targets androidwebview_instrumentation_tests, chromeshell_instrumentation_tests, contentshell_instrumentation_tests. This CL seems the most likely in the blamelist of https://build.chromium.org/p/chromium.linux/builders/Android%20Tests/builds/15905.
>
> Original issue's description:
> > [Android] JUnit runner + gyp changes.
> >
> > This adds Java code for running junit tests, as well as gyp targets for
> > both runnable and non-runnable host-side JARs.
> >
> > BUG=316383
> >
> > Committed: https://crrev.com/2e56d4508e33de5fc60bbbb41c5a5d5534e88174
> > Cr-Commit-Position: refs/heads/master@{#296340}
>
> TBR=cjhopman@chromium.org,nyquist@chromium.org,aurimas@chromium.org,jbudorick@chromium.org
> NOTREECHECKS=true
> NOTRY=true
> BUG=316383
>
> Committed: https://crrev.com/54b9408f8b18e3bf3a33343e375186e1949e8e86
> Cr-Commit-Position: refs/heads/master@{#296384}

TBR=cjhopman@chromium.org,nyquist@chromium.org,aurimas@chromium.org,jbudorick@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=316383

Review URL: https://codereview.chromium.org/596303002

Cr-Original-Commit-Position: refs/heads/master@{#296406}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 6e9dc50aecf078d7826fe8e4611b2c238aab3f23
This commit is contained in:
phoglund 2014-09-24 07:02:00 -07:00 коммит произвёл Commit bot
Родитель 9e1ba0c668
Коммит 6b74137567
5 изменённых файлов: 220 добавлений и 6 удалений

Просмотреть файл

@ -781,6 +781,7 @@
'../sandbox/sandbox.gyp:sandbox_linux_unittests_stripped',
'../sql/sql.gyp:sql_unittests',
'../sync/sync.gyp:sync_unit_tests',
'../testing/android/junit/junit_test.gyp:junit_unit_tests',
'../third_party/leveldatabase/leveldatabase.gyp:env_chromium_unittests',
'../third_party/WebKit/public/all.gyp:*',
'../tools/android/android_tools.gyp:android_tools',

Просмотреть файл

@ -12,7 +12,8 @@ import sys
from util import build_utils
from util import md5_check
def Jar(class_files, classes_dir, jar_path):
def Jar(class_files, classes_dir, jar_path, manifest_file=None):
jar_path = os.path.abspath(jar_path)
# The paths of the files in the jar will be the same as they are passed in to
@ -20,7 +21,11 @@ def Jar(class_files, classes_dir, jar_path):
# options.classes_dir so the .class file paths in the jar are correct.
jar_cwd = classes_dir
class_files_rel = [os.path.relpath(f, jar_cwd) for f in class_files]
jar_cmd = ['jar', 'cf0', jar_path] + class_files_rel
jar_cmd = ['jar', 'cf0', jar_path]
if manifest_file:
jar_cmd[1] += 'm'
jar_cmd.append(os.path.abspath(manifest_file))
jar_cmd.extend(class_files_rel)
record_path = '%s.md5.stamp' % jar_path
md5_check.CallAndRecordIfStale(
@ -34,13 +39,14 @@ def Jar(class_files, classes_dir, jar_path):
build_utils.Touch(jar_path, fail_if_missing=True)
def JarDirectory(classes_dir, excluded_classes, jar_path):
def JarDirectory(classes_dir, excluded_classes, jar_path, manifest_file=None):
class_files = build_utils.FindInDirectory(classes_dir, '*.class')
for exclude in excluded_classes:
class_files = filter(
lambda f: not fnmatch.fnmatch(f, exclude), class_files)
Jar(class_files, classes_dir, jar_path)
Jar(class_files, classes_dir, jar_path, manifest_file=manifest_file)
def main():
parser = optparse.OptionParser()
@ -52,8 +58,12 @@ def main():
options, _ = parser.parse_args()
if options.excluded_classes:
excluded_classes = build_utils.ParseGypList(options.excluded_classes)
else:
excluded_classes = []
JarDirectory(options.classes_dir,
build_utils.ParseGypList(options.excluded_classes),
excluded_classes,
options.jar_path)
if options.stamp:

Просмотреть файл

@ -10,6 +10,7 @@ import os
import shutil
import re
import sys
import textwrap
from util import build_utils
from util import md5_check
@ -99,6 +100,43 @@ def DoJavac(
input_strings=javac_cmd)
_MAX_MANIFEST_LINE_LEN = 72
def CreateManifest(manifest_path, classpath, main_class=None):
"""Creates a manifest file with the given parameters.
This generates a manifest file that compiles with the spec found at
http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Manifest
Args:
manifest_path: The path to the manifest file that should be created.
classpath: The JAR files that should be listed on the manifest file's
classpath.
main_class: If present, the class containing the main() function.
"""
output = ['Manifest-Version: 1.0']
if main_class:
output.append('Main-Class: %s' % main_class)
if classpath:
sanitized_paths = []
for path in classpath:
sanitized_paths.append(os.path.basename(path.strip('"')))
output.append('Class-Path: %s' % ' '.join(sanitized_paths))
output.append('Created-By: ')
output.append('')
wrapper = textwrap.TextWrapper(break_long_words=True,
drop_whitespace=False,
subsequent_indent=' ',
width=_MAX_MANIFEST_LINE_LEN - 2)
output = '\r\n'.join(w for l in output for w in wrapper.wrap(l))
with open(manifest_path, 'w') as f:
f.write(output)
def main(argv):
colorama.init()
@ -139,11 +177,17 @@ def main(argv):
'--classes-dir',
help='Directory for compiled .class files.')
parser.add_option('--jar-path', help='Jar output path.')
parser.add_option(
'--main-class',
help='The class containing the main method.')
parser.add_option('--stamp', help='Path to touch on success.')
options, args = parser.parse_args(argv)
if options.main_class and not options.jar_path:
parser.error('--main-class requires --jar-path')
classpath = []
for arg in options.classpath:
classpath += build_utils.ParseGypList(arg)
@ -185,9 +229,16 @@ def main(argv):
java_files)
if options.jar_path:
if options.main_class:
manifest_file = os.path.join(temp_dir, 'manifest')
CreateManifest(manifest_file, classpath,
options.main_class)
else:
manifest_file = None
jar.JarDirectory(classes_dir,
build_utils.ParseGypList(options.jar_excluded_classes),
options.jar_path)
options.jar_path,
manifest_file=manifest_file)
if options.classes_dir:
# Delete the old classes directory. This ensures that all .class files in

102
host_jar.gypi Normal file
Просмотреть файл

@ -0,0 +1,102 @@
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This file is meant to be included into a target to provide a rule to build
# a JAR file for use on a host in a consistent manner.
#
# To use this, create a gyp target with the following form:
# {
# 'target_name': 'my_jar',
# 'type': 'none',
# 'variables': {
# 'src_paths': [
# 'path/to/directory',
# 'path/to/other/directory',
# 'path/to/individual_file.java',
# ...
# ],
# },
# 'includes': [ 'path/to/this/gypi/file' ],
# }
#
# Required variables:
# src_paths - A list of all paths containing java files that should be
# included in the jar. Paths can be either directories or files.
# Optional/automatic variables:
# excluded_src_paths - A list of all paths that should be excluded from
# the jar.
# generated_src_dirs - Directories containing additional .java files
# generated at build time.
# input_jars_paths - A list of paths to the jars that should be included
# in the classpath.
# main_class - The class containing the main() function that should be called
# when running the jar file.
# jar_excluded_classes - A list of .class files that should be excluded
# from the jar.
{
'dependencies': [
'<(DEPTH)/build/android/setup.gyp:build_output_dirs',
],
'variables': {
'classes_dir': '<(intermediate_dir)/classes',
'excluded_src_paths': [],
'generated_src_dirs': [],
'input_jars_paths': [],
'intermediate_dir': '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)',
'jar_dir': '<(PRODUCT_DIR)/lib.java',
'jar_excluded_classes': [],
'jar_name': '<(_target_name).jar',
'jar_path': '<(jar_dir)/<(jar_name)',
'main_class%': '',
'stamp': '<(intermediate_dir)/jar.stamp',
},
'all_dependent_settings': {
'variables': {
'input_jars_paths': ['<(jar_path)']
},
},
'actions': [
{
'action_name': 'javac_<(_target_name)',
'message': 'Compiling <(_target_name) java sources',
'variables': {
'extra_options': [],
'java_sources': [ '<!@(find <@(src_paths) -name "*.java")' ],
'conditions': [
['"<(excluded_src_paths)" != ""', {
'java_sources!': ['<!@(find <@(excluded_src_paths) -name "*.java")']
}],
['"<(jar_excluded_classes)" != ""', {
'extra_options': ['--excluded-classes=<(jar_excluded_classes)']
}],
['">(main_class)" != ""', {
'extra_options': ['--main-class=>(main_class)']
}]
],
},
'inputs': [
'<(DEPTH)/build/android/gyp/util/build_utils.py',
'<(DEPTH)/build/android/gyp/javac.py',
'^@(java_sources)',
'>@(input_jars_paths)',
],
'outputs': [
'<(jar_path)',
'<(stamp)',
],
'action': [
'python', '<(DEPTH)/build/android/gyp/javac.py',
'--classpath=>(input_jars_paths)',
'--src-gendirs=>(generated_src_dirs)',
'--chromium-code=<(chromium_code)',
'--stamp=<(stamp)',
'--jar-path=<(jar_path)',
'<@(extra_options)',
'^@(java_sources)',
],
},
]
}

50
host_prebuilt_jar.gypi Normal file
Просмотреть файл

@ -0,0 +1,50 @@
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This file is meant to be included into a target to provide a rule to
# copy a prebuilt JAR for use on a host to the output directory.
#
# To use this, create a gyp target with the following form:
# {
# 'target_name': 'my_prebuilt_jar',
# 'type': 'none',
# 'variables': {
# 'jar_path': 'path/to/prebuilt.jar',
# },
# 'includes': [ 'path/to/this/gypi/file' ],
# }
#
# Required variables:
# jar_path - The path to the prebuilt jar.
{
'dependencies': [
],
'variables': {
'dest_path': '<(PRODUCT_DIR)/lib.java/<(_target_name).jar',
'src_path': '<(jar_path)',
},
'all_dependent_settings': {
'variables': {
'input_jars_paths': [
'<(dest_path)',
]
},
},
'actions': [
{
'action_name': 'copy_prebuilt_jar',
'message': 'Copy <(src_path) to <(dest_path)',
'inputs': [
'<(src_path)',
],
'outputs': [
'<(dest_path)',
],
'action': [
'python', '<(DEPTH)/build/cp.py', '<(src_path)', '<(dest_path)',
],
}
]
}