From a34ca6cb07d95bbfdcaeff5b4d850c6790f79c59 Mon Sep 17 00:00:00 2001 From: Birh Burh Date: Sat, 8 Mar 2025 03:53:25 +0100 Subject: [PATCH 1/3] aapt: Bump to 15.0.0.23 conforming to android-35 --- packages/aapt/aapt2-io-Util.h.patch | 12 - packages/aapt/aapt2-util-Util.cpp.patch | 37 ++- packages/aapt/aidl-aidl_language.h.patch | 278 ++++++++++++++++++ .../aapt/androidfw-AssetManager.cpp.patch | 6 +- .../aapt/androidfw-ResourceTypes.cpp.patch | 2 +- packages/aapt/build.sh | 22 +- packages/aapt/include-utils-CallStack.h.patch | 11 - packages/aapt/include-utils-LruCache.h.patch | 18 -- packages/aapt/libbase-properties.cpp.patch | 44 +-- .../aapt/libcutils-native_handle.cpp.patch | 18 ++ packages/aapt/libutils-Threads.cpp.patch | 38 ++- .../aapt/libziparchive-zip_archive.cc.patch | 25 +- ...parchive-zip_archive_stream_entry.cc.patch | 11 + .../aapt/libziparchive-zip_writer.cc.patch | 2 +- packages/aapt/sources.sh | 51 ++-- 15 files changed, 446 insertions(+), 129 deletions(-) delete mode 100644 packages/aapt/aapt2-io-Util.h.patch create mode 100644 packages/aapt/aidl-aidl_language.h.patch delete mode 100644 packages/aapt/include-utils-CallStack.h.patch delete mode 100644 packages/aapt/include-utils-LruCache.h.patch create mode 100644 packages/aapt/libcutils-native_handle.cpp.patch create mode 100644 packages/aapt/libziparchive-zip_archive_stream_entry.cc.patch diff --git a/packages/aapt/aapt2-io-Util.h.patch b/packages/aapt/aapt2-io-Util.h.patch deleted file mode 100644 index f3a127d580ec1ab..000000000000000 --- a/packages/aapt/aapt2-io-Util.h.patch +++ /dev/null @@ -1,12 +0,0 @@ ---- a/base/tools/aapt2/io/Util.h -+++ b/base/tools/aapt2/io/Util.h -@@ -131,8 +131,7 @@ - template bool ReadMessage(T *message) { - ZeroCopyInputAdaptor adapter(in_); - google::protobuf::io::CodedInputStream coded_stream(&adapter); -- coded_stream.SetTotalBytesLimit(std::numeric_limits::max(), -- coded_stream.BytesUntilTotalBytesLimit()); -+ coded_stream.SetTotalBytesLimit(std::numeric_limits::max()); - return message->ParseFromCodedStream(&coded_stream); - } - diff --git a/packages/aapt/aapt2-util-Util.cpp.patch b/packages/aapt/aapt2-util-Util.cpp.patch index a9957f3bab8d660..1c09e52e0afaef2 100644 --- a/packages/aapt/aapt2-util-Util.cpp.patch +++ b/packages/aapt/aapt2-util-Util.cpp.patch @@ -1,26 +1,41 @@ --- a/base/tools/aapt2/util/Util.cpp +++ b/base/tools/aapt2/util/Util.cpp -@@ -24,7 +24,6 @@ - #include "android-base/stringprintf.h" - #include "android-base/strings.h" +@@ -27,7 +27,6 @@ + #include "androidfw/BigBuffer.h" #include "androidfw/StringPiece.h" + #include "androidfw/Util.h" -#include "build/version.h" #include "text/Unicode.h" #include "text/Utf8Iterator.h" - #include "util/BigBuffer.h" -@@ -230,17 +229,7 @@ + #include "utils/Unicode.h" +@@ -229,32 +228,7 @@ // Update minor version whenever a feature or flag is added. static const char* const sMinorVersion = "19"; - // The build id of aapt2 binary. -- static std::string sBuildId = android::build::GetBuildNumber(); +- static const std::string sBuildId = [] { +- std::string buildNumber = android::build::GetBuildNumber(); - -- if (android::base::StartsWith(sBuildId, "eng.")) { -- time_t now = time(0); -- tm* ltm = localtime(&now); +- if (android::base::StartsWith(buildNumber, "eng.")) { +- // android::build::GetBuildNumber() returns something like "eng.user.20230725.214219" where +- // the latter two parts are "yyyyMMdd.HHmmss" at build time. Use "yyyyMM" in the fingerprint. +- std::vector parts = util::Split(buildNumber, '.'); +- int buildYear; +- int buildMonth; +- if (parts.size() < 3 || parts[2].length() < 6 || +- !android::base::ParseInt(parts[2].substr(0, 4), &buildYear) || +- !android::base::ParseInt(parts[2].substr(4, 2), &buildMonth)) { +- // Fallback to localtime() if GetBuildNumber() returns an unexpected output. +- time_t now = time(0); +- tm* ltm = localtime(&now); +- buildYear = 1900 + ltm->tm_year; +- buildMonth = 1 + ltm->tm_mon; +- } - -- sBuildId = android::base::StringPrintf("eng.%d%d", 1900 + ltm->tm_year, 1 + ltm->tm_mon); -- } +- buildNumber = android::base::StringPrintf("eng.%04d%02d", buildYear, buildMonth); +- } +- return buildNumber; +- }(); - - return android::base::StringPrintf("%s.%s-%s", sMajorVersion, sMinorVersion, sBuildId.c_str()); + return android::base::StringPrintf("%s.%s", sMajorVersion, sMinorVersion); diff --git a/packages/aapt/aidl-aidl_language.h.patch b/packages/aapt/aidl-aidl_language.h.patch new file mode 100644 index 000000000000000..ef63475b4e98ff1 --- /dev/null +++ b/packages/aapt/aidl-aidl_language.h.patch @@ -0,0 +1,278 @@ +--- a/aidl/aidl_language.h ++++ b/aidl/aidl_language.h +@@ -396,6 +396,137 @@ class AidlAnnotatable : public AidlCommentable { + vector> annotations_; + }; + ++class AidlUnaryConstExpression; ++class AidlBinaryConstExpression; ++class AidlConstantReference; ++ ++class AidlConstantValue : public AidlNode { ++ public: ++ enum class Type { ++ // WARNING: Don't change this order! The order is used to determine type ++ // promotion during a binary expression. ++ BOOLEAN, ++ INT8, ++ INT32, ++ INT64, ++ ARRAY, ++ CHARACTER, ++ STRING, ++ REF, ++ FLOATING, ++ UNARY, ++ BINARY, ++ ERROR, ++ }; ++ ++ // Returns the evaluated value. T> should match to the actual type. ++ template ++ T EvaluatedValue() const { ++ is_evaluated_ || (CheckValid() && evaluate()); ++ AIDL_FATAL_IF(!is_valid_, this); ++ ++ if constexpr (is_vector::value) { ++ AIDL_FATAL_IF(final_type_ != Type::ARRAY, this); ++ T result; ++ for (const auto& v : values_) { ++ result.push_back(v->EvaluatedValue()); ++ } ++ return result; ++ } else if constexpr (is_one_of::value) { ++ AIDL_FATAL_IF(final_type_ != Type::FLOATING, this); ++ T result; ++ AIDL_FATAL_IF(!ParseFloating(value_, &result), this); ++ return result; ++ } else if constexpr (std::is_same::value) { ++ AIDL_FATAL_IF(final_type_ != Type::STRING, this); ++ return final_string_value_.substr(1, final_string_value_.size() - 2); // unquote " ++ } else if constexpr (is_one_of::value) { ++ AIDL_FATAL_IF(final_type_ < Type::INT8 && final_type_ > Type::INT64, this); ++ return static_cast(final_value_); ++ } else if constexpr (std::is_same::value) { ++ AIDL_FATAL_IF(final_type_ != Type::CHARACTER, this); ++ return final_string_value_.at(1); // unquote ' ++ } else if constexpr (std::is_same::value) { ++ static_assert(std::is_same::value, ".."); ++ AIDL_FATAL_IF(final_type_ != Type::BOOLEAN, this); ++ return final_value_ != 0; ++ } else { ++ static_assert(unsupported_type::value); ++ } ++ } ++ ++ virtual ~AidlConstantValue() = default; ++ ++ // non-copyable, non-movable ++ AidlConstantValue(const AidlConstantValue&) = delete; ++ AidlConstantValue(AidlConstantValue&&) = delete; ++ AidlConstantValue& operator=(const AidlConstantValue&) = delete; ++ AidlConstantValue& operator=(AidlConstantValue&&) = delete; ++ ++ // creates default value, when one isn't specified ++ // nullptr if no default available ++ static AidlConstantValue* Default(const AidlTypeSpecifier& specifier); ++ ++ static AidlConstantValue* Boolean(const AidlLocation& location, bool value); ++ static AidlConstantValue* Character(const AidlLocation& location, const std::string& value); ++ // example: 123, -5498, maybe any size ++ static AidlConstantValue* Integral(const AidlLocation& location, const std::string& value); ++ static AidlConstantValue* Floating(const AidlLocation& location, const std::string& value); ++ static AidlConstantValue* Array(const AidlLocation& location, ++ std::unique_ptr>> values); ++ // example: "\"asdf\"" ++ static AidlConstantValue* String(const AidlLocation& location, const string& value); ++ ++ Type GetType() const { return final_type_; } ++ const std::string& Literal() const { return value_; } ++ ++ bool Evaluate() const; ++ virtual bool CheckValid() const; ++ ++ // Raw value of type (currently valid in C++ and Java). Empty string on error. ++ string ValueString(const AidlTypeSpecifier& type, const ConstantValueDecorator& decorator) const; ++ ++ void TraverseChildren(std::function traverse) const override { ++ if (type_ == Type::ARRAY) { ++ for (const auto& v : values_) { ++ traverse(*v); ++ } ++ } ++ } ++ void DispatchVisit(AidlVisitor& visitor) const override { visitor.Visit(*this); } ++ size_t Size() const { return values_.size(); } ++ const AidlConstantValue& ValueAt(size_t index) const { return *values_.at(index); } ++ static string ToString(Type type); ++ ++ private: ++ AidlConstantValue(const AidlLocation& location, Type parsed_type, int64_t parsed_value, ++ const string& checked_value); ++ AidlConstantValue(const AidlLocation& location, Type type, const string& checked_value); ++ AidlConstantValue(const AidlLocation& location, Type type, ++ std::unique_ptr>> values, ++ const std::string& value); ++ static bool ParseIntegral(const string& value, int64_t* parsed_value, Type* parsed_type); ++ static bool IsHex(const string& value); ++ ++ virtual bool evaluate() const; ++ bool IsLiteral() const; ++ ++ const Type type_ = Type::ERROR; ++ const vector> values_; // if type_ == ARRAY ++ const string value_; // otherwise ++ ++ // State for tracking evaluation of expressions ++ mutable bool is_valid_ = false; // cache of CheckValid, but may be marked false in evaluate ++ mutable bool is_evaluated_ = false; // whether evaluate has been called ++ mutable Type final_type_; ++ mutable int64_t final_value_; ++ mutable string final_string_value_ = ""; ++ ++ friend AidlUnaryConstExpression; ++ friend AidlBinaryConstExpression; ++ friend AidlConstantReference; ++}; ++ + // Represents `[]` + struct DynamicArray {}; + // Represents `[N][M]..` +@@ -613,137 +744,6 @@ struct ArgumentAspect { + std::set possible_directions; + }; + +-class AidlUnaryConstExpression; +-class AidlBinaryConstExpression; +-class AidlConstantReference; +- +-class AidlConstantValue : public AidlNode { +- public: +- enum class Type { +- // WARNING: Don't change this order! The order is used to determine type +- // promotion during a binary expression. +- BOOLEAN, +- INT8, +- INT32, +- INT64, +- ARRAY, +- CHARACTER, +- STRING, +- REF, +- FLOATING, +- UNARY, +- BINARY, +- ERROR, +- }; +- +- // Returns the evaluated value. T> should match to the actual type. +- template +- T EvaluatedValue() const { +- is_evaluated_ || (CheckValid() && evaluate()); +- AIDL_FATAL_IF(!is_valid_, this); +- +- if constexpr (is_vector::value) { +- AIDL_FATAL_IF(final_type_ != Type::ARRAY, this); +- T result; +- for (const auto& v : values_) { +- result.push_back(v->EvaluatedValue()); +- } +- return result; +- } else if constexpr (is_one_of::value) { +- AIDL_FATAL_IF(final_type_ != Type::FLOATING, this); +- T result; +- AIDL_FATAL_IF(!ParseFloating(value_, &result), this); +- return result; +- } else if constexpr (std::is_same::value) { +- AIDL_FATAL_IF(final_type_ != Type::STRING, this); +- return final_string_value_.substr(1, final_string_value_.size() - 2); // unquote " +- } else if constexpr (is_one_of::value) { +- AIDL_FATAL_IF(final_type_ < Type::INT8 && final_type_ > Type::INT64, this); +- return static_cast(final_value_); +- } else if constexpr (std::is_same::value) { +- AIDL_FATAL_IF(final_type_ != Type::CHARACTER, this); +- return final_string_value_.at(1); // unquote ' +- } else if constexpr (std::is_same::value) { +- static_assert(std::is_same::value, ".."); +- AIDL_FATAL_IF(final_type_ != Type::BOOLEAN, this); +- return final_value_ != 0; +- } else { +- static_assert(unsupported_type::value); +- } +- } +- +- virtual ~AidlConstantValue() = default; +- +- // non-copyable, non-movable +- AidlConstantValue(const AidlConstantValue&) = delete; +- AidlConstantValue(AidlConstantValue&&) = delete; +- AidlConstantValue& operator=(const AidlConstantValue&) = delete; +- AidlConstantValue& operator=(AidlConstantValue&&) = delete; +- +- // creates default value, when one isn't specified +- // nullptr if no default available +- static AidlConstantValue* Default(const AidlTypeSpecifier& specifier); +- +- static AidlConstantValue* Boolean(const AidlLocation& location, bool value); +- static AidlConstantValue* Character(const AidlLocation& location, const std::string& value); +- // example: 123, -5498, maybe any size +- static AidlConstantValue* Integral(const AidlLocation& location, const std::string& value); +- static AidlConstantValue* Floating(const AidlLocation& location, const std::string& value); +- static AidlConstantValue* Array(const AidlLocation& location, +- std::unique_ptr>> values); +- // example: "\"asdf\"" +- static AidlConstantValue* String(const AidlLocation& location, const string& value); +- +- Type GetType() const { return final_type_; } +- const std::string& Literal() const { return value_; } +- +- bool Evaluate() const; +- virtual bool CheckValid() const; +- +- // Raw value of type (currently valid in C++ and Java). Empty string on error. +- string ValueString(const AidlTypeSpecifier& type, const ConstantValueDecorator& decorator) const; +- +- void TraverseChildren(std::function traverse) const override { +- if (type_ == Type::ARRAY) { +- for (const auto& v : values_) { +- traverse(*v); +- } +- } +- } +- void DispatchVisit(AidlVisitor& visitor) const override { visitor.Visit(*this); } +- size_t Size() const { return values_.size(); } +- const AidlConstantValue& ValueAt(size_t index) const { return *values_.at(index); } +- static string ToString(Type type); +- +- private: +- AidlConstantValue(const AidlLocation& location, Type parsed_type, int64_t parsed_value, +- const string& checked_value); +- AidlConstantValue(const AidlLocation& location, Type type, const string& checked_value); +- AidlConstantValue(const AidlLocation& location, Type type, +- std::unique_ptr>> values, +- const std::string& value); +- static bool ParseIntegral(const string& value, int64_t* parsed_value, Type* parsed_type); +- static bool IsHex(const string& value); +- +- virtual bool evaluate() const; +- bool IsLiteral() const; +- +- const Type type_ = Type::ERROR; +- const vector> values_; // if type_ == ARRAY +- const string value_; // otherwise +- +- // State for tracking evaluation of expressions +- mutable bool is_valid_ = false; // cache of CheckValid, but may be marked false in evaluate +- mutable bool is_evaluated_ = false; // whether evaluate has been called +- mutable Type final_type_; +- mutable int64_t final_value_; +- mutable string final_string_value_ = ""; +- +- friend AidlUnaryConstExpression; +- friend AidlBinaryConstExpression; +- friend AidlConstantReference; +-}; +- + // Represents "." which resolves to a constant which is one of + // - constant declaration + // - enumerator diff --git a/packages/aapt/androidfw-AssetManager.cpp.patch b/packages/aapt/androidfw-AssetManager.cpp.patch index 2fce38d40c3bf70..d6514d3fdd23e94 100644 --- a/packages/aapt/androidfw-AssetManager.cpp.patch +++ b/packages/aapt/androidfw-AssetManager.cpp.patch @@ -1,15 +1,15 @@ --- a/base/libs/androidfw/AssetManager.cpp +++ b/base/libs/androidfw/AssetManager.cpp -@@ -940,13 +940,9 @@ +@@ -941,13 +941,9 @@ if (method == ZipFileRO::kCompressStored) { pAsset = Asset::createFromUncompressedMap(std::move(*dataMap), mode); -- ALOGV("Opened uncompressed entry %s in zip %s mode %d: %p", entryName.string(), +- ALOGV("Opened uncompressed entry %s in zip %s mode %d: %p", entryName.c_str(), - dataMap->file_name(), mode, pAsset.get()); } else { pAsset = Asset::createFromCompressedMap(std::move(*dataMap), static_cast(uncompressedLen), mode); -- ALOGV("Opened compressed entry %s in zip %s mode %d: %p", entryName.string(), +- ALOGV("Opened compressed entry %s in zip %s mode %d: %p", entryName.c_str(), - dataMap->file_name(), mode, pAsset.get()); } if (pAsset == NULL) { diff --git a/packages/aapt/androidfw-ResourceTypes.cpp.patch b/packages/aapt/androidfw-ResourceTypes.cpp.patch index defd7df32e0edf9..1232ac210a2402e 100644 --- a/packages/aapt/androidfw-ResourceTypes.cpp.patch +++ b/packages/aapt/androidfw-ResourceTypes.cpp.patch @@ -1,6 +1,6 @@ --- a/base/libs/androidfw/ResourceTypes.cpp +++ b/base/libs/androidfw/ResourceTypes.cpp -@@ -43,7 +43,7 @@ +@@ -45,7 +45,7 @@ #include #include diff --git a/packages/aapt/build.sh b/packages/aapt/build.sh index 7500eca5e729d07..431cd651c4fe542 100644 --- a/packages/aapt/build.sh +++ b/packages/aapt/build.sh @@ -2,11 +2,12 @@ TERMUX_PKG_HOMEPAGE=https://elinux.org/Android_aapt TERMUX_PKG_DESCRIPTION="Android Asset Packaging Tool" TERMUX_PKG_LICENSE="Apache-2.0" TERMUX_PKG_MAINTAINER="@termux" -_TAG_VERSION=13.0.0 -_TAG_REVISION=6 +_TAG_VERSION=15.0.0 +_TAG_REVISION=23 TERMUX_PKG_VERSION=${_TAG_VERSION}.${_TAG_REVISION} TERMUX_PKG_REVISION=18 TERMUX_PKG_SRCURL=(https://android.googlesource.com/platform/frameworks/base + https://android.googlesource.com/platform/frameworks/native https://android.googlesource.com/platform/system/core https://android.googlesource.com/platform/system/libbase https://android.googlesource.com/platform/system/libziparchive @@ -22,6 +23,7 @@ TERMUX_PKG_SHA256=(SKIP_CHECKSUM SKIP_CHECKSUM SKIP_CHECKSUM SKIP_CHECKSUM + SKIP_CHECKSUM SKIP_CHECKSUM) TERMUX_PKG_SKIP_SRC_EXTRACT=true TERMUX_PKG_BUILD_IN_SRC=true @@ -67,7 +69,7 @@ termux_step_pre_configure() { export PATH=$TERMUX_PKG_HOSTBUILD_DIR/_prefix/bin:$PATH CFLAGS+=" -fPIC" - CXXFLAGS+=" -fPIC -std=c++17" + CXXFLAGS+=" -fPIC -std=gnu++2b" CPPFLAGS+=" -DNDEBUG -D__ANDROID_SDK_VERSION__=__ANDROID_API__" CPPFLAGS+=" -DPROTOBUF_USE_DLLS" @@ -98,6 +100,7 @@ termux_step_make() { local AAPT2_SRCDIR=$TERMUX_PKG_SRCDIR/base/tools/aapt2 local ZIPALIGN_SRCDIR=$TERMUX_PKG_SRCDIR/build/tools/zipalign local AIDL_SRCDIR=$TERMUX_PKG_SRCDIR/aidl + local FTL_INCDIR=$TERMUX_PKG_SRCDIR/native/include CPPFLAGS+=" -I. -I./include -I$LIBBASE_SRCDIR/include @@ -146,7 +149,11 @@ termux_step_make() { CPPFLAGS+=" -I$INCFS_UTIL_SRCDIR/include" + CPPFLAGS+=" -I$FTL_INCDIR" + # Build libandroidfw: + CPPFLAGS+=" -I$ANDROIDFW_SRCDIR/include_pathutils" + cd $ANDROIDFW_SRCDIR for f in $androidfw_sources $INCFS_UTIL_SRCDIR/map_ptr.cpp; do $CXX $CXXFLAGS $CPPFLAGS $f -c @@ -161,6 +168,10 @@ termux_step_make() { CPPFLAGS+=" -I$ANDROIDFW_SRCDIR/include" + # Build libandroidfw_pathutils: + $CXX $CXXFLAGS $CPPFLAGS PathUtils.cpp -c -o PathUtils.o + $AR rcs $_TMP_LIBDIR/libandroidfw_pathutils.a PathUtils.o + # Build aapt: cd $AAPT_SRCDIR for f in *.cpp; do @@ -172,6 +183,7 @@ termux_step_make() { -lexpat \ -lpng \ -lz \ + -l:libandroidfw_pathutils.a \ -o $_TMP_BINDIR/aapt # Build aapt2: @@ -190,6 +202,7 @@ termux_step_make() { -landroid-ziparchive \ -lexpat \ -lpng \ + -lfmt \ -lprotobuf \ $($TERMUX_SCRIPTDIR/packages/libprotobuf/interface_link_libraries.sh) \ -o $_TMP_BINDIR/aapt2 @@ -197,7 +210,8 @@ termux_step_make() { # Build zipalign: cd $ZIPALIGN_SRCDIR for f in *.cpp; do - $CXX $CXXFLAGS $CPPFLAGS -I$TERMUX_PKG_SRCDIR/zopfli/src $f -c + $CXX $CXXFLAGS $CPPFLAGS -I$TERMUX_PKG_SRCDIR/zopfli/src \ + -D_FILE_OFFSET_BITS=64 $f -c done $CXX $CXXFLAGS *.o $LDFLAGS \ -landroid-utils \ diff --git a/packages/aapt/include-utils-CallStack.h.patch b/packages/aapt/include-utils-CallStack.h.patch deleted file mode 100644 index bc4d96ed05d6f5b..000000000000000 --- a/packages/aapt/include-utils-CallStack.h.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/core/libutils/include/utils/CallStack.h -+++ b/core/libutils/include/utils/CallStack.h -@@ -20,7 +20,7 @@ - #include - - #include --#include -+#define BACKTRACE_CURRENT_THREAD -1 - #include - #include - diff --git a/packages/aapt/include-utils-LruCache.h.patch b/packages/aapt/include-utils-LruCache.h.patch deleted file mode 100644 index 338ece8b932e2ab..000000000000000 --- a/packages/aapt/include-utils-LruCache.h.patch +++ /dev/null @@ -1,18 +0,0 @@ ---- a/core/include/utils/LruCache.h -+++ b/core/include/utils/LruCache.h -@@ -84,13 +84,13 @@ - const TKey& getKey() const final { return key; } - }; - -- struct HashForEntry : public std::unary_function { -+ struct HashForEntry { - size_t operator() (const KeyedEntry* entry) const { - return hash_type(entry->getKey()); - }; - }; - -- struct EqualityForHashedEntries : public std::unary_function { -+ struct EqualityForHashedEntries { - bool operator() (const KeyedEntry* lhs, const KeyedEntry* rhs) const { - return lhs->getKey() == rhs->getKey(); - }; diff --git a/packages/aapt/libbase-properties.cpp.patch b/packages/aapt/libbase-properties.cpp.patch index 3bf0acb9dc71e7b..37eb473c012642a 100644 --- a/packages/aapt/libbase-properties.cpp.patch +++ b/packages/aapt/libbase-properties.cpp.patch @@ -1,42 +1,24 @@ --- a/libbase/properties.cpp +++ b/libbase/properties.cpp -@@ -32,7 +32,7 @@ - #include - #include - --#if !defined(__BIONIC__) -+#if !defined(__BIONIC__) || defined(__TERMUX__) +@@ -16,7 +16,7 @@ - #define PROP_VALUE_MAX 92 + #include "android-base/properties.h" -@@ -53,6 +53,9 @@ - return 0; - } - -+#endif -+ -+#if !defined(__BIONIC__) - int __system_property_get(const char* key, char* value) { - auto it = g_properties.find(key); - if (it == g_properties.end()) { -@@ -62,7 +65,6 @@ - snprintf(value, PROP_VALUE_MAX, "%s", it->second.c_str()); - return strlen(value); - } -- +-#if defined(__BIONIC__) ++#if defined(__BIONIC__) && !defined(__TERMUX__) + #include #endif - namespace android { -@@ -108,7 +110,7 @@ +@@ -31,7 +31,7 @@ + #include + #include - std::string GetProperty(const std::string& key, const std::string& default_value) { - std::string property_value; --#if defined(__BIONIC__) -+#if defined(__BIONIC__) && !defined(__TERMUX__) - const prop_info* pi = __system_property_find(key.c_str()); - if (pi == nullptr) return default_value; +-#if !defined(__BIONIC__) ++#if !defined(__BIONIC__) || defined(__TERMUX__) -@@ -134,7 +136,7 @@ + // Here lies a rudimentary implementation of system properties for non-Bionic + // platforms. We are using weak symbols here because we want to allow +@@ -178,7 +178,7 @@ bool SetProperty(const std::string& key, const std::string& value) { return (__system_property_set(key.c_str(), value.c_str()) == 0); } diff --git a/packages/aapt/libcutils-native_handle.cpp.patch b/packages/aapt/libcutils-native_handle.cpp.patch new file mode 100644 index 000000000000000..06839fe7e1fa86d --- /dev/null +++ b/packages/aapt/libcutils-native_handle.cpp.patch @@ -0,0 +1,18 @@ +--- a/core/libcutils/native_handle.cpp ++++ b/core/libcutils/native_handle.cpp +@@ -23,13 +23,13 @@ + #include + + // Needs to come after stdlib includes to capture the __BIONIC__ definition +-#ifdef __BIONIC__ ++#if defined(__BIONIC__) && __ANDROID_API__ >= 29 + #include + #endif + + namespace { + +-#if !defined(__BIONIC__) ++#if !defined(__BIONIC__) || __ANDROID_API__ < 29 + // fdsan stubs when not linked against bionic + #define ANDROID_FDSAN_OWNER_TYPE_NATIVE_HANDLE 0 + diff --git a/packages/aapt/libutils-Threads.cpp.patch b/packages/aapt/libutils-Threads.cpp.patch index 04593fa22dbe03e..3543e19d3749aee 100644 --- a/packages/aapt/libutils-Threads.cpp.patch +++ b/packages/aapt/libutils-Threads.cpp.patch @@ -2,23 +2,23 @@ +++ b/core/libutils/Threads.cpp @@ -36,7 +36,7 @@ - #include + #include -#if defined(__ANDROID__) +#if defined(__ANDROID__) && !defined(__TERMUX__) - #include - #include - #endif -@@ -67,7 +67,7 @@ + # define __android_unused + #else + # define __android_unused __attribute__((__unused__)) +@@ -62,7 +62,7 @@ using namespace android; - typedef void* (*android_pthread_entry)(void*); + typedef int (*android_pthread_entry)(void*); -#if defined(__ANDROID__) +#if defined(__ANDROID__) && !defined(__TERMUX__) struct thread_data_t { thread_func_t entryFunction; void* userData; -@@ -133,7 +133,7 @@ +@@ -134,7 +134,7 @@ int androidCreateRawThreadEtc(android_thread_func_t entryFunction, pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); @@ -27,7 +27,7 @@ if (threadPriority != PRIORITY_DEFAULT || threadName != NULL) { // Now that the pthread_t has a method to find the associated // android_thread_id_t (pid) from pthread_t, it would be possible to avoid -@@ -177,7 +177,7 @@ +@@ -183,7 +183,7 @@ int androidCreateRawThreadEtc(android_thread_func_t entryFunction, return 1; } @@ -36,7 +36,7 @@ static pthread_t android_thread_id_t_to_pthread(android_thread_id_t thread) { return (pthread_t) thread; -@@ -303,7 +303,7 @@ +@@ -309,7 +309,7 @@ void androidSetCreateThreadFunc(android_create_thread_fn func) gCreateThreadFn = func; } @@ -45,7 +45,25 @@ int androidSetThreadPriority(pid_t tid, int pri) { int rc = 0; -@@ -845,7 +845,7 @@ +@@ -648,7 +648,7 @@ Thread::Thread(bool canCallJava) + mStatus(OK), + mExitPending(false), + mRunning(false) +-#if defined(__ANDROID__) ++#if defined(__ANDROID__) && !defined(__TERMUX__) + , + mTid(-1) + #endif +@@ -721,7 +721,7 @@ int Thread::_threadLoop(void* user) + wp weak(strong); + self->mHoldSelf.clear(); + +-#if defined(__ANDROID__) ++#if defined(__ANDROID__) && !defined(__TERMUX__) + // this is very useful for debugging with gdb + self->mTid = gettid(); + #endif +@@ -832,7 +832,7 @@ bool Thread::isRunning() const { return mRunning; } diff --git a/packages/aapt/libziparchive-zip_archive.cc.patch b/packages/aapt/libziparchive-zip_archive.cc.patch index 1e26e5254e4eb11..6a65344ea7810cc 100644 --- a/packages/aapt/libziparchive-zip_archive.cc.patch +++ b/packages/aapt/libziparchive-zip_archive.cc.patch @@ -1,6 +1,6 @@ --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc -@@ -40,7 +40,7 @@ +@@ -46,7 +46,7 @@ #define lseek64 lseek #endif @@ -9,25 +9,25 @@ #include #endif -@@ -91,7 +91,7 @@ - * of the string length into the hash table entry. - */ +@@ -148,7 +148,7 @@ constexpr size_t kPageSize = 4096; + #endif + } -#if defined(__BIONIC__) +#if defined(__BIONIC__) && __ANDROID_API__ >= 29 - uint64_t GetOwnerTag(const ZipArchive* archive) { + static uint64_t GetOwnerTag(const ZipArchive* archive) { return android_fdsan_create_owner_tag(ANDROID_FDSAN_OWNER_TYPE_ZIPARCHIVE, reinterpret_cast(archive)); -@@ -105,7 +105,7 @@ +@@ -162,7 +162,7 @@ ZipArchive::ZipArchive(MappedZipFile&& map, bool assume_ownership) central_directory(), directory_map(), num_entries(0) { -#if defined(__BIONIC__) +#if defined(__BIONIC__) && __ANDROID_API__ >= 29 if (assume_ownership) { - CHECK(mapped_zip.HasFd()); + CHECK(mapped_zip.GetFileDescriptor() >= 0 || !mapped_zip.GetBasePtr()); android_fdsan_exchange_owner_tag(mapped_zip.GetFileDescriptor(), 0, GetOwnerTag(this)); -@@ -123,7 +123,7 @@ +@@ -180,7 +180,7 @@ ZipArchive::ZipArchive(const void* address, size_t length) ZipArchive::~ZipArchive() { if (close_file && mapped_zip.GetFileDescriptor() >= 0) { @@ -36,3 +36,12 @@ android_fdsan_close_with_tag(mapped_zip.GetFileDescriptor(), GetOwnerTag(this)); #else close(mapped_zip.GetFileDescriptor()); +@@ -1475,7 +1475,7 @@ static int32_t inflateImpl(const zip_archive::Reader& reader, + + remaining_bytes -= read_size; + +- zstream.next_in = buf; ++ zstream.next_in = const_cast(buf); + zstream.avail_in = read_size; + } + diff --git a/packages/aapt/libziparchive-zip_archive_stream_entry.cc.patch b/packages/aapt/libziparchive-zip_archive_stream_entry.cc.patch new file mode 100644 index 000000000000000..0231fb7e946a8c5 --- /dev/null +++ b/packages/aapt/libziparchive-zip_archive_stream_entry.cc.patch @@ -0,0 +1,11 @@ +--- a/libziparchive/zip_archive_stream_entry.cc ++++ b/libziparchive/zip_archive_stream_entry.cc +@@ -236,7 +236,7 @@ const std::vector* ZipArchiveStreamEntryCompressed::Read() { + + compressed_length_ -= bytes; + offset_ += bytes; +- z_stream_.next_in = res; ++ z_stream_.next_in = const_cast(res); + z_stream_.avail_in = bytes; + } + diff --git a/packages/aapt/libziparchive-zip_writer.cc.patch b/packages/aapt/libziparchive-zip_writer.cc.patch index d475e9e8f29b596..96307ebf57cf359 100644 --- a/packages/aapt/libziparchive-zip_writer.cc.patch +++ b/packages/aapt/libziparchive-zip_writer.cc.patch @@ -5,7 +5,7 @@ // Prepare the input. - z_stream_->next_in = reinterpret_cast(data); -+ z_stream_->next_in = const_cast(reinterpret_cast(data)); ++ z_stream_->next_in = static_cast(const_cast(data)); z_stream_->avail_in = len; while (z_stream_->avail_in > 0) { diff --git a/packages/aapt/sources.sh b/packages/aapt/sources.sh index b0eb2ecde15ebae..009c9b9347b4952 100644 --- a/packages/aapt/sources.sh +++ b/packages/aapt/sources.sh @@ -33,31 +33,32 @@ local libcutils_sources=" properties.cpp record_stream.cpp strlcpy.c - threads.cpp " # libutils local libutils_sources=" - Errors.cpp FileMap.cpp JenkinsHash.cpp LightRefBase.cpp NativeHandle.cpp Printer.cpp - RefBase.cpp - SharedBuffer.cpp StopWatch.cpp - String8.cpp - String16.cpp - StrongPointer.cpp SystemClock.cpp Threads.cpp Timers.cpp Tokenizer.cpp - Unicode.cpp - VectorImpl.cpp misc.cpp " +libutils_sources+=" + binder/Errors.cpp + binder/RefBase.cpp + binder/SharedBuffer.cpp + binder/String8.cpp + binder/String16.cpp + binder/StrongPointer.cpp + binder/Unicode.cpp + binder/VectorImpl.cpp +" # libbase local libbase_linux_sources=" @@ -77,6 +78,7 @@ local libbase_sources=" posix_strerror_r.cpp process.cpp properties.cpp + result.cpp stringprintf.cpp strings.cpp threads.cpp @@ -98,24 +100,35 @@ libziparchive_sources+=" # androidfw local androidfw_sources=" ApkAssets.cpp + ApkParsing.cpp Asset.cpp AssetDir.cpp AssetManager.cpp AssetManager2.cpp AssetsProvider.cpp AttributeResolution.cpp + BigBuffer.cpp + BigBufferStream.cpp ChunkIterator.cpp ConfigDescription.cpp + FileStream.cpp Idmap.cpp LoadedArsc.cpp Locale.cpp LocaleData.cpp misc.cpp + NinePatch.cpp ObbFile.cpp + PathUtils.cpp PosixUtils.cpp + Png.cpp + PngChunkFilter.cpp + PngCrunch.cpp + ResourceTimer.cpp ResourceTypes.cpp ResourceUtils.cpp StreamingZipInflater.cpp + StringPool.cpp TypeWrappers.cpp Util.cpp ZipFileRO.cpp @@ -124,18 +137,16 @@ local androidfw_sources=" # aapt2 local libaapt2_proto=" + ApkInfo.proto Configuration.proto Resources.proto + ResourceMetadata.proto ResourcesInternal.proto " local libaapt2_sources=" ${libaapt2_proto//.proto/.pb.cc} compile/IdAssigner.cpp compile/InlineXmlFormatParser.cpp - compile/NinePatch.cpp - compile/Png.cpp - compile/PngChunkFilter.cpp - compile/PngCrunch.cpp compile/PseudolocaleGenerator.cpp compile/Pseudolocalizer.cpp compile/XmlIdCollector.cpp @@ -147,21 +158,21 @@ local libaapt2_sources=" format/Container.cpp format/binary/BinaryResourceParser.cpp format/binary/ResChunkPullParser.cpp + format/binary/ResEntryWriter.cpp format/binary/TableFlattener.cpp format/binary/XmlFlattener.cpp format/proto/ProtoDeserialize.cpp format/proto/ProtoSerialize.cpp - io/BigBufferStream.cpp io/File.cpp - io/FileStream.cpp io/FileSystem.cpp io/StringStream.cpp io/Util.cpp io/ZipArchive.cpp link/AutoVersioner.cpp + link/FeatureFlagsFilter.cpp + link/FlagDisabledResourceRemover.cpp link/ManifestFixer.cpp link/NoDefaultResourceRemover.cpp - link/ProductFilter.cpp link/PrivateAttributeMover.cpp link/ReferenceLinker.cpp link/ResourceExcluder.cpp @@ -172,14 +183,14 @@ local libaapt2_sources=" optimize/MultiApkGenerator.cpp optimize/ResourceDeduper.cpp optimize/ResourceFilter.cpp - optimize/ResourcePathShortener.cpp + optimize/Obfuscator.cpp optimize/VersionCollapser.cpp + process/ProductFilter.cpp process/SymbolTable.cpp split/TableSplitter.cpp text/Printer.cpp text/Unicode.cpp text/Utf8Iterator.cpp - util/BigBuffer.cpp util/Files.cpp util/Util.cpp Debug.cpp @@ -196,7 +207,6 @@ local libaapt2_sources=" ResourceUtils.cpp ResourceValues.cpp SdkConstants.cpp - StringPool.cpp trace/TraceBuffer.cpp xml/XmlActionExecutor.cpp xml/XmlDom.cpp @@ -205,6 +215,7 @@ local libaapt2_sources=" ValueTransformer.cpp " local aapt2_tool_sources=" + cmd/ApkInfo.cpp cmd/Command.cpp cmd/Compile.cpp cmd/Convert.cpp @@ -226,6 +237,7 @@ local libaidl_sources=" aidl_const_expressions.cpp aidl_dumpapi.cpp aidl_language.cpp + aidl_to_common.cpp aidl_to_cpp_common.cpp aidl_to_cpp.cpp aidl_to_java.cpp @@ -240,6 +252,7 @@ local libaidl_sources=" diagnostics.cpp generate_aidl_mappings.cpp generate_cpp.cpp + generate_cpp_analyzer.cpp generate_java_binder.cpp generate_java.cpp generate_ndk.cpp From 2cd8f14723174e8fe913cdd48cc51dd9f1fe0a5c Mon Sep 17 00:00:00 2001 From: Birh Burh Date: Sat, 24 May 2025 01:13:45 +0200 Subject: [PATCH 2/3] aapt2 segfaults for me now, but no linking errors --- packages/aapt/build.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/aapt/build.sh b/packages/aapt/build.sh index 431cd651c4fe542..f738e3e076778e5 100644 --- a/packages/aapt/build.sh +++ b/packages/aapt/build.sh @@ -86,6 +86,8 @@ termux_step_pre_configure() { termux_step_make() { . $TERMUX_PKG_BUILDER_DIR/sources.sh + termux_setup_protobuf + local CORE_INCDIR=$TERMUX_PKG_SRCDIR/core/include local LIBLOG_INCDIR=$TERMUX_PKG_SRCDIR/logging/liblog/include local LIBBASE_SRCDIR=$TERMUX_PKG_SRCDIR/libbase @@ -138,7 +140,7 @@ termux_step_make() { # Build libziparchive: cd $LIBZIPARCHIVE_SRCDIR for f in $libziparchive_sources; do - $CXX $CXXFLAGS -std=c++20 $CPPFLAGS -I$INCFS_SUPPORT_INCDIR $f -c + $CXX $CXXFLAGS $CPPFLAGS -I$INCFS_SUPPORT_INCDIR $f -c done $CXX $CXXFLAGS *.o -shared $LDFLAGS \ -landroid-base \ @@ -163,6 +165,7 @@ termux_step_make() { -landroid-cutils \ -landroid-utils \ -landroid-ziparchive \ + -lpng \ -lz \ -o $_TMP_LIBDIR/libandroid-fw.so @@ -195,6 +198,7 @@ termux_step_make() { $CXX $CXXFLAGS $CPPFLAGS -I$LIBIDMAP2_POLICIES_INCDIR \ $f -c -o ${f%.*}.o done + $CXX $CXXFLAGS $(find . -name '*.o') $LDFLAGS \ -landroid-base \ -landroid-fw \ From 03383d086f7bf7f15cd774256eca165f6659b3f7 Mon Sep 17 00:00:00 2001 From: Birh Burh Date: Sun, 29 Jun 2025 04:04:19 +0200 Subject: [PATCH 3/3] fix properties.cpp segfault for appt2 --- packages/aapt/libbase-properties.cpp.patch | 30 +++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/aapt/libbase-properties.cpp.patch b/packages/aapt/libbase-properties.cpp.patch index 37eb473c012642a..5b55a10f80c6890 100644 --- a/packages/aapt/libbase-properties.cpp.patch +++ b/packages/aapt/libbase-properties.cpp.patch @@ -1,29 +1,47 @@ --- a/libbase/properties.cpp +++ b/libbase/properties.cpp -@@ -16,7 +16,7 @@ +@@ -16,8 +16,10 @@ #include "android-base/properties.h" -#if defined(__BIONIC__) -+#if defined(__BIONIC__) && !defined(__TERMUX__) ++#if 1 ++#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include ++#include #endif -@@ -31,7 +31,7 @@ + #include +@@ -31,7 +33,7 @@ #include #include -#if !defined(__BIONIC__) -+#if !defined(__BIONIC__) || defined(__TERMUX__) ++#if 0 // Here lies a rudimentary implementation of system properties for non-Bionic // platforms. We are using weak symbols here because we want to allow -@@ -178,7 +178,7 @@ bool SetProperty(const std::string& key, const std::string& value) { +@@ -161,13 +163,6 @@ std::string GetProperty(const std::string& key, const std::string& default_value + const prop_info* pi = __system_property_find(key.c_str()); + if (pi == nullptr) return default_value; + +- __system_property_read_callback( +- pi, +- [](void* cookie, const char*, const char* value, unsigned) { +- auto property_value = reinterpret_cast(cookie); +- *property_value = value; +- }, +- &property_value); + // If the property exists but is empty, also return the default value. + // Since we can't remove system properties, "empty" is traditionally + // the same as "missing" (this was true for cutils' property_get). +@@ -178,7 +173,7 @@ bool SetProperty(const std::string& key, const std::string& value) { return (__system_property_set(key.c_str(), value.c_str()) == 0); } -#if defined(__BIONIC__) -+#if defined(__BIONIC__) && !defined(__TERMUX__) ++#if 0 struct WaitForPropertyData { bool done; +