Skip to content

Commit

Permalink
Support using loadable module for libpeerconnection on Android.
Browse files Browse the repository at this point in the history
Borrowed create_standalone_apk_action.gypi, create_standalone_apk.py and finalize_apk_action.gypi from https://codereview.chromium.org/14843017/ with some minor fix in create_standalone_apk_action.gypi.

For some cases where libpeerconnection needs to be a loadable module, we need to add libpeerconnection.so into Chrome_apk.
This patch takes 2 steps:
1. build chrome with libpeer_target_type=loadable_module.
2. add libpeerconnection.so into the apk file.

TEST=run gyp: GYP_DEFINES="$GYP_DEFINES libpeer_target_type=loadable_module" build/gyp_chromium
     build chrome
     re-run gyp: GYP_DEFINES="$GYP_DEFINES libpeer_target_type=loadable_module" CHROMIUM_GYP_FILE="build/android/chrome_with_libs.gyp" build/gyp_chromium
     build chrome_with_libs
     install Chrome-with-libs.apk and it works for https://apprtc.appspot.com

R=cjhopman@chromium.org, mallinath@chromium.org, tommi@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208246 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
wjia@chromium.org committed Jun 24, 2013
1 parent 3df79f4 commit 51d173f
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 15 deletions.
82 changes: 82 additions & 0 deletions build/android/chrome_with_libs.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2013 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 add more loadable libs into Chrome_apk.
#
# This is useful when building Chrome_apk with some loadable modules which are
# not included in Chrome_apk.
# As an example, when building Chrome_apk with
# libpeer_target_type=loadable_module,
# the libpeerconnection.so is not included in Chrome_apk. To add the missing
# lib, follow the steps below:
# - Run gyp:
# GYP_DEFINES="$GYP_DEFINES libpeer_target_type=loadable_module" CHROMIUM_GYP_FILE="build/android/chrome_with_libs.gyp" build/gyp_chromium
# - Build chrome_with_libs:
# ninja (or make) chrome_with_libs
#
# This tool also allows replacing the loadable module with a new one via the
# following steps:
# - Build Chrome_apk with the gyp define:
# GYP_DEFINES="$GYP_DEFINES libpeer_target_type=loadable_module" build/gyp_chromium
# ninja (or make) Chrome_apk
# - Replace libpeerconnection.so with a new one:
# cp the_new_one path/to/libpeerconnection.so
# - Run gyp:
# GYP_DEFINES="$GYP_DEFINES libpeer_target_type=loadable_module" CHROMIUM_GYP_FILE="build/android/chrome_with_libs.gyp" build/gyp_chromium
# - Build chrome_with_libs:
# ninja (or make) chrome_with_libs
{
'targets': [
{
# An "All" target is required for a top-level gyp-file.
'target_name': 'All',
'type': 'none',
'dependencies': [
'chrome_with_libs',
],
},
{
'target_name': 'chrome_with_libs',
'type': 'none',
'variables': {
'intermediate_dir': '<(PRODUCT_DIR)/prebuilt_libs/',
'chrome_unsigned_path': '<(PRODUCT_DIR)/chrome_apk/Chrome-unsigned.apk',
'chrome_with_libs_unsigned': '<(intermediate_dir)/Chrome-with-libs-unsigned.apk',
'chrome_with_libs_final': '<(PRODUCT_DIR)/apks/Chrome-with-libs.apk',
},
'dependencies': [
'<(DEPTH)/clank/native/framework/clank.gyp:chrome_apk'
],
'copies': [
{
'destination': '<(intermediate_dir)/lib/<(android_app_abi)',
'files': [
'<(PRODUCT_DIR)/libpeerconnection.so',
],
},
],
'actions': [
{
'action_name': 'put_libs_in_chrome',
'variables': {
'inputs': [
'<(intermediate_dir)/lib/<(android_app_abi)/libpeerconnection.so',
],
'input_apk_path': '<(chrome_unsigned_path)',
'output_apk_path': '<(chrome_with_libs_unsigned)',
'libraries_top_dir%': '<(intermediate_dir)',
},
'includes': [ 'create_standalone_apk_action.gypi' ],
},
{
'action_name': 'finalize_chrome_with_libs',
'variables': {
'input_apk_path': '<(chrome_with_libs_unsigned)',
'output_apk_path': '<(chrome_with_libs_final)',
},
'includes': [ 'finalize_apk_action.gypi'],
},
],
}],
}
61 changes: 61 additions & 0 deletions build/android/create_standalone_apk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python
#
# Copyright 2013 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.

"""Combines stripped libraries and incomplete APK into single standalone APK.
"""

