Commit graph

94 commits

Author SHA1 Message Date
Elliott Hughes
7bc87a5a78 Move init's kernel logging into libbase.
This will let other stuff (such as adbd and recovery) use it too.

Bug: http://b/28467098
Change-Id: Idab51f438ed3edd6fe65a56c4b396eaff5f3833e
2016-08-04 16:09:39 -07:00
Elliott Hughes
e5dd71a290 libbase should use its own logging!
Not doing so led to us using a bogus log tag.

Bug: http://b/30281203
Change-Id: I3ac91758a1a043146c65f2ae0f36fcfbe372c30f
2016-07-28 15:15:28 -07:00
Colin Cross
fc06bd0ca3 Convert libbase Android.mk to Android.bp
Change-Id: I429d0a06c5138c3e54c9d25f15adb3e2647496e1
2016-07-11 14:23:32 -07:00
Elliott Hughes
4e5fd111d8 Add timestamps to libbase's stderr logging.
adb is the client that wants this, but I'm not aware of any client that
doesn't.

Bug: http://b/28467098
Test: tested manually with cat.
Change-Id: I82c3f7ddf466a67aedfbb9010e0939a44b71d3e5
2016-06-21 14:27:16 -07:00
Chih-Hung Hsieh
c713bce901 Fix misc-macro-parentheses warnings in init and other core modules.
Bug: 28705665
Change-Id: Ice67cebb8c42538f8fb9cf1756678f41a9d68a31
2016-05-18 18:11:49 -07:00
Josh Gao
13ea01db45 adb/base: allow use of unique_fd inside adb.
adb implements its own file descriptor emulation layer on Windows,
which requires the use of adb_close instead of close throughout the
codebase. Add a template argument to unique_fd that allows for this.

Bug: http://b/28347842
Change-Id: I6397261f4973d49f2f8e04257bf67b348585bb63
2016-05-14 18:25:51 -07:00
Christopher Wiley
2a7b86337f Don't include android-base/macros.h from android-base/unique_fd.h
This prevents a ton of macro collisions when libfoo includes libbinder
includes unique_fd.h.

Bug: 27804373
Change-Id: Ide834afb1052b32e86fad3fcba10cff3dafeb899
2016-04-19 14:45:48 -07:00
Christopher Wiley
ec9ea66a2b Define LIKELY and UNLIKELY in a vendor friendly way
This prevents macro conflicts with vendor code.

