Commit cad816ee authored by qsr's avatar qsr Committed by Commit bot

[Android] Fix gn build for instrumentation tests.

This fixes the following issue:
- allow forwarder2 to compile with clang
- Makes android executables position independant so that they can be run
  on android devices
- Add missing BUILD.gn

TBR=brettw@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#302429}
parent 33c932b4
# 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.
import("//build/config/android/rules.gni")
group("commands") {
datadeps = [
":chromium_commands",
]
}
# GYP: //build/android/pylib/device/commands/commands.gyp:chromium_commands
android_library("chromium_commands") {
java_files = [ "java/src/org/chromium/android/commands/unzip/Unzip.java" ]
dex_path = "$root_build_dir/lib.java/chromium_commands.dex.jar"
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
{ {
'targets': [ 'targets': [
{ {
# GN version: //build/android/pylib/devices/commands:chromium_commands
'target_name': 'chromium_commands', 'target_name': 'chromium_commands',
'type': 'none', 'type': 'none',
'variables': { 'variables': {
......
...@@ -434,6 +434,9 @@ if (is_win) { ...@@ -434,6 +434,9 @@ if (is_win) {
"//build/config/mac:mac_executable_flags" ] "//build/config/mac:mac_executable_flags" ]
} else if (is_linux || is_android) { } else if (is_linux || is_android) {
_executable_configs += [ "//build/config/gcc:executable_ldconfig" ] _executable_configs += [ "//build/config/gcc:executable_ldconfig" ]
if (is_android) {
_executable_configs += [ "//build/config/android:executable_config" ]
}
} }
set_defaults("executable") { set_defaults("executable") {
configs = _executable_configs configs = _executable_configs
......
...@@ -18,3 +18,8 @@ config("sdk") { ...@@ -18,3 +18,8 @@ config("sdk") {
] ]
} }
} }
config("executable_config") {
cflags = [ "-fPIE" ]
ldflags = [ "-pie" ]
}
...@@ -685,7 +685,11 @@ template("android_library") { ...@@ -685,7 +685,11 @@ template("android_library") {
_base_path = "$target_gen_dir/$target_name" _base_path = "$target_gen_dir/$target_name"
_build_config = _base_path + ".build_config" _build_config = _base_path + ".build_config"
_jar_path = _base_path + ".jar" _jar_path = _base_path + ".jar"
if (defined(invoker.dex_path)) {
_dex_path = invoker.dex_path
} else {
_dex_path = _base_path + ".dex.jar" _dex_path = _base_path + ".dex.jar"
}
write_build_config("${target_name}__build_config") { write_build_config("${target_name}__build_config") {
type = "android_library" type = "android_library"
...@@ -1075,6 +1079,7 @@ template("android_apk") { ...@@ -1075,6 +1079,7 @@ template("android_apk") {
} }
if (_dist_jar_path != "") { if (_dist_jar_path != "") {
final_deps += [ ":${_template_name}__create_dist_jar" ]
# TODO(cjhopman): This is only ever needed to calculate the list of tests to # TODO(cjhopman): This is only ever needed to calculate the list of tests to
# run. See build/android/pylib/instrumentation/test_jar.py. We should be # run. See build/android/pylib/instrumentation/test_jar.py. We should be
# able to just do that calculation at build time instead. # able to just do that calculation at build time instead.
...@@ -1248,6 +1253,7 @@ template("unittest_apk") { ...@@ -1248,6 +1253,7 @@ template("unittest_apk") {
deps += invoker.deps deps += invoker.deps
} }
datadeps = [ datadeps = [
"//tools/android/forwarder2",
"//tools/android/md5sum", "//tools/android/md5sum",
] ]
} }
......
# 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.
# GYP: //tools/android/common/common.gyp:android_tools_common
source_set("common") {
sources = [
"adb_connection.cc",
"adb_connection.h",
"daemon.cc",
"daemon.h",
"net.cc",
"net.h",
]
}
...@@ -34,7 +34,6 @@ int ConnectAdbHostSocket(const char* forward_to) { ...@@ -34,7 +34,6 @@ int ConnectAdbHostSocket(const char* forward_to) {
// HHHH is the hexidecimal length of the "tcp:port:address" part. // HHHH is the hexidecimal length of the "tcp:port:address" part.
const size_t kBufferMaxLength = 30; const size_t kBufferMaxLength = 30;
const size_t kLengthOfLength = 4; const size_t kLengthOfLength = 4;
const size_t kAddressMaxLength = kBufferMaxLength - kLengthOfLength;
const char kAddressPrefix[] = { 't', 'c', 'p', ':' }; const char kAddressPrefix[] = { 't', 'c', 'p', ':' };
size_t address_length = arraysize(kAddressPrefix) + strlen(forward_to); size_t address_length = arraysize(kAddressPrefix) + strlen(forward_to);
...@@ -89,7 +88,7 @@ int ConnectAdbHostSocket(const char* forward_to) { ...@@ -89,7 +88,7 @@ int ConnectAdbHostSocket(const char* forward_to) {
bytes_remaining -= ret; bytes_remaining -= ret;
} }
const size_t kAdbStatusLength = 4; const int kAdbStatusLength = 4;
char response[kBufferMaxLength]; char response[kBufferMaxLength];
int response_length = HANDLE_EINTR(recv(host_socket, response, int response_length = HANDLE_EINTR(recv(host_socket, response,
kBufferMaxLength, 0)); kBufferMaxLength, 0));
......
...@@ -3,8 +3,12 @@ ...@@ -3,8 +3,12 @@
# found in the LICENSE file. # found in the LICENSE file.
{ {
'variables': {
'chromium_code': 1,
},
'targets': [ 'targets': [
{ {
# GN version: //tools/android/common
'target_name': 'android_tools_common', 'target_name': 'android_tools_common',
'type': 'static_library', 'type': 'static_library',
'toolsets': ['host', 'target'], 'toolsets': ['host', 'target'],
......
...@@ -25,7 +25,7 @@ int DeferAccept(int socket) { ...@@ -25,7 +25,7 @@ int DeferAccept(int socket) {
std::string DumpBinary(const char* buffer, size_t length) { std::string DumpBinary(const char* buffer, size_t length) {
std::string result = "["; std::string result = "[";
for (int i = 0; i < length; ++i) { for (size_t i = 0; i < length; ++i) {
base::StringAppendF(&result, "%02x,", base::StringAppendF(&result, "%02x,",
static_cast<unsigned char>(buffer[i])); static_cast<unsigned char>(buffer[i]));
} }
......
# 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.
# GYP: //tools/android/forwarder2/forwarder.gyp:forwarder2
group("forwarder2") {
datadeps = [
":host_forwarder($host_toolchain)",
":host_forwarder_copy($host_toolchain)",
":device_forwarder($default_toolchain)",
":device_forwarder_prepare_dist($default_toolchain)",
]
}
if (current_toolchain == default_toolchain) {
import("//build/config/android/rules.gni")
# GYP: //tools/android/forwarder2/forwarder.gyp:device_forwarder
executable("device_forwarder") {
sources = [
"command.cc",
"command.h",
"common.cc",
"common.h",
"daemon.cc",
"daemon.h",
"device_controller.cc",
"device_controller.h",
"device_forwarder_main.cc",
"device_listener.cc",
"device_listener.h",
"forwarder.cc",
"forwarder.h",
"forwarders_manager.cc",
"forwarders_manager.h",
"pipe_notifier.cc",
"pipe_notifier.h",
"self_deleter_helper.h",
"socket.cc",
"socket.h",
"util.h",
]
deps = [
"//base",
"//tools/android/common",
]
datadeps = [
"//build/android/pylib/device/commands",
]
}
# GYP: //tools/android/forwarder2/forwarder.gyp:forwarder2
create_native_executable_dist("device_forwarder_prepare_dist") {
dist_dir = "$root_build_dir/forwarder_dist"
binary = "$root_build_dir/exe.stripped/device_forwarder"
}
}
if (current_toolchain != default_toolchain) {
# GYP: //tools/android/forwarder2/forwarder.gyp:host_forwarder
executable("host_forwarder") {
sources = [
"command.cc",
"command.h",
"common.cc",
"common.h",
"daemon.cc",
"daemon.h",
"forwarder.cc",
"forwarder.h",
"forwarders_manager.cc",
"forwarders_manager.h",
"host_controller.cc",
"host_controller.h",
"host_forwarder_main.cc",
"pipe_notifier.cc",
"pipe_notifier.h",
"self_deleter_helper.h",
"socket.cc",
"socket.h",
"util.h",
]
deps = [
"//base",
"//tools/android/common",
]
}
# GYP: //tools/android/forwarder2/forwarder.gyp:forwarder2
copy("host_forwarder_copy") {
sources = ["$root_out_dir/host_forwarder"]
outputs = ["$root_build_dir/host_forwarder"]
}
}
...@@ -98,31 +98,6 @@ void SigChildHandler(int signal_number) { ...@@ -98,31 +98,6 @@ void SigChildHandler(int signal_number) {
SIGNAL_SAFE_LOG(ERROR, string_builder.buffer()); SIGNAL_SAFE_LOG(ERROR, string_builder.buffer());
} }
// Note that 0 is written to |lock_owner_pid| in case the file is not locked.
bool GetFileLockOwnerPid(int fd, pid_t* lock_owner_pid) {
struct flock lock_info = {};
lock_info.l_type = F_WRLCK;
lock_info.l_whence = SEEK_CUR;
const int ret = HANDLE_EINTR(fcntl(fd, F_GETLK, &lock_info));
if (ret < 0) {
if (errno == EBADF) {
// Assume that the provided file descriptor corresponding to the PID file
// was valid until the daemon removed this file.
*lock_owner_pid = 0;
return true;
}
PError("fcntl");
return false;
}
if (lock_info.l_type == F_UNLCK) {
*lock_owner_pid = 0;
return true;
}
CHECK_EQ(F_WRLCK /* exclusive lock */, lock_info.l_type);
*lock_owner_pid = lock_info.l_pid;
return true;
}
scoped_ptr<Socket> ConnectToUnixDomainSocket( scoped_ptr<Socket> ConnectToUnixDomainSocket(
const std::string& socket_name, const std::string& socket_name,
int tries_count, int tries_count,
......
...@@ -124,7 +124,7 @@ class ClientDelegate : public Daemon::ClientDelegate { ...@@ -124,7 +124,7 @@ class ClientDelegate : public Daemon::ClientDelegate {
const int bytes_read = daemon_socket->Read( const int bytes_read = daemon_socket->Read(
buf, sizeof(buf) - 1 /* leave space for null terminator */); buf, sizeof(buf) - 1 /* leave space for null terminator */);
CHECK_GT(bytes_read, 0); CHECK_GT(bytes_read, 0);
DCHECK(bytes_read < sizeof(buf)); DCHECK(static_cast<unsigned int>(bytes_read) < sizeof(buf));
buf[bytes_read] = 0; buf[bytes_read] = 0;
base::StringPiece msg(buf, bytes_read); base::StringPiece msg(buf, bytes_read);
if (msg.starts_with("ERROR")) { if (msg.starts_with("ERROR")) {
......
...@@ -25,10 +25,10 @@ const int kBufferSize = 32 * 1024; ...@@ -25,10 +25,10 @@ const int kBufferSize = 32 * 1024;
// //
// These objects are used in a pair to handle duplex traffic, as in: // These objects are used in a pair to handle duplex traffic, as in:
// //
// ------> [BufferedCopier_1] ---> // -------> [BufferedCopier_1] --->
// / \ // | |
// socket_1 * * socket_2 // socket_1 * * socket_2
// \ / // | |
// <------ [BufferedCopier_2] <---- // <------ [BufferedCopier_2] <----
// //
// When a BufferedCopier is in the READING state (see below), it only listens // When a BufferedCopier is in the READING state (see below), it only listens
......
...@@ -3,8 +3,12 @@ ...@@ -3,8 +3,12 @@
# found in the LICENSE file. # found in the LICENSE file.
{ {
'variables': {
'chromium_code': 1,
},
'targets': [ 'targets': [
{ {
# GN version: //tools/android/forwarder2
'target_name': 'forwarder2', 'target_name': 'forwarder2',
'type': 'none', 'type': 'none',
'dependencies': [ 'dependencies': [
...@@ -20,6 +24,7 @@ ...@@ -20,6 +24,7 @@
'includes': ['../../../build/android/native_app_dependencies.gypi'], 'includes': ['../../../build/android/native_app_dependencies.gypi'],
}, },
{ {
# GN version: //tools/android/forwarder2:device_forwarder
'target_name': 'device_forwarder', 'target_name': 'device_forwarder',
'type': 'executable', 'type': 'executable',
'toolsets': ['target'], 'toolsets': ['target'],
...@@ -45,6 +50,7 @@ ...@@ -45,6 +50,7 @@
], ],
}, },
{ {
# GN version: //tools/android/forwarder2:host_forwarder
'target_name': 'host_forwarder', 'target_name': 'host_forwarder',
'type': 'executable', 'type': 'executable',
'toolsets': ['host'], 'toolsets': ['host'],
......
...@@ -81,7 +81,7 @@ void ForwardersManager::WaitForEventsOnInternalThread() { ...@@ -81,7 +81,7 @@ void ForwardersManager::WaitForEventsOnInternalThread() {
deletion_notifier_.receiver_fd(), deletion_notifier_.receiver_fd(),
}; };
for (int i = 0; i < arraysize(notifier_fds); ++i) { for (size_t i = 0; i < arraysize(notifier_fds); ++i) {
const int notifier_fd = notifier_fds[i]; const int notifier_fd = notifier_fds[i];
DCHECK_GT(notifier_fd, -1); DCHECK_GT(notifier_fd, -1);
FD_SET(notifier_fd, &read_fds); FD_SET(notifier_fd, &read_fds);
......
...@@ -49,9 +49,6 @@ namespace { ...@@ -49,9 +49,6 @@ namespace {
const char kLogFilePath[] = "/tmp/host_forwarder_log"; const char kLogFilePath[] = "/tmp/host_forwarder_log";
const char kDaemonIdentifier[] = "chrome_host_forwarder_daemon"; const char kDaemonIdentifier[] = "chrome_host_forwarder_daemon";
const char kKillServerCommand[] = "kill-server";
const char kForwardCommand[] = "forward";
const int kBufSize = 256; const int kBufSize = 256;
// Needs to be global to be able to be accessed from the signal handler. // Needs to be global to be able to be accessed from the signal handler.
...@@ -364,14 +361,14 @@ class ClientDelegate : public Daemon::ClientDelegate { ...@@ -364,14 +361,14 @@ class ClientDelegate : public Daemon::ClientDelegate {
// Daemon::ClientDelegate: // Daemon::ClientDelegate:
virtual void OnDaemonReady(Socket* daemon_socket) override { virtual void OnDaemonReady(Socket* daemon_socket) override {
// Send the forward command to the daemon. // Send the forward command to the daemon.
CHECK_EQ(command_pickle_.size(), CHECK_EQ(static_cast<long>(command_pickle_.size()),
daemon_socket->WriteNumBytes(command_pickle_.data(), daemon_socket->WriteNumBytes(command_pickle_.data(),
command_pickle_.size())); command_pickle_.size()));
char buf[kBufSize]; char buf[kBufSize];
const int bytes_read = daemon_socket->Read( const int bytes_read = daemon_socket->Read(
buf, sizeof(buf) - 1 /* leave space for null terminator */); buf, sizeof(buf) - 1 /* leave space for null terminator */);
CHECK_GT(bytes_read, 0); CHECK_GT(bytes_read, 0);
DCHECK(bytes_read < sizeof(buf)); DCHECK(static_cast<size_t>(bytes_read) < sizeof(buf));
buf[bytes_read] = 0; buf[bytes_read] = 0;
base::StringPiece msg(buf, bytes_read); base::StringPiece msg(buf, bytes_read);
if (msg.starts_with("ERROR")) { if (msg.starts_with("ERROR")) {
......
...@@ -291,7 +291,7 @@ int Socket::GetPort() { ...@@ -291,7 +291,7 @@ int Socket::GetPort() {
} }
int Socket::ReadNumBytes(void* buffer, size_t num_bytes) { int Socket::ReadNumBytes(void* buffer, size_t num_bytes) {
int bytes_read = 0; size_t bytes_read = 0;
int ret = 1; int ret = 1;
while (bytes_read < num_bytes && ret > 0) { while (bytes_read < num_bytes && ret > 0) {
ret = Read(static_cast<char*>(buffer) + bytes_read, num_bytes - bytes_read); ret = Read(static_cast<char*>(buffer) + bytes_read, num_bytes - bytes_read);
...@@ -380,7 +380,7 @@ bool Socket::DidReceiveEvent() const { ...@@ -380,7 +380,7 @@ bool Socket::DidReceiveEvent() const {
} }
int Socket::WriteNumBytes(const void* buffer, size_t num_bytes) { int Socket::WriteNumBytes(const void* buffer, size_t num_bytes) {
int bytes_written = 0; size_t bytes_written = 0;
int ret = 1; int ret = 1;
while (bytes_written < num_bytes && ret > 0) { while (bytes_written < num_bytes && ret > 0) {
ret = Write(static_cast<const char*>(buffer) + bytes_written, ret = Write(static_cast<const char*>(buffer) + bytes_written,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment