Revert of Add GN build rules to allow java_assertion_enabler to enable Java asserts. (patchset #2 id:140001 of https://codereview.chromium.org/2506013004/ )

Reason for revert:
This CL cause WebView to crash

BUG=666193

Original issue's description:
> Reland of Add GN build rules to allow java_assertion_enabler to enable Java asserts.
>
> Reverted in:
> https://codereview.chromium.org/2507153002/
>
> Reason for reland:
> Now explicitly lists default toolchain
>
> Also modify java_assertion_enabler to resolve cycle dependency issue
> and empty jar issue.
>
> TBR=jbudorick@chromium.org,agrieve@chromium.org,toyoshim@chromium.org,qinmin@chromium.org
> BUG=462676,665157,665478
>
> Committed: https://crrev.com/95785a8601992a057837bc189e9f7eba61701f1e
> Cr-Commit-Position: refs/heads/master@{#432607}

TBR=jbudorick@chromium.org,agrieve@chromium.org,toyoshim@chromium.org,qinmin@chromium.org,zpeng@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=462676,665157,665478

Review-Url: https://codereview.chromium.org/2506263003
Cr-Original-Commit-Position: refs/heads/master@{#432789}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 5e5387276fc07873f2a2c730b7b1adbd0d0a70ca
This commit is contained in:
yolandyan 2016-11-16 22:54:34 -08:00 коммит произвёл Commit bot
Родитель 7931e19b94
Коммит 73ac91764e
3 изменённых файлов: 75 добавлений и 143 удалений

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

@ -4,14 +4,13 @@
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
assert(current_toolchain == default_toolchain)
java_binary("java_assertion_enabler") { java_binary("java_assertion_enabler") {
testonly = true
java_files = java_files =
[ "java/org/chromium/javaassertionenabler/AssertionEnabler.java" ] [ "java/org/chromium/javaassertionenabler/AssertionEnabler.java" ]
main_class = "org.chromium.javaassertionenabler.AssertionEnabler" main_class = "org.chromium.javaassertionenabler.AssertionEnabler"
deps = [ deps = [
"//third_party/guava:guava_java",
"//third_party/ow2_asm:asm_java", "//third_party/ow2_asm:asm_java",
] ]
wrapper_script_name = "helper/java_assertion_enabler"
} }

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

@ -4,6 +4,8 @@
package org.chromium.javaassertionenabler; package org.chromium.javaassertionenabler;
import com.google.common.io.ByteStreams;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
@ -12,30 +14,21 @@ import org.objectweb.asm.Opcodes;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.util.Collections;
import java.nio.file.Files; import java.util.jar.JarEntry;
import java.nio.file.Path; import java.util.jar.JarFile;
import java.nio.file.Paths; import java.util.jar.JarOutputStream;
import java.nio.file.StandardCopyOption;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
/** /**
* An application that enables Java ASSERT statements by modifying Java bytecode. It takes in a JAR * An application that enables Java ASSERT statements by modifying Java bytecode. It takes in a JAR
* file, modifies bytecode of classes that use ASSERT, and outputs the bytecode to a new JAR file. * file, modifies bytecode of classes that use ASSERT, and outputs the bytecode to a new JAR file.
*/ */
class AssertionEnabler { class AssertionEnabler {
static final String ASSERTION_DISABLED_NAME = "$assertionsDisabled";
static final String CLASS_FILE_SUFFIX = ".class"; static final String CLASS_FILE_SUFFIX = ".class";
static final String STATIC_INITIALIZER_NAME = "<clinit>"; static final String STATIC_INITIALIZER_NAME = "<clinit>";
static final String TEMPORARY_FILE_SUFFIX = ".temp"; static final String ASSERTION_DISABLED_NAME = "$assertionsDisabled";
static final int BUFFER_SIZE = 16384;
static class AssertionEnablerVisitor extends ClassVisitor { static class AssertionEnablerVisitor extends ClassVisitor {
AssertionEnablerVisitor(ClassWriter writer) { AssertionEnablerVisitor(ClassWriter writer) {
@ -75,53 +68,33 @@ class AssertionEnabler {
} }
} }
static byte[] readAllBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int numRead = 0;
byte[] data = new byte[BUFFER_SIZE];
while ((numRead = inputStream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, numRead);
}
return buffer.toByteArray();
}
static void enableAssertionInJar(String inputJarPath, String outputJarPath) { static void enableAssertionInJar(String inputJarPath, String outputJarPath) {
String tempJarPath = outputJarPath + TEMPORARY_FILE_SUFFIX; try (JarOutputStream outputStream = new JarOutputStream(
try (ZipInputStream inputStream = new ZipInputStream( new BufferedOutputStream(new FileOutputStream(outputJarPath)))) {
new BufferedInputStream(new FileInputStream(inputJarPath))); JarFile jarFile = new JarFile(inputJarPath);
ZipOutputStream tempStream = new ZipOutputStream( for (JarEntry entry : Collections.list(jarFile.entries())) {
new BufferedOutputStream(new FileOutputStream(tempJarPath)))) { try (BufferedInputStream inputStream = new BufferedInputStream(
ZipEntry entry = null; jarFile.getInputStream(entry))) {
byte[] byteCode = ByteStreams.toByteArray(inputStream);
while ((entry = inputStream.getNextEntry()) != null) { if (entry.isDirectory() || !entry.getName().endsWith(CLASS_FILE_SUFFIX)) {
byte[] byteCode = readAllBytes(inputStream); outputStream.putNextEntry(entry);
outputStream.write(byteCode);
if (entry.isDirectory() || !entry.getName().endsWith(CLASS_FILE_SUFFIX)) { outputStream.closeEntry();
tempStream.putNextEntry(entry); continue;
tempStream.write(byteCode); }
tempStream.closeEntry(); ClassReader reader = new ClassReader(byteCode);
continue; ClassWriter writer = new ClassWriter(reader, 0);
reader.accept(new AssertionEnablerVisitor(writer), 0);
byte[] patchedByteCode = writer.toByteArray();
outputStream.putNextEntry(new JarEntry(entry.getName()));
outputStream.write(patchedByteCode);
outputStream.closeEntry();
} }
ClassReader reader = new ClassReader(byteCode);
ClassWriter writer = new ClassWriter(reader, 0);
reader.accept(new AssertionEnablerVisitor(writer), 0);
byte[] patchedByteCode = writer.toByteArray();
tempStream.putNextEntry(new ZipEntry(entry.getName()));
tempStream.write(patchedByteCode);
tempStream.closeEntry();
} }
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
try {
Path src = Paths.get(tempJarPath);
Path dest = Paths.get(outputJarPath);
Files.move(src, dest, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException ioException) {
throw new RuntimeException(ioException);
}
} }
public static void main(String[] args) { public static void main(String[] args) {

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

@ -6,7 +6,6 @@
# Some projects (e.g. V8) do not have non-build directories DEPS'ed in. # Some projects (e.g. V8) do not have non-build directories DEPS'ed in.
import("//build_overrides/build.gni") import("//build_overrides/build.gni")
import("//build/config/android/config.gni") import("//build/config/android/config.gni")
import("//build/config/dcheck_always_on.gni")
import("//build/config/sanitizers/sanitizers.gni") import("//build/config/sanitizers/sanitizers.gni")
assert(is_android) assert(is_android)
@ -1015,11 +1014,10 @@ if (enable_java_templates) {
_rebased_build_config = rebase_path(_build_config, root_build_dir) _rebased_build_config = rebase_path(_build_config, root_build_dir)
assert(_rebased_build_config != "" || true) # Mark used. assert(_rebased_build_config != "" || true) # Mark used.
_input_jar_path = invoker.input_jar_path
_output_jar_path = invoker.output_jar_path
_proguard_preprocess = _proguard_preprocess =
defined(invoker.proguard_preprocess) && invoker.proguard_preprocess defined(invoker.proguard_preprocess) && invoker.proguard_preprocess
_input_jar_path = invoker.input_jar_path
_output_jar_path = invoker.output_jar_path
_jar_excluded_patterns = [] _jar_excluded_patterns = []
if (defined(invoker.jar_excluded_patterns)) { if (defined(invoker.jar_excluded_patterns)) {
@ -1029,15 +1027,24 @@ if (enable_java_templates) {
invoker.strip_resource_classes invoker.strip_resource_classes
_filter_jar = _jar_excluded_patterns != [] || _strip_resource_classes _filter_jar = _jar_excluded_patterns != [] || _strip_resource_classes
_enable_assert =
defined(invoker.supports_android) && invoker.supports_android &&
(is_java_debug || dcheck_always_on)
assert(_enable_assert || true) # Mark used.
if (_filter_jar) { if (_filter_jar) {
_filter_target = "${target_name}__filter" _filter_target = "${target_name}__filter"
_output_jar_target = _filter_target
}
if (_proguard_preprocess) {
_proguard_target = "${target_name}__proguard_process"
_output_jar_target = _proguard_target
}
if (!_filter_jar && !_proguard_preprocess) {
_copy_target = "${target_name}__copy"
_output_jar_target = _copy_target
}
_filter_jar_path = "$target_out_dir/$target_name-filtered.jar" if (_filter_jar) {
_filtered_jar_path = _output_jar_path
if (_proguard_preprocess) {
_filtered_jar_path = "$target_out_dir/$target_name-filtered.jar"
}
action(_filter_target) { action(_filter_target) {
script = "//build/android/gyp/jar.py" script = "//build/android/gyp/jar.py"
forward_variables_from(invoker, forward_variables_from(invoker,
@ -1050,13 +1057,13 @@ if (enable_java_templates) {
_input_jar_path, _input_jar_path,
] ]
outputs = [ outputs = [
_filter_jar_path, _filtered_jar_path,
] ]
args = [ args = [
"--input-jar", "--input-jar",
rebase_path(_input_jar_path, root_build_dir), rebase_path(_input_jar_path, root_build_dir),
"--jar-path", "--jar-path",
rebase_path(_filter_jar_path, root_build_dir), rebase_path(_filtered_jar_path, root_build_dir),
"--excluded-classes=$_jar_excluded_patterns", "--excluded-classes=$_jar_excluded_patterns",
] ]
if (_strip_resource_classes) { if (_strip_resource_classes) {
@ -1066,83 +1073,15 @@ if (enable_java_templates) {
} }
if (_proguard_preprocess) { if (_proguard_preprocess) {
_output_jar_target = "${target_name}__proguard_process"
_proguard_output_jar = _output_jar_path
_proguard_config_path = invoker.proguard_preprocess_config _proguard_config_path = invoker.proguard_preprocess_config
proguard(_output_jar_target) { proguard(_proguard_target) {
if (_filter_jar) { if (_filter_jar) {
_proguard_input_jar = _filter_jar_path _proguard_input_jar = _filtered_jar_path
deps = [
":$_filter_target",
]
} else {
_proguard_input_jar = _input_jar_path
deps = []
}
if (defined(invoker.deps)) {
deps += invoker.deps
}
if (defined(invoker.public_deps)) {
public_deps = invoker.public_deps
}
inputs = [
_build_config,
_proguard_config_path,
_proguard_input_jar,
]
output_jar_path = _proguard_output_jar
_rebased_input_paths =
[ rebase_path(_proguard_input_jar, root_build_dir) ]
_rebased_proguard_configs =
[ rebase_path(_proguard_config_path, root_build_dir) ]
args = [
"--input-paths=$_rebased_input_paths",
"--proguard-configs=$_rebased_proguard_configs",
"--classpath=@FileArg($_rebased_build_config:javac:classpath)",
]
}
} else if (_enable_assert) {
_output_jar_target = "${target_name}__assert"
_assert_output_jar = _output_jar_path
action(_output_jar_target) {
script = "$root_out_dir/bin/helper/java_assertion_enabler"
deps = [
"//build/android/java_assertion_enabler($default_toolchain)",
]
if (_filter_jar) {
_assert_input_jar = _filter_jar_path
deps += [ ":$_filter_target" ]
} else {
_assert_input_jar = _input_jar_path
}
if (defined(invoker.deps)) {
deps += invoker.deps
}
if (defined(invoker.public_deps)) {
public_deps = invoker.public_deps
}
inputs = [
_assert_input_jar,
]
outputs = [
_assert_output_jar,
]
args = [
rebase_path(_assert_input_jar, root_build_dir),
rebase_path(_assert_output_jar, root_build_dir),
]
}
} else {
_output_jar_target = "${target_name}__copy"
copy(_output_jar_target) {
if (_filter_jar) {
_copy_input_jar = _filter_jar_path
public_deps = [ public_deps = [
":$_filter_target", ":$_filter_target",
] ]
} else { } else {
_copy_input_jar = _input_jar_path _proguard_input_jar = _input_jar_path
public_deps = [] public_deps = []
} }
if (defined(invoker.deps)) { if (defined(invoker.deps)) {
@ -1151,8 +1090,31 @@ if (enable_java_templates) {
if (defined(invoker.public_deps)) { if (defined(invoker.public_deps)) {
public_deps += invoker.public_deps public_deps += invoker.public_deps
} }
inputs = [
_build_config,
_proguard_config_path,
_proguard_input_jar,
]
output_jar_path = _output_jar_path
_rebased_input_paths = [ rebase_path(_input_jar_path, root_build_dir) ]
_rebased_proguard_configs =
[ rebase_path(_proguard_config_path, root_build_dir) ]
args = [
"--input-paths=$_rebased_input_paths",
"--proguard-configs=$_rebased_proguard_configs",
"--classpath=@FileArg($_rebased_build_config:javac:classpath)",
]
}
} else if (!_filter_jar) {
copy(_copy_target) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
])
sources = [ sources = [
_copy_input_jar, _input_jar_path,
] ]
outputs = [ outputs = [
_output_jar_path, _output_jar_path,
@ -1848,7 +1810,6 @@ if (enable_java_templates) {
visibility += [ ":$_dex_target_name" ] visibility += [ ":$_dex_target_name" ]
} }
supports_android = _supports_android
build_config = _build_config build_config = _build_config
input_jar_path = invoker.jar_path input_jar_path = invoker.jar_path
output_jar_path = _jar_path output_jar_path = _jar_path
@ -2140,7 +2101,6 @@ if (enable_java_templates) {
"proguard_preprocess", "proguard_preprocess",
"proguard_preprocess_config", "proguard_preprocess_config",
]) ])
supports_android = _supports_android
build_config = _build_config build_config = _build_config
input_jar_path = _javac_jar_path input_jar_path = _javac_jar_path
output_jar_path = _process_prebuilt_jar_path output_jar_path = _process_prebuilt_jar_path