Bug: 27804373
Change-Id: I759c2b7b611203d0afdc35ddd5c2adb8f942ea17
Test: Compiles when libbinder include path changes to include libbase.
2016-04-18 16:08:19 -07:00
Elliott Hughes
2c5d1d7cd9 Add operator int() to unique_fd.
Change-Id: I7512559be7befbb8772d5529e06550267a2f1543
2016-03-28 12:15:36 -07:00
Elliott Hughes
3761365735 Merge "Fix <android-base/*.h> header guards." 2016-03-26 16:08:59 +00:00
Elliott Hughes
19388fc312 Merge "Copy the good comment and warn_unused_result from ScopedFd to unique_fd." 2016-03-26 15:53:20 +00:00
Elliott Hughes
54c72aaccc Fix <android-base/*.h> header guards.
I've been meaning to do this for a while, and it came up on the bug below
that there have been conflicts with similar-named files in <base/*.h>,
so let's rule out one possible explanation.

Bug: http://b/27804373
Change-Id: I69e5d52b6260c573c308513420aee0e281426bd4
2016-03-23 15:04:52 -07:00
Elliott Hughes
c0e6e40cc9 Copy the good comment and warn_unused_result from ScopedFd to unique_fd.
Also list all known aliases of this class to increase the chances that
anyone searching for it by another name finds it anyway.

Change-Id: I58ea0a5421987fb69f93cc56252a771e9c34147e
2016-03-23 14:56:37 -07:00
Pierre Imai
e65f8bedec Merge "Add C++ thread annotations support to core." 2016-03-23 03:13:22 +00:00
Pierre Imai
021ea2d176 Add C++ thread annotations support to core.
Change-Id: I7b8940c12e0f3121d8c09d86d2d4077b0a0ce376
2016-03-23 11:23:28 +09:00
Yabin Cui
2527628eda base: Avoid compilation error when compiled with -Wdangling-else.
As logging macros uses `if xxx else yyy` style, it is reported as an
error when DCHECK() is compiled with -Wdangling-else option. Because
after preprocess, DCHECK(x) becomes:
if (EnableDChecks)
  if (x)
    ;
  else
    LogMessage(FATAL) << yyy;

This CL avoids compilation error by replacing `if xxx else yyy`
with `xxx && yyy` or `!(xxx) || yyy`.

Bug: 26962895

Change-Id: Ib0bf242cc04a238ec31a1ab66b53fc8a5b5ed28f
2016-03-21 17:46:21 -07:00
Chih-Hung Hsieh
7e0e14ca84 Make CHECK(x) work with static analyzer.
When __clang_analyzer__ is defined call abort after FATAL LogMessage.
BUG: 27379879

Change-Id: I198aad2be1191b6eb45db5333f94436f619facd9
2016-03-02 09:23:02 -08:00
Elliott Hughes
38e2b63db8 Remove libbase's libutils dependency.
Yuck.

Change-Id: If84758f25bc15d5b1a732eaccc226385f51cac13
2016-02-17 11:53:54 -08:00
Yabin Cui
b958d22310 Merge "libziparchive: port unit tests to darwin and windows." 2016-02-09 00:56:43 +00:00
Yabin Cui
8e6f722764 libziparchive: port unit tests to darwin and windows.
Also use ReadFully to replace read, because read can
return reading bytes less than requested. And use
WriteFully to replace write.

Bug: 26962895
Change-Id: Iff0b2bc6d925619a537f7fef682c2a7ad89a2dc2
2016-02-08 16:52:55 -08:00
Dan Willemsen
3f68ba4dc6 Merge "Fix windows 64-bit builds" 2016-02-08 23:40:48 +00:00
Dan Willemsen
86cf941c48 Fix windows 64-bit builds
pid_t is 64-bit in 64-bit mingw, but the windows process/thread
functions return a DWORD(uint32_t). Instead of promoting to a pid_t and
fixing the format strings, just use a uint32_t to store the values.

android_thread_id also cannot be a 64-bit pointer, so for windows just
force it to be a uint32_t.

libutils/ProcessCallStack only works under Linux, since it makes heavy
use of /proc. Don't compile it under Windows or Darwin.

Bug: 26957718
Change-Id: I4e43e7cf18a96f22b3a9a08dbab8c3e960c12930
2016-02-05 16:10:10 -08:00
Elliott Hughes
5cf0dcd5b2 Fix libbase's logging dependency.
Get liblog directly, rather than transitively through libcutils.

Change-Id: Ia08ac6f04ac68c39807989d869709bae0a051578
2016-02-04 08:24:55 -08:00
David Pursell
5f787ed2b3 base: add SystemErrorCodeToString() function.
Pulls the Windows error string generation out of adb into libbase so
that it can be used by fastboot as well. Also makes a Unix equivalent
that just wraps strerror() so that upcoming fastboot error reporting
code can be platform-independent.

The intent here is just to provide a portable way to report an error to
the user. More general cross-platform error handling is out of scope.

Bug: http://b/26236380
Change-Id: I5a784a844775949562d069bb41dcb0ebd13a32bc
2016-02-01 12:18:26 -08:00
Yabin Cui
b6e314aa86 base: add API to remove file if it exists.
It is a function needed in different places like uncrypt, simpleperf.

Bug: 26883096
Change-Id: I26f4f30e8367867a88272625f00858569fc8e950
2016-01-29 19:24:55 -08:00
David Pursell
706955ff0d base: add network address parsing function from adb.
This CL moves the network address parsing function from adb to libbase
so that it can be used by fastboot as well as adb.

libbase seemed like the right choice because:
  1. It already has some parsing functions (parseint)
  2. The net address parsing function uses the libbase string
     functions so we have a libbase dependency anyway.

The parsing function has been modified slightly to make the canonical
address optional, and debug logging on success has been removed.

For adb the only functional difference is that parsing a network
address will no longer print the result to the debug log, which seemed
unnecessary.

Bug: http://b/26236380
Change-Id: Ife6df02937225fc66de87884d3572d79c092c522
2016-01-21 20:03:33 -08:00
Dan Albert
bac7bb5c16 Fix a couple sign-comparison warnings.
Bug: http://b/26523949
Change-Id: Id33146b5544147945fee3f14f7f72f39bae449f6
2016-01-15 12:18:14 -08:00
Elliott Hughes
f2584be414 Rename base/ to android-base/.
Bug: http://b/26023797
Change-Id: Ie6c63bf86bed05faab87d290de6f34d9af3532a8
2015-12-07 14:31:53 -08:00
Elliott Hughes
4f71319df0 Track rename of base/ to android-base/.
Change-Id: Idf9444fece4aa89c93e15640de59a91f6e758ccf
2015-12-04 22:00:26 -08:00
Elliott Hughes
7f24c45b7d Add a symlink android-base/ pointing to base/.
This lets us move things over piece by piece without breaking anything.

Change-Id: I06fc29572f63c4af9675888987acdcdea086711d
2015-12-04 15:18:27 -08:00
Casey Dahlin
918b9e8dc6 Introduce unique_fd
unique_fds are wrappers for integer file descriptors that automatically
close when they go out of scope. They are movable but not copyable and
generally mimic the semantics of std::unique_ptr

Change-Id: I0657b848b6536d5ad9fc06686e240ea5c387b0ac
Test: Considerable exercise in new AIDL integration tests
Bug: None
Signed-off-by: Casey Dahlin <sadmac@google.com>
2015-11-18 12:01:24 -08:00
Spencer Low
d21dc825bb adb: win32: remove widen()/narrow() in favor of UTF8ToWide()/WideToUTF8()
Now that we have a more standardized API (also available in Chromium),
switch to it. Another benefit is real error handling instead of just
killing the process on invalid Unicode.

Make UTF8ToWide()/WideToUTF8() set errno to EILSEQ on bad input. This is
the same error code that wcsrtombs(3) uses.

Update the unittest to check for EILSEQ.

Change-Id: Ie92acf74d37adaea116cf610c1bf8cd433741e16
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-12 17:13:08 -08:00
Josh Gao
26f2e1fd4f Merge changes Ic124ecb9,I94de55d2
* changes:
  libbase: remove exit-time destructors.
  adb: remove exit-time destructors.
2015-11-12 22:50:03 +00:00
Josh Gao
7df6b5fc79 libbase: remove exit-time destructors.
Removed for the same reason as the adb exit-time destructors.

Bug: http://b/23384853
Change-Id: Ic124ecb9df132b850a3855e207baffec926dde29
2015-11-12 11:54:47 -08:00
Elliott Hughes
c1fd492ac5 Revert "Revert "adb/base: fix adb push of Unicode filenames on Win32""
This reverts commit cc8cd59456.

With the dependency on libcutils (for gettid for non-bionic) removed,
this no longer breaks the build.

Change-Id: I645bd6876e2502ddc1535b69af1e645c0df9d178
2015-11-11 18:23:00 -08:00
Elliott Hughes
cc8cd59456 Revert "adb/base: fix adb push of Unicode filenames on Win32"
This reverts commit ac9514a452.

The new gettid dependency caused other breakage.

Change-Id: I74a75e40c30a45beb275f9dd38eb5c7beac15fbd
2015-11-11 18:01:12 +00:00
Spencer Low
ac9514a452 adb/base: fix adb push of Unicode filenames on Win32
ae5a6c06cd made adb push use
android::base::ReadFileToString() for small files, but that API did not
support UTF-8 filenames on Windows, until this fix which does the
following:

- Add android::base::{WideToUTF8,UTF8ToWide}() which are only available
  on Windows. The signatures are based on Chromium's APIs of the same
  name.

- Add the namespace android::base::utf8 which has versions of APIs that
  take UTF-8 strings. To use this, make sure your code is in a namespace
  and then do "using namespace android::base::utf8;". On Windows, this will
  make calls to open() call android::base::utf8::open(), and on other
  platforms, it will just call the regular ::open().

- Make ReadFileToString() and WriteStringToFile() use utf8::open() and
  utf8::unlink().

- Adapt unittests from Chromium.

- fastboot needs to link with libcutils because it links with libbase
  which depends on libcutils for gettid() for logging.

Change-Id: I1aeac40ff358331d7a1ff457ce894bfb17863904
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-10 15:48:54 -08:00
Spencer Low
363af568b8 adb/base: minor compiler portability improvements
I've been using these changes to compile with Visual Studio.

- GetFileBasename(): __FILE__ uses \ with Visual Studio.

- adb_trace.cpp: Apparently VS needs an ampersand before the function name.

- "expr1 ? : expr2" is a GCC extension.

- <algorithm> contains std::min().

- seekdir can't always be #define'd because some headers have members
  named seekdir.

- adb_utils.cpp: Not really a compiler issue, just a random fix:
  0x7F/DEL is not printable.

Change-Id: I0dfb634f1ba4ccbc0d1b9f71b00e838fbebb3b41
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-09 10:22:13 -08:00
Casey Dahlin
46776e7423 Merge "Make Join support string delimiters" 2015-11-02 20:28:09 +00:00
Casey Dahlin
5345f1df0d Make Join support string delimiters
We've needed this several times in the past.

Change-Id: I7324e8083fe2ff1aa0bf392a8c124fc2f3bb26e2
Test: Full android build
Signed-off-by: Casey Dahlin <sadmac@google.com>
2015-11-02 11:04:34 -08:00
Elliott Hughes
3ab05869d8 Fix ParseInt/ParseUint to handle explicit "0x" hex.
Also improve fastboot error reporting around max-download-size.

Change-Id: Ic3aec9460de01e5264a2803a0a6be3706d73026b
2015-11-02 09:01:53 -08:00
Elliott Hughes
c96de0d36e Fix lseek argument order.
Change-Id: I12feed2de8a4e0782f90609254a3e2ec66d7d98e
2015-10-20 13:18:22 -07:00
Spencer Low
765ae6bcfc base logging: fix errno restoring, severity conditionality, dangling ifs
Fix LOG() to properly save and restore errno. Test this properly.

Only do logging if severity is >= the minimum.

Fix dangling if statements in CHECK(), CHECK_STR{EQ,NE}(). Test this
properly.

Fix base logging tests on Windows. All libbase_tests now pass on
Windows.

Change place to lock, so the lock can protect logging of all data in
LogMessage.

Change-Id: I7ff531c67ae10a99ef0a2bbfe279aa77282d5ae9
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-21 12:46:12 -07:00
Spencer Low
b2d4949cee libbase_test: get it building for Windows
Add to whitelist.

For some reason, when compiling, parseint_test.cpp would encounter
errors like the following:

host cross C++: host_cross_libbase_test <= system/core/base/parseint_test.cpp
In file included from external/gtest/include/gtest/gtest.h:1929:0,
                 from system/core/base/parseint_test.cpp:19:
system/core/base/parseint_test.cpp: In member function ‘virtual void parseint_signed_smoke_Test::TestBody()’:
external/gtest/include/gtest/internal/gtest-internal.h:133:55: error: converting ‘false’ to pointer type for argument 1 of ‘char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’ [-Werror=conversion-null]
     (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
                                                       ^
external/gtest/include/gtest/gtest_pred_impl.h:77:52: note: in definition of macro ‘GTEST_ASSERT_’
   if (const ::testing::AssertionResult gtest_ar = (expression)) \
                                                    ^
external/gtest/include/gtest/gtest_pred_impl.h:166:3: note: in expansion of macro ‘GTEST_PRED_FORMAT2_’
   GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
   ^
external/gtest/include/gtest/gtest.h:1993:3: note: in expansion of macro ‘ASSERT_PRED_FORMAT2’
   ASSERT_PRED_FORMAT2(::testing::internal:: \
   ^
external/gtest/include/gtest/gtest.h:1994:32: note: in expansion of macro ‘GTEST_IS_NULL_LITERAL_’
                       EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
                                ^
external/gtest/include/gtest/gtest.h:2011:32: note: in expansion of macro ‘GTEST_ASSERT_EQ’
 # define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
                                ^
system/core/base/parseint_test.cpp:23:3: note: in expansion of macro ‘ASSERT_EQ’
   ASSERT_EQ(false, android::base::ParseInt("x", &i));
   ^

For whatever reason, the gcc for Windows isn't handling the template
metaprogramming correctly, so to work-around the issue, I
search-and-replaced "ASSERT_EQ(false, " to "ASSERT_FALSE(" and
"ASSERT_EQ(true, " to "ASSERT_TRUE(" and that seems to compile just fine
for Linux and Windows (and the tests pass on both platforms).

Change-Id: I05132909d1f4b18afff23139652a218649689f2d
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-11 20:01:29 -07:00
Dan Albert
933f4fd413 Merge "Ensure that libbase and liblog can be built for Windows." 2015-09-11 20:47:07 +00:00
Stephen Hines
b0e4f08226 Ensure that libbase and liblog can be built for Windows.
Change-Id: If4adf1e2bd7ec36a7f02ae2e263d2db5187c6e7b
2015-09-11 11:39:16 -07:00
Elliott Hughes
afe151fb02 Add ParseInt (and ParseUint).
strtol and family are hard to use correctly, and most callers don't
even try.

Change-Id: I2833622a92cccd4662c0c5bdbbef5eeb4e496914
2015-09-04 16:32:00 -07:00
Dan Willemsen
87a419c8b1 Remove USE_MINGW/CYGWIN; Whitelist windows modules
CYGWIN is not supported, USE_MINGW and HOST_OS==windows are being
replaced with LOCAL_..._windows variables.

Bug: 23566667
Change-Id: I3e4a1e4097dc994cf5abdce6939e83a91758fd75
2015-09-02 17:10:35 -07:00
Spencer Low
2fbeb0cc71 adb/base win32 tests: fix comment and open() flags
Match base's use of O_BINARY.

Change-Id: I930b5c8fddde20966580069f2e681b99cb26f1a3
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-01 14:57:58 -07:00
Elliott Hughes
470d79a09c Use O_BINARY in base/file for Windows.
This matches the behavior of the google3/Chrome APIs. It's probably what you
want in all cases except where you plan on calling Split(content, "\n"), but
we should probably have something like simpleperf's LineReader for that
anyway.

Change-Id: I1a128ed8c328bc95b0b2ef4068a65a8562721418
2015-09-01 13:35:44 -07:00