From 438062bd436f86b5a41d6b184827ba5ed0d4ee18 Mon Sep 17 00:00:00 2001 From: mbonadei Date: Mon, 9 Jan 2017 02:37:21 -0800 Subject: [PATCH] Reland of Fixing package-boundary violation with srjar_deps (patchset #1 id:1 of https://codereview.webrtc.org/2617533005/ ) Reason for revert: Skipping the build of the target "//webrtc/modules/audio_device:audio_device_java" when building webrtc with chromium. This was causing a failure because in that case it is not possible to refer to the script used by the template "android_shared_srcjar" with an absolute path (which seems to be necessary since the script attribute of action is relative to the invocation target and not to the template declaration). Original issue's description: > Revert of Fixing package-boundary violation with srjar_deps (patchset #5 id:80001 of https://codereview.webrtc.org/2610823002/ ) > > Reason for revert: > This CL is breaking a chromium.webrtc.fyi: https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Builder/builds/226 > > I am trying to reproduce the issue on my local machine and I will try to re-land the CL later. > > Original issue's description: > > Fixing package-boundary violation with srjar_deps > > > > Without the usage of the srcjar_deps attribute we were not able to > > include .java files from other packages without violating the package > > boundary contraint. > > > > As an example, in this CL the target "libjingle_peerconnection_java" was > > directly including .java files from another packages in its "java_files" > > attribute. > > > > Using srcjar_deps we are able to declare the dependency of the target > > avoiding to create hidden dependencies in the codebase. > > > > This is not fixing the webrtc:6356 bug directly but it is a first step to > > include ThreadUtils classes in libjingle_peerconnection_client_java.jar > > again. > > > > It seems also to be related to the chromium:648244 bug. This can be solved > > if we can find a way to perform srcjar generation in the android_library > > target without changing the semantic of the target. > > > > BUG=webrtc:6356 > > > > Review-Url: https://codereview.webrtc.org/2610823002 > > Cr-Commit-Position: refs/heads/master@{#15914} > > Committed: https://chromium.googlesource.com/external/webrtc/+/10a76592a78762187bfaf3547b7e9986454062ab > > TBR=kjellander@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:6356 > > Review-Url: https://codereview.webrtc.org/2617533005 > Cr-Commit-Position: refs/heads/master@{#15915} > Committed: https://chromium.googlesource.com/external/webrtc/+/eb731ed09ebfea1b26d1b7bc1f2678f7bbc012ee TBR=kjellander@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:6356 Review-Url: https://codereview.webrtc.org/2612953004 Cr-Commit-Position: refs/heads/master@{#15958} --- webrtc/build/generate_srcjar.py | 68 ++++++++++++++++++++++++++++ webrtc/build/webrtc.gni | 29 ++++++++++++ webrtc/modules/audio_device/BUILD.gn | 18 ++++++++ webrtc/sdk/android/BUILD.gn | 8 +--- 4 files changed, 117 insertions(+), 6 deletions(-) create mode 100755 webrtc/build/generate_srcjar.py diff --git a/webrtc/build/generate_srcjar.py b/webrtc/build/generate_srcjar.py new file mode 100755 index 0000000000..946722ad5e --- /dev/null +++ b/webrtc/build/generate_srcjar.py @@ -0,0 +1,68 @@ +#!/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. + +# TODO(mbonadei): move this script into chromium (build/android/gyp) +# when approved + +import optparse +import os +import re +import sys +import zipfile + +sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, os.pardir, 'build', + 'android', 'gyp', 'util'))) +import build_utils + + +def PackageToPath(src_file): + """Returns the path of a .java file according to the package declaration. + + Example: + src_file='/home/foo/bar/org/android/TestClass.java' + With the following package definition: + package org.android; + + It will return 'org/android'. + + Args: + A string with the path of the .java source file to analyze. + + Returns: + A string with the translation of the package definition into a path. + """ + with open(src_file) as f: + file_src = f.read() + package = re.search('package (.*);', file_src).group(1) + zip_folder = package.replace('.', os.path.sep) + file_name = os.path.basename(src_file) + return os.path.join(zip_folder, file_name) + + +def DoMain(argv): + usage = 'usage: %prog [options] input_file(s)...' + parser = optparse.OptionParser(usage=usage) + parser.add_option('-s', '--srcjar', + help='The path where the .srcjar file will be generated') + + options, args = parser.parse_args(argv) + + if not args: + parser.error('Need to specify at least one input source file (.java)') + input_paths = args + + with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar: + for src_path in input_paths: + zip_path = PackageToPath(src_path) + build_utils.AddToZipHermetic(srcjar, zip_path, src_path) + + +if __name__ == '__main__': + DoMain(sys.argv[1:]) diff --git a/webrtc/build/webrtc.gni b/webrtc/build/webrtc.gni index ce59871576..8a460f5d7e 100644 --- a/webrtc/build/webrtc.gni +++ b/webrtc/build/webrtc.gni @@ -324,3 +324,32 @@ template("rtc_shared_library") { } } } + +# TODO(mbonadei): Merge this in android_library or create an +# rtc_android_library. Waiting for hints from chromium:648244. +if (is_android) { + template("android_shared_srcjar") { + action(target_name) { + check_includes = false + set_sources_assignment_filter([]) + assert(defined(invoker.sources)) + + forward_variables_from(invoker, + [ + "sources", + "testonly", + "visibility", + ]) + script = "//webrtc/build/generate_srcjar.py" + _srcjar_path = "${target_gen_dir}/${target_name}.srcjar" + _rebased_srcjar_path = rebase_path(_srcjar_path, root_build_dir) + _rebased_sources = rebase_path(invoker.sources, root_build_dir) + + args = [ "--srcjar=$_rebased_srcjar_path" ] + _rebased_sources + + outputs = [ + _srcjar_path, + ] + } + } +} diff --git a/webrtc/modules/audio_device/BUILD.gn b/webrtc/modules/audio_device/BUILD.gn index 22941484b2..ab9406e13f 100644 --- a/webrtc/modules/audio_device/BUILD.gn +++ b/webrtc/modules/audio_device/BUILD.gn @@ -8,6 +8,11 @@ import("../../build/webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + config("audio_device_config") { include_dirs = [ "../include", @@ -296,3 +301,16 @@ if (rtc_include_tests && !is_ios) { public_configs = [ ":audio_device_config" ] } } + +if (!build_with_chromium && is_android) { + android_shared_srcjar("audio_device_java") { + sources = [ + "android/java/src/org/webrtc/voiceengine/BuildInfo.java", + "android/java/src/org/webrtc/voiceengine/WebRtcAudioEffects.java", + "android/java/src/org/webrtc/voiceengine/WebRtcAudioManager.java", + "android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java", + "android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java", + "android/java/src/org/webrtc/voiceengine/WebRtcAudioUtils.java", + ] + } +} diff --git a/webrtc/sdk/android/BUILD.gn b/webrtc/sdk/android/BUILD.gn index 174a90e5d3..6797e3d80a 100644 --- a/webrtc/sdk/android/BUILD.gn +++ b/webrtc/sdk/android/BUILD.gn @@ -112,12 +112,6 @@ rtc_shared_library("libjingle_peerconnection_so") { android_library("libjingle_peerconnection_java") { java_files = [ - "//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/BuildInfo.java", - "//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioEffects.java", - "//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioManager.java", - "//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java", - "//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java", - "//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioUtils.java", "api/org/webrtc/AudioSource.java", "api/org/webrtc/AudioTrack.java", "api/org/webrtc/CallSessionFileRotatingLogSink.java", @@ -178,6 +172,8 @@ android_library("libjingle_peerconnection_java") { deps = [ "//webrtc/base:base_java", ] + + srcjar_deps = [ "//webrtc/modules/audio_device:audio_device_java" ] } android_library("libjingle_peerconnection_metrics_default_java") {