import optparse
import os
import shutil
import sys
import tempfile

from util import build_utils
from util import md5_check

def CreateStandaloneApk(options):
def DoZip():
with tempfile.NamedTemporaryFile(suffix='.zip') as intermediate_file:
intermediate_path = intermediate_file.name
shutil.copy(options.input_apk_path, intermediate_path)
apk_path_abs = os.path.abspath(intermediate_path)
build_utils.CheckCallDie(
['zip', '-r', '-1', apk_path_abs, 'lib'],
cwd=options.libraries_top_dir,
suppress_output=True)
shutil.copy(intermediate_path, options.output_apk_path)

input_paths = [options.input_apk_path, options.libraries_top_dir]
record_path = '%s.standalone.stamp' % options.input_apk_path
md5_check.CallAndRecordIfStale(
DoZip,
record_path=record_path,
input_paths=input_paths)


def main(argv):
parser = optparse.OptionParser()
parser.add_option('--libraries-top-dir',
help='Top directory that contains libraries '
'(i.e. library paths are like '
'libraries_top_dir/lib/android_app_abi/foo.so).')
parser.add_option('--input-apk-path', help='Path to incomplete APK.')
parser.add_option('--output-apk-path', help='Path for standalone APK.')
parser.add_option('--stamp', help='Path to touch on success.')
options, _ = parser.parse_args()

required_options = ['libraries_top_dir', 'input_apk_path', 'output_apk_path']
build_utils.CheckOptions(options, parser, required=required_options)

CreateStandaloneApk(options)

if options.stamp:
build_utils.Touch(options.stamp)


if __name__ == '__main__':
sys.exit(main(sys.argv))
41 changes: 41 additions & 0 deletions build/android/create_standalone_apk_action.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2013 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 an action to provide an action that
# combines a directory of shared libraries and an incomplete APK into a
# standalone APK.
#
# To use this, create a gyp action with the following form:
# {
# 'action_name': 'some descriptive action name',
# 'variables': {
# 'inputs': [ 'input_path1', 'input_path2' ],
# 'input_apk_path': '<(unsigned_apk_path)',
# 'output_apk_path': '<(unsigned_standalone_apk_path)',
# 'libraries_top_dir': '<(libraries_top_dir)',
# },
# 'includes': [ 'relative/path/to/create_standalone_apk_action.gypi' ],
# },

{
'message': 'Creating standalone APK: <(output_apk_path)',
'variables': {
'inputs': [],
},
'inputs': [
'<(DEPTH)/build/android/gyp/util/build_utils.py',
'<(DEPTH)/build/android/gyp/create_standalone_apk.py',
'<(input_apk_path)',
'>@(inputs)',
],
'outputs': [
'<(output_apk_path)',
],
'action': [
'python', '<(DEPTH)/build/android/gyp/create_standalone_apk.py',
'--libraries-top-dir=<(libraries_top_dir)',
'--input-apk-path=<(input_apk_path)',
'--output-apk-path=<(output_apk_path)',
],
}
46 changes: 46 additions & 0 deletions build/android/finalize_apk_action.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2013 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 an action to provide an action that
# signs and zipaligns an APK.
#
# To use this, create a gyp action with the following form:
# {
# 'action_name': 'some descriptive action name',
# 'variables': {
# 'inputs': [ 'input_path1', 'input_path2' ],
# 'input_apk_path': 'relative/path/to/input.apk',
# 'output_apk_path': 'relative/path/to/output.apk',
# },
# 'includes': [ '../../build/android/finalize_apk.gypi' ],
# },
#

