summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Erat <derat@google.com>2015-07-07 08:31:05 -0600
committerDaniel Erat <derat@google.com>2015-07-08 10:21:39 -0600
commitb910a63ff3111067e79c016f40a7c1baac943405 (patch)
treeb4f367768d9a1e6f7048f961e6ce5752f850cadb
parentb8cf94937c52feb53b55c39e3f82094d27de464c (diff)
downloadlibchrome-b910a63ff3111067e79c016f40a7c1baac943405.tar.gz
Build libchrome as shared library on Android.
Add Android.mk and build_config.h files, along with stubs for gmock, gtest, and protobuf headers in the locations where Chromium expects them to be. Also patch a few source files so they'll build. Bug: 22317122 Change-Id: If4d603b35a23fe4b4caa678935f8ed8f4de6ca7c
-rw-r--r--Android.mk214
-rw-r--r--base/files/file_posix.cc4
-rw-r--r--base/message_loop/message_pump_libevent.cc7
-rw-r--r--base/strings/string_util.h4
-rw-r--r--base/testing/gmock/include/gmock/gmock.h1
-rw-r--r--base/testing/gtest/include/gtest/gtest_prod.h1
-rw-r--r--base/third_party/protobuf/src/google/protobuf/message_lite.h1
-rw-r--r--build/build_config.h177
8 files changed, 408 insertions, 1 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000000..57942b8e04
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,214 @@
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+# Common variables
+# ========================================================
+
+libchromeCommonCppExtension := .cc
+libchromeCommonCFlags := -D__BRILLO__ -Wall -Werror \
+ -Wno-char-subscripts -Wno-missing-field-initializers \
+ -Wno-unused-function -Wno-unused-parameter
+libchromeCommonCppFlags := -Wno-deprecated-register -Wno-non-virtual-dtor \
+ -Wno-sign-promo
+libchromeCommonCIncludes := \
+ external/gmock/include \
+ external/gtest/include
+libchromeCommonSharedLibraries := libevent
+libchromeCommonStaticLibraries :=
+
+# libchrome shared library for target
+# ========================================================
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libchrome
+LOCAL_SRC_FILES := \
+ base/allocator/type_profiler_control.cc \
+ base/at_exit.cc \
+ base/atomicops_internals_x86_gcc.cc \
+ base/base_switches.cc \
+ base/bind_helpers.cc \
+ base/build_time.cc \
+ base/callback_helpers.cc \
+ base/callback_internal.cc \
+ base/command_line.cc \
+ base/cpu.cc \
+ base/debug/alias.cc \
+ base/debug/debugger.cc \
+ base/debug/debugger_posix.cc \
+ base/debug/stack_trace.cc \
+ base/debug/stack_trace_posix.cc \
+ base/debug/task_annotator.cc \
+ base/environment.cc \
+ base/files/file.cc \
+ base/files/file_enumerator.cc \
+ base/files/file_enumerator_posix.cc \
+ base/files/file_path.cc \
+ base/files/file_path_constants.cc \
+ base/files/file_path_watcher.cc \
+ base/files/file_path_watcher_linux.cc \
+ base/files/file_posix.cc \
+ base/files/file_tracing.cc \
+ base/files/file_util.cc \
+ base/files/file_util_linux.cc \
+ base/files/file_util_posix.cc \
+ base/files/important_file_writer.cc \
+ base/files/scoped_file.cc \
+ base/files/scoped_temp_dir.cc \
+ base/guid.cc \
+ base/guid_posix.cc \
+ base/hash.cc \
+ base/json/json_parser.cc \
+ base/json/json_reader.cc \
+ base/json/json_string_value_serializer.cc \
+ base/json/json_writer.cc \
+ base/json/string_escape.cc \
+ base/lazy_instance.cc \
+ base/location.cc \
+ base/logging.cc \
+ base/md5.cc \
+ base/memory/ref_counted.cc \
+ base/memory/ref_counted_memory.cc \
+ base/memory/singleton.cc \
+ base/memory/weak_ptr.cc \
+ base/message_loop/incoming_task_queue.cc \
+ base/message_loop/message_loop.cc \
+ base/message_loop/message_loop_proxy.cc \
+ base/message_loop/message_loop_proxy_impl.cc \
+ base/message_loop/message_pump.cc \
+ base/message_loop/message_pump_default.cc \
+ base/message_loop/message_pump_libevent.cc \
+ base/metrics/bucket_ranges.cc \
+ base/metrics/field_trial.cc \
+ base/metrics/histogram_base.cc \
+ base/metrics/histogram.cc \
+ base/metrics/histogram_samples.cc \
+ base/metrics/histogram_snapshot_manager.cc \
+ base/metrics/sample_map.cc \
+ base/metrics/sample_vector.cc \
+ base/metrics/sparse_histogram.cc \
+ base/metrics/statistics_recorder.cc \
+ base/pending_task.cc \
+ base/pickle.cc \
+ base/posix/file_descriptor_shuffle.cc \
+ base/posix/safe_strerror.cc \
+ base/posix/unix_domain_socket_linux.cc \
+ base/process/internal_linux.cc \
+ base/process/kill.cc \
+ base/process/kill_posix.cc \
+ base/process/launch.cc \
+ base/process/launch_posix.cc \
+ base/process/process_handle_linux.cc \
+ base/process/process_handle_posix.cc \
+ base/process/process_iterator.cc \
+ base/process/process_iterator_linux.cc \
+ base/process/process_metrics.cc \
+ base/process/process_metrics_linux.cc \
+ base/process/process_metrics_posix.cc \
+ base/process/process_posix.cc \
+ base/profiler/alternate_timer.cc \
+ base/profiler/scoped_profile.cc \
+ base/profiler/scoped_tracker.cc \
+ base/profiler/tracked_time.cc \
+ base/rand_util.cc \
+ base/rand_util_posix.cc \
+ base/run_loop.cc \
+ base/sequence_checker_impl.cc \
+ base/sequenced_task_runner.cc \
+ base/sha1_portable.cc \
+ base/strings/safe_sprintf.cc \
+ base/strings/string16.cc \
+ base/strings/string_number_conversions.cc \
+ base/strings/string_piece.cc \
+ base/strings/stringprintf.cc \
+ base/strings/string_split.cc \
+ base/strings/string_util.cc \
+ base/strings/string_util_constants.cc \
+ base/strings/sys_string_conversions_posix.cc \
+ base/strings/utf_string_conversions.cc \
+ base/strings/utf_string_conversion_utils.cc \
+ base/synchronization/cancellation_flag.cc \
+ base/synchronization/condition_variable_posix.cc \
+ base/synchronization/lock.cc \
+ base/synchronization/lock_impl_posix.cc \
+ base/synchronization/waitable_event_posix.cc \
+ base/sync_socket_posix.cc \
+ base/sys_info.cc \
+ base/sys_info_chromeos.cc \
+ base/sys_info_linux.cc \
+ base/sys_info_posix.cc \
+ base/task/cancelable_task_tracker.cc \
+ base/task_runner.cc \
+ base/third_party/dmg_fp/dtoa.cc \
+ base/third_party/dmg_fp/g_fmt.cc \
+ base/third_party/dynamic_annotations/dynamic_annotations.c \
+ base/third_party/icu/icu_utf.cc \
+ base/third_party/nspr/prtime.cc \
+ base/third_party/superfasthash/superfasthash.c \
+ base/threading/non_thread_safe_impl.cc \
+ base/threading/platform_thread_internal_posix.cc \
+ base/threading/platform_thread_linux.cc \
+ base/threading/platform_thread_posix.cc \
+ base/threading/post_task_and_reply_impl.cc \
+ base/threading/sequenced_worker_pool.cc \
+ base/threading/simple_thread.cc \
+ base/threading/thread.cc \
+ base/threading/thread_checker_impl.cc \
+ base/threading/thread_collision_warner.cc \
+ base/threading/thread_id_name_manager.cc \
+ base/threading/thread_local_posix.cc \
+ base/threading/thread_local_storage.cc \
+ base/threading/thread_local_storage_posix.cc \
+ base/threading/thread_restrictions.cc \
+ base/threading/worker_pool.cc \
+ base/threading/worker_pool_posix.cc \
+ base/thread_task_runner_handle.cc \
+ base/time/clock.cc \
+ base/time/default_clock.cc \
+ base/time/default_tick_clock.cc \
+ base/timer/elapsed_timer.cc \
+ base/timer/timer.cc \
+ base/time/tick_clock.cc \
+ base/time/time.cc \
+ base/time/time_posix.cc \
+ base/trace_event/malloc_dump_provider.cc \
+ base/trace_event/memory_allocator_dump.cc \
+ base/trace_event/memory_allocator_dump_guid.cc \
+ base/trace_event/memory_dump_manager.cc \
+ base/trace_event/memory_dump_session_state.cc \
+ base/trace_event/process_memory_dump.cc \
+ base/trace_event/process_memory_maps.cc \
+ base/trace_event/process_memory_maps_dump_provider.cc \
+ base/trace_event/process_memory_totals.cc \
+ base/trace_event/process_memory_totals_dump_provider.cc \
+ base/trace_event/trace_config.cc \
+ base/trace_event/trace_event_argument.cc \
+ base/trace_event/trace_event_impl.cc \
+ base/trace_event/trace_event_impl_constants.cc \
+ base/trace_event/trace_event_memory.cc \
+ base/trace_event/trace_event_memory_overhead.cc \
+ base/trace_event/trace_event_synthetic_delay.cc \
+ base/tracked_objects.cc \
+ base/tracking_info.cc \
+ base/values.cc \
+ base/vlog.cc
+LOCAL_CPP_EXTENSION := $(libchromeCommonCppExtension)
+LOCAL_CFLAGS := $(libchromeCommonCFlags)
+LOCAL_CPPFLAGS := $(libchromeCommonCppFlags)
+LOCAL_C_INCLUDES := $(libchromeCommonCIncludes)
+LOCAL_SHARED_LIBRARIES := $(libchromeCommonSharedLibraries)
+LOCAL_STATIC_LIBRARIES := $(libchromeCommonStaticLibraries)
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+include $(BUILD_SHARED_LIBRARY)
diff --git a/base/files/file_posix.cc b/base/files/file_posix.cc
index bb49d2dd73..129f5faf4b 100644
--- a/base/files/file_posix.cc
+++ b/base/files/file_posix.cc
@@ -183,7 +183,9 @@ int64 File::Seek(Whence whence, int64 offset) {
SCOPED_FILE_TRACE_WITH_SIZE("Seek", offset);
-#if defined(OS_ANDROID)
+// Additionally check __BIONIC__ since older versions of Android don't define
+// _FILE_OFFSET_BITS.
+#if _FILE_OFFSET_BITS != 64 || defined(__BIONIC__)
COMPILE_ASSERT(sizeof(int64) == sizeof(off64_t), off64_t_64_bit);
return lseek64(file_.get(), static_cast<off64_t>(offset),
static_cast<int>(whence));
diff --git a/base/message_loop/message_pump_libevent.cc b/base/message_loop/message_pump_libevent.cc
index b5b1fb7e81..66296e3999 100644
--- a/base/message_loop/message_pump_libevent.cc
+++ b/base/message_loop/message_pump_libevent.cc
@@ -16,7 +16,14 @@
#include "base/posix/eintr_wrapper.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
+
+#if defined(__BRILLO__)
+#include <event2/event.h>
+#include <event2/event_compat.h>
+#include <event2/event_struct.h>
+#else
#include "third_party/libevent/event.h"
+#endif
#if defined(OS_MACOSX)
#include "base/mac/scoped_nsautorelease_pool.h"
diff --git a/base/strings/string_util.h b/base/strings/string_util.h
index 9628c67cbe..027c6b675c 100644
--- a/base/strings/string_util.h
+++ b/base/strings/string_util.h
@@ -19,6 +19,10 @@
#include "base/strings/string16.h"
#include "base/strings/string_piece.h" // For implicit conversions.
+// On Android, bionic's stdio.h defines an snprintf macro when being built with
+// clang. Undefine it here so it won't collide with base::snprintf().
+#undef snprintf
+
namespace base {
// C standard-library functions like "strncasecmp" and "snprintf" that aren't
diff --git a/base/testing/gmock/include/gmock/gmock.h b/base/testing/gmock/include/gmock/gmock.h
new file mode 100644
index 0000000000..9678b68bd1
--- /dev/null
+++ b/base/testing/gmock/include/gmock/gmock.h
@@ -0,0 +1 @@
+#include <gmock/gmock.h>
diff --git a/base/testing/gtest/include/gtest/gtest_prod.h b/base/testing/gtest/include/gtest/gtest_prod.h
new file mode 100644
index 0000000000..00174fc47a
--- /dev/null
+++ b/base/testing/gtest/include/gtest/gtest_prod.h
@@ -0,0 +1 @@
+#include <gtest/gtest_prod.h>
diff --git a/base/third_party/protobuf/src/google/protobuf/message_lite.h b/base/third_party/protobuf/src/google/protobuf/message_lite.h
new file mode 100644
index 0000000000..c472844141
--- /dev/null
+++ b/base/third_party/protobuf/src/google/protobuf/message_lite.h
@@ -0,0 +1 @@
+#include <google/protobuf/message_lite.h>
diff --git a/build/build_config.h b/build/build_config.h
new file mode 100644
index 0000000000..acd28d9edb
--- /dev/null
+++ b/build/build_config.h
@@ -0,0 +1,177 @@
+// Copyright (c) 2012 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 adds defines about the platform we're currently building on.
+// Operating System:
+// OS_WIN / OS_MACOSX / OS_LINUX / OS_POSIX (MACOSX or LINUX) /
+// OS_NACL (NACL_SFI or NACL_NONSFI) / OS_NACL_SFI / OS_NACL_NONSFI
+// Compiler:
+// COMPILER_MSVC / COMPILER_GCC
+// Processor:
+// ARCH_CPU_X86 / ARCH_CPU_X86_64 / ARCH_CPU_X86_FAMILY (X86 or X86_64)
+// ARCH_CPU_32_BITS / ARCH_CPU_64_BITS
+
+#ifndef BUILD_BUILD_CONFIG_H_
+#define BUILD_BUILD_CONFIG_H_
+
+// Add Brillo-specific defines.
+#if defined(__BRILLO__)
+#define __linux__ 1
+#define __UCLIBC__ 1
+#define OS_CHROMEOS 1
+// Unset ANDROID, which is just used for building Chrome on Android.
+#undef ANDROID
+#endif
+
+// A set of macros to use for platform detection.
+#if defined(__native_client__)
+// __native_client__ must be first, so that other OS_ defines are not set.
+#define OS_NACL 1
+// OS_NACL comes in two sandboxing technology flavors, SFI or Non-SFI.
+// PNaCl toolchain defines __native_client_nonsfi__ macro in Non-SFI build
+// mode, while it does not in SFI build mode.
+#if defined(__native_client_nonsfi__)
+#define OS_NACL_NONSFI
+#else
+#define OS_NACL_SFI
+#endif
+#elif defined(ANDROID)
+#define OS_ANDROID 1
+#elif defined(__APPLE__)
+// only include TargetConditions after testing ANDROID as some android builds
+// on mac don't have this header available and it's not needed unless the target
+// is really mac/ios.
+#include <TargetConditionals.h>
+#define OS_MACOSX 1
+#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
+#define OS_IOS 1
+#endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
+#elif defined(__linux__)
+#define OS_LINUX 1
+// include a system header to pull in features.h for glibc/uclibc macros.
+#include <unistd.h>
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+// we really are using glibc, not uClibc pretending to be glibc
+#define LIBC_GLIBC 1
+#endif
+#elif defined(_WIN32)
+#define OS_WIN 1
+#define TOOLKIT_VIEWS 1
+#elif defined(__FreeBSD__)
+#define OS_FREEBSD 1
+#elif defined(__OpenBSD__)
+#define OS_OPENBSD 1
+#elif defined(__sun)
+#define OS_SOLARIS 1
+#elif defined(__QNXNTO__)
+#define OS_QNX 1
+#else
+#error Please add support for your platform in build/build_config.h
+#endif
+
+#if defined(USE_OPENSSL) && defined(USE_NSS)
+#error Cannot use both OpenSSL and NSS
+#endif
+
+// For access to standard BSD features, use OS_BSD instead of a
+// more specific macro.
+#if defined(OS_FREEBSD) || defined(OS_OPENBSD)
+#define OS_BSD 1
+#endif
+
+// For access to standard POSIXish features, use OS_POSIX instead of a
+// more specific macro.
+#if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_FREEBSD) || \
+ defined(OS_OPENBSD) || defined(OS_SOLARIS) || defined(OS_ANDROID) || \
+ defined(OS_NACL) || defined(OS_QNX)
+#define OS_POSIX 1
+#endif
+
+// Use tcmalloc
+#if (defined(OS_WIN) || defined(OS_LINUX) || defined(OS_ANDROID)) && \
+ !defined(NO_TCMALLOC)
+#define USE_TCMALLOC 1
+#endif
+
+// Compiler detection.
+#if defined(__GNUC__)
+#define COMPILER_GCC 1
+#elif defined(_MSC_VER)
+#define COMPILER_MSVC 1
+#else
+#error Please add support for your compiler in build/build_config.h
+#endif
+
+// Processor architecture detection. For more info on what's defined, see:
+// http://msdn.microsoft.com/en-us/library/b0084kay.aspx
+// http://www.agner.org/optimize/calling_conventions.pdf
+// or with gcc, run: "echo | gcc -E -dM -"
+#if defined(_M_X64) || defined(__x86_64__)
+#define ARCH_CPU_X86_FAMILY 1
+#define ARCH_CPU_X86_64 1
+#define ARCH_CPU_64_BITS 1
+#define ARCH_CPU_LITTLE_ENDIAN 1
+#elif defined(_M_IX86) || defined(__i386__)
+#define ARCH_CPU_X86_FAMILY 1
+#define ARCH_CPU_X86 1
+#define ARCH_CPU_32_BITS 1
+#define ARCH_CPU_LITTLE_ENDIAN 1
+#elif defined(__ARMEL__)
+#define ARCH_CPU_ARM_FAMILY 1
+#define ARCH_CPU_ARMEL 1
+#define ARCH_CPU_32_BITS 1
+#define ARCH_CPU_LITTLE_ENDIAN 1
+#elif defined(__aarch64__)
+#define ARCH_CPU_ARM_FAMILY 1
+#define ARCH_CPU_ARM64 1
+#define ARCH_CPU_64_BITS 1
+#define ARCH_CPU_LITTLE_ENDIAN 1
+#elif defined(__pnacl__)
+#define ARCH_CPU_32_BITS 1
+#define ARCH_CPU_LITTLE_ENDIAN 1
+#elif defined(__MIPSEL__)
+#if defined(__LP64__)
+#define ARCH_CPU_MIPS64_FAMILY 1
+#define ARCH_CPU_MIPS64EL 1
+#define ARCH_CPU_64_BITS 1
+#define ARCH_CPU_LITTLE_ENDIAN 1
+#else
+#define ARCH_CPU_MIPS_FAMILY 1
+#define ARCH_CPU_MIPSEL 1
+#define ARCH_CPU_32_BITS 1
+#define ARCH_CPU_LITTLE_ENDIAN 1
+#endif
+#else
+#error Please add support for your architecture in build/build_config.h
+#endif
+
+// Type detection for wchar_t.
+#if defined(OS_WIN)
+#define WCHAR_T_IS_UTF16
+#elif defined(OS_POSIX) && defined(COMPILER_GCC) && \
+ defined(__WCHAR_MAX__) && \
+ (__WCHAR_MAX__ == 0x7fffffff || __WCHAR_MAX__ == 0xffffffff)
+#define WCHAR_T_IS_UTF32
+#elif defined(OS_POSIX) && defined(COMPILER_GCC) && \
+ defined(__WCHAR_MAX__) && \
+ (__WCHAR_MAX__ == 0x7fff || __WCHAR_MAX__ == 0xffff)
+// On Posix, we'll detect short wchar_t, but projects aren't guaranteed to
+// compile in this mode (in particular, Chrome doesn't). This is intended for
+// other projects using base who manage their own dependencies and make sure
+// short wchar works for them.
+#define WCHAR_T_IS_UTF16
+#else
+#error Please add support for your compiler in build/build_config.h
+#endif
+
+#if defined(OS_ANDROID)
+// The compiler thinks std::string::const_iterator and "const char*" are
+// equivalent types.
+#define STD_STRING_ITERATOR_IS_CHAR_POINTER
+// The compiler thinks base::string16::const_iterator and "char16*" are
+// equivalent types.
+#define BASE_STRING16_ITERATOR_IS_CHAR16_POINTER
+#endif
+
+#endif // BUILD_BUILD_CONFIG_H_