Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 803c7c80 authored by Adam Lesinski's avatar Adam Lesinski
Browse files

AAPT2: Enable windows build and make sure it builds

Mingw32 4.8 is kind of picky with macros and some complicated template
stuff. Luckily there was another way to represent the
SFINAE code that works on all platforms. Yay!

Change-Id: Idc2e38f47bfdc57b394550bfa0f53cc0b825df25
parent 50e439df
Loading
Loading
Loading
Loading
+45 −34
Original line number Diff line number Diff line
@@ -131,33 +131,40 @@ hostStaticLibs := \
	libbase \
	libprotobuf-cpp-lite_static

# Do not add any shared libraries. AAPT2 is built to run on many
# environments that may not have the required dependencies.
hostSharedLibs :=

ifneq ($(strip $(USE_MINGW)),)
	hostStaticLibs += libz
else
	hostLdLibs += -lz
endif
# Statically link libz for MinGW (Win SDK under Linux),
# and dynamically link for all others.
hostStaticLibs_windows := libz
hostLdLibs_linux := -lz
hostLdLibs_darwin := -lz

cFlags := -Wall -Werror -Wno-unused-parameter -UNDEBUG
cppFlags := -std=c++14 -Wno-missing-field-initializers -fno-exceptions -fno-rtti
cFlags_darwin := -D_DARWIN_UNLIMITED_STREAMS
cFlags_windows := -Wno-maybe-uninitialized # Incorrectly marking use of Maybe.value() as error.
cppFlags := -std=c++11 -Wno-missing-field-initializers -fno-exceptions -fno-rtti
protoIncludes := $(call generated-sources-dir-for,STATIC_LIBRARIES,libaapt2,HOST)

# ==========================================================
# NOTE: Do not add any shared libraries.
# AAPT2 is built to run on many environments
# that may not have the required dependencies.
# ==========================================================

# ==========================================================
# Build the host static library: libaapt2
# ==========================================================
include $(CLEAR_VARS)
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE := libaapt2

LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_HOST_OS := darwin linux windows
LOCAL_CFLAGS := $(cFlags)
LOCAL_CFLAGS_darwin := $(cFlags_darwin)
LOCAL_CFLAGS_windows := $(cFlags_windows)
LOCAL_CPPFLAGS := $(cppFlags)
LOCAL_C_INCLUDES := $(protoIncludes)
LOCAL_SRC_FILES := $(sources)
LOCAL_STATIC_LIBRARIES += $(hostStaticLibs)
LOCAL_CFLAGS += $(cFlags)
LOCAL_CPPFLAGS += $(cppFlags)
LOCAL_C_INCLUDES += $(protoIncludes)

LOCAL_STATIC_LIBRARIES := $(hostStaticLibs)
LOCAL_STATIC_LIBRARIES_windows := $(hostStaticLibs_windows)
include $(BUILD_HOST_STATIC_LIBRARY)