{
'message': 'Signing/aligning <(_target_name) APK: <(input_apk_path).',
'variables': {
'inputs': [],
'keystore_path%': '<(DEPTH)/build/android/ant/chromium-debug.keystore',
},
'inputs': [
'<(DEPTH)/build/android/gyp/util/build_utils.py',
'<(DEPTH)/build/android/gyp/finalize_apk.py',
'<(keystore_path)',
'<(input_apk_path)',
'>@(inputs)',
],
'outputs': [
'<(output_apk_path)',
],
'action': [
'python', '<(DEPTH)/build/android/gyp/finalize_apk.py',
'--android-sdk-root=<(android_sdk_root)',
'--unsigned-apk-path=<(input_apk_path)',
'--final-apk-path=<(output_apk_path)',
'--keystore-path=<(keystore_path)',

# TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
'--ignore=>!(echo \'>(_inputs)\' | md5sum)',
],
}
7 changes: 3 additions & 4 deletions third_party/libjingle/libjingle.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -898,13 +898,12 @@
'libjingle_webrtc_common',
],
'conditions': [
['libpeer_allocator_shim==1 and '
'libpeer_target_type!="static_library"', {
['libpeer_target_type!="static_library"', {
'sources': [
'overrides/initialize_module.cc',
],
'conditions': [
['OS!="mac"', {
['OS!="mac" and OS!="android"', {
'sources': [
'overrides/allocator_shim/allocator_proxy.cc',
],
Expand Down Expand Up @@ -936,7 +935,7 @@
['OS=="mac" and libpeer_target_type!="static_library"', {
'product_name': 'libpeerconnection',
}],
['OS=="android"', {
['OS=="android" and "<(libpeer_target_type)"=="static_library"', {
'standalone_static_library': 1,
}],
['OS=="linux" and libpeer_target_type!="static_library"', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#error "Only compile the allocator proxy with the shared_library implementation"
#endif

#if defined(OS_MACOSX)
#error "The allocator proxy isn't supported (or needed) on mac."
#if defined(OS_MACOSX) || defined(OS_ANDROID)
#error "The allocator proxy isn't supported (or needed) on mac or android."
#endif

extern AllocateFunction g_alloc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include "allocator_shim/allocator_stub.h"

#if defined(OS_MACOSX)
#error "The allocator stub isn't supported (or needed) on mac."
#if defined(OS_MACOSX) || defined(OS_ANDROID)
#error "The allocator stub isn't supported (or needed) on mac or android."
#endif

void* Allocate(std::size_t n) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "base/basictypes.h"

#if !defined(OS_MACOSX)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)

typedef void* (*AllocateFunction)(std::size_t);
typedef void (*DellocateFunction)(void*);
Expand All @@ -19,6 +19,6 @@ typedef void (*DellocateFunction)(void*);
void* Allocate(std::size_t n);
void Dellocate(void* p);

#endif // OS_MACOSX
#endif // OS_MACOSX && OS_ANDROID

#endif // THIRD_PARTY_LIBJINGLE_OVERRIDES_ALLOCATOR_SHIM_ALLOCATOR_STUB_H_
6 changes: 5 additions & 1 deletion third_party/libjingle/overrides/init_webrtc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ static base::FilePath GetLibPeerConnectionPath() {
CHECK(PathService::Get(base::DIR_MODULE, &path));
path = path.Append(FILE_PATH_LITERAL("Libraries"))
.Append(FILE_PATH_LITERAL("libpeerconnection.so"));
#elif defined(OS_ANDROID)
base::FilePath path;
CHECK(PathService::Get(base::DIR_MODULE, &path));
path = path.Append(FILE_PATH_LITERAL("libpeerconnection.so"));
#else
base::FilePath path;
CHECK(PathService::Get(base::DIR_MODULE, &path));
Expand Down Expand Up @@ -94,7 +98,7 @@ bool InitializeWebRtcModule() {
// PS: This function is actually implemented in allocator_proxy.cc with the
// new/delete overrides.
return initialize_module(*CommandLine::ForCurrentProcess(),
#if !defined(OS_MACOSX)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
&Allocate, &Dellocate,
#endif
logging::GetLogMessageHandler(),
Expand Down
2 changes: 1 addition & 1 deletion third_party/libjingle/overrides/init_webrtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef void (*DestroyWebRtcMediaEngineFunction)(
// to go through GetProcAddress et al and rely on specific name mangling.
typedef bool (*InitializeModuleFunction)(
const CommandLine& command_line,
#if !defined(OS_MACOSX)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
AllocateFunction alloc,
DellocateFunction dealloc,
#endif
Expand Down
6 changes: 3 additions & 3 deletions third_party/libjingle/overrides/initialize_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define ALLOC_EXPORT __attribute__((visibility("default")))
#endif

#if !defined(OS_MACOSX)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
// These are used by our new/delete overrides in
// allocator_shim/allocator_proxy.cc
AllocateFunction g_alloc = NULL;
Expand All @@ -44,7 +44,7 @@ extern "C" {
// Called from init_webrtc.cc.
ALLOC_EXPORT
bool InitializeModule(const CommandLine& command_line,
#if !defined(OS_MACOSX)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
AllocateFunction alloc,
DellocateFunction dealloc,
#endif
Expand All @@ -53,7 +53,7 @@ bool InitializeModule(const CommandLine& command_line,
webrtc::AddTraceEventPtr trace_add_trace_event,
CreateWebRtcMediaEngineFunction* create_media_engine,
DestroyWebRtcMediaEngineFunction* destroy_media_engine) {
#if !defined(OS_MACOSX)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
g_alloc = alloc;
g_dealloc = dealloc;
#endif
Expand Down

0 comments on commit 51d173f

Please sign in to comment.