# ==========================================================
@@ -166,16 +173,18 @@ include $(BUILD_HOST_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libaapt2_tests
LOCAL_MODULE_TAGS := tests

LOCAL_MODULE_HOST_OS := darwin linux windows
LOCAL_CFLAGS := $(cFlags)
LOCAL_CFLAGS_darwin := $(cFlags_darwin)
LOCAL_CFLAGS_windows := $(cFlags_windows)
LOCAL_CPPFLAGS := $(cppFlags)
LOCAL_C_INCLUDES := $(protoIncludes)
LOCAL_SRC_FILES := $(testSources)

LOCAL_STATIC_LIBRARIES += libaapt2 $(hostStaticLibs)
LOCAL_SHARED_LIBRARIES += $(hostSharedLibs)
LOCAL_LDLIBS += $(hostLdLibs)
LOCAL_CFLAGS += $(cFlags)
LOCAL_CPPFLAGS += $(cppFlags)
LOCAL_C_INCLUDES += $(protoIncludes)

LOCAL_STATIC_LIBRARIES := libaapt2 $(hostStaticLibs)
LOCAL_STATIC_LIBRARIES_windows := $(hostStaticLibs_windows)
LOCAL_LDLIBS := $(hostLdLibs)
LOCAL_LDLIBS_darwin := $(hostLdLibs_darwin)
LOCAL_LDLIBS_linux := $(hostLdLibs_linux)
include $(BUILD_HOST_NATIVE_TEST)

# ==========================================================
@@ -183,16 +192,18 @@ include $(BUILD_HOST_NATIVE_TEST)
# ==========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := aapt2

LOCAL_MODULE_HOST_OS := darwin linux windows
LOCAL_CFLAGS := $(cFlags)
LOCAL_CFLAGS_darwin := $(cFlags_darwin)
LOCAL_CFLAGS_windows := $(cFlags_windows)
LOCAL_CPPFLAGS := $(cppFlags)
LOCAL_C_INCLUDES := $(protoIncludes)
LOCAL_SRC_FILES := $(main) $(toolSources)

LOCAL_STATIC_LIBRARIES += libaapt2 $(hostStaticLibs)
LOCAL_SHARED_LIBRARIES += $(hostSharedLibs)
LOCAL_LDLIBS += $(hostLdLibs)
LOCAL_CFLAGS += $(cFlags)
LOCAL_CPPFLAGS += $(cppFlags)
LOCAL_C_INCLUDES += $(protoIncludes)

LOCAL_STATIC_LIBRARIES := libaapt2 $(hostStaticLibs)
LOCAL_STATIC_LIBRARIES_windows := $(hostStaticLibs_windows)
LOCAL_LDLIBS := $(hostLdLibs)
LOCAL_LDLIBS_darwin := $(hostLdLibs_darwin)
LOCAL_LDLIBS_linux := $(hostLdLibs_linux)
include $(BUILD_HOST_EXECUTABLE)

ifeq ($(ONE_SHOT_MAKEFILE),)
+12 −8
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@
#include <gtest/gtest.h>
#include <string>

using namespace android;

namespace aapt {

TEST(StringPoolTest, InsertOneString) {
@@ -171,24 +169,28 @@ TEST(StringPoolTest, DoNotDedupeStyleWithSameStringAsNonStyle) {
}

TEST(StringPoolTest, FlattenEmptyStringPoolUtf8) {
    using namespace android; // For NO_ERROR on Windows.

    StringPool pool;
    BigBuffer buffer(1024);
    StringPool::flattenUtf8(&buffer, pool);

    std::unique_ptr<uint8_t[]> data = util::copy(buffer);
    android::ResStringPool test;
    ASSERT_EQ(test.setTo(data.get(), buffer.size()), android::NO_ERROR);
    ResStringPool test;
    ASSERT_EQ(test.setTo(data.get(), buffer.size()), NO_ERROR);
}

TEST(StringPoolTest, FlattenOddCharactersUtf16) {
    using namespace android; // For NO_ERROR on Windows.

    StringPool pool;
    pool.makeRef(u"\u093f");
    BigBuffer buffer(1024);
    StringPool::flattenUtf16(&buffer, pool);

    std::unique_ptr<uint8_t[]> data = util::copy(buffer);
    android::ResStringPool test;
    ASSERT_EQ(test.setTo(data.get(), buffer.size()), android::NO_ERROR);
    ResStringPool test;
    ASSERT_EQ(test.setTo(data.get(), buffer.size()), NO_ERROR);
    size_t len = 0;
    const char16_t* str = test.stringAt(0, &len);
    EXPECT_EQ(1u, len);
@@ -199,6 +201,8 @@ TEST(StringPoolTest, FlattenOddCharactersUtf16) {
constexpr const char16_t* sLongString = u"バッテリーを長持ちさせるため、バッテリーセーバーは端末のパフォーマンスを抑え、バイブレーション、位置情報サービス、大半のバックグラウンドデータを制限します。メール、SMSや、同期を使 用するその他のアプリは、起動しても更新されないことがあります。バッテリーセーバーは端末の充電中は自動的にOFFになります。";

TEST(StringPoolTest, FlattenUtf8) {
    using namespace android; // For NO_ERROR on Windows.

    StringPool pool;

    StringPool::Ref ref1 = pool.makeRef(u"hello");
@@ -219,8 +223,8 @@ TEST(StringPoolTest, FlattenUtf8) {

    std::unique_ptr<uint8_t[]> data = util::copy(buffer);
    {
        android::ResStringPool test;
        ASSERT_EQ(test.setTo(data.get(), buffer.size()), android::NO_ERROR);
        ResStringPool test;
        ASSERT_EQ(test.setTo(data.get(), buffer.size()), NO_ERROR);

        EXPECT_EQ(util::getString(test, 0), u"hello");
        EXPECT_EQ(util::getString(test, 1), u"goodbye");
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@
#include "compile/PseudolocaleGenerator.h"
#include "compile/Pseudolocalizer.h"

#include <algorithm>

namespace aapt {

std::unique_ptr<StyledString> pseudolocalizeStyledString(StyledString* string,
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include "util/BigBuffer.h"

#include <android-base/macros.h>
#include <algorithm>
#include <type_traits>
#include <numeric>

+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include "xml/XmlDom.h"

#include <androidfw/ResourceTypes.h>
#include <algorithm>
#include <utils/misc.h>
#include <vector>

Loading