author | Anatol Pomozov
<anatolik@archlinux.org> 2020-05-11 06:47:38 UTC |
committer | Anatol Pomozov
<anatolik@archlinux.org> 2020-05-11 06:47:38 UTC |
parent | 830e171ddbd7a1c1fd615f8461bd69a2d84133e0 |
PKGBUILD | +11 | -9 |
fix_build_core.patch | +83 | -11 |
generate_build.rb | +44 | -19 |
diff --git a/PKGBUILD b/PKGBUILD index 399b466..5acea49 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -3,17 +3,17 @@ # Contributor: Alucryd <alucryd at gmail dot com> pkgname=android-tools -pkgver=29.0.6 +pkgver=30.0.0 pkgrel=1 tag=platform-tools-$pkgver pkgdesc='Android platform tools' arch=(x86_64) url='http://tools.android.com/' license=(Apache MIT) -depends=(pcre2 libusb protobuf) +depends=(pcre2 libusb protobuf brotli) optdepends=('python: for mkbootimg script' 'python2: for unpack_bootimg & avbtool scripts') -# depend on 'vim' for 'xxd' tool. +# it depends on 'vim' because of 'xxd' tool. makedepends=(git clang gtest ruby cmake ninja go vim) provides=(fastboot adb) conflicts=(fastboot adb) @@ -27,13 +27,14 @@ source=(git+https://android.googlesource.com/platform/frameworks/base#tag=$tag git+https://android.googlesource.com/platform/external/f2fs-tools#tag=$tag git+https://android.googlesource.com/platform/external/e2fsprogs#tag=$tag git+https://android.googlesource.com/platform/external/avb#tag=$tag + #git+https://android.googlesource.com/platform/external/boringssl#tag=$tag git+https://boringssl.googlesource.com/boringssl#commit=$_boringssl_commit generate_build.rb # deployagent.jar is a library built from Android sources. # Building this java library requires a lot of dependencies: # java, protobuf-java, dex compiler, Android base libs. # To avoid the complexity we prebuilt the lib from the Android sources directly -# using following instructiuons: +# using following instructions: # (See https://wiki.archlinux.org/index.php/Android for context) # # source build/envsetup.sh @@ -54,14 +55,12 @@ sha1sums=('SKIP' 'SKIP' 'SKIP' 'SKIP' - '37992d0d7547b7deb703f3232ec124a4c6b96aef' + '930c5d4b94f7cc09087fe599d4b868e7187abd74' 'd9dfac30245faa0a96968b96f3acd9ad536f4910' - '31779cd6c0df710be9589bd2ee4f697f59b100fd' + '70abd4483233ee481490b3369dbdd4977772c57f' '7004dbd0c193668827174880de6f8434de8ceaee') prepare() { - PLATFORM_TOOLS_VERSION="$pkgver-$pkgrel" LDFLAGS='-Wl,-z,relro,-z,now' ./generate_build.rb > build.ninja - cd "$srcdir"/core patch -p1 < ../fix_build_core.patch @@ -71,10 +70,13 @@ prepare() { cd "$srcdir"/mkbootimg sed -i 's|/usr/bin/env python$|/usr/bin/env python2|g' unpack_bootimg.py - mkdir -p "$srcdir"/boringssl/build && cd "$srcdir"/boringssl/build && cmake -GNinja ..; ninja crypto/libcrypto.a + mkdir -p "$srcdir"/boringssl/build } build() { + (cd "$srcdir"/boringssl/build && cmake -GNinja ..; ninja crypto/libcrypto.a ssl/libssl.a) + + PLATFORM_TOOLS_VERSION="$pkgver-$pkgrel" ./generate_build.rb > build.ninja ninja } diff --git a/fix_build_core.patch b/fix_build_core.patch index fede1c0..f2c4ae7 100644 --- a/fix_build_core.patch +++ b/fix_build_core.patch @@ -1,8 +1,8 @@ diff --git a/adb/adb.cpp b/adb/adb.cpp -index 1ec145b25c..b6e943f6ee 100644 +index 08d3904c71..a73362acec 100644 --- a/adb/adb.cpp +++ b/adb/adb.cpp -@@ -44,8 +44,6 @@ +@@ -45,8 +45,6 @@ #include <android-base/parsenetaddress.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> @@ -11,7 +11,7 @@ index 1ec145b25c..b6e943f6ee 100644 #include "adb_auth.h" #include "adb_io.h" -@@ -66,10 +64,10 @@ std::string adb_version() { +@@ -74,10 +72,10 @@ std::string adb_version() { // Don't change the format of this --- it's parsed by ddmlib. return android::base::StringPrintf( "Android Debug Bridge version %d.%d.%d\n" @@ -24,23 +24,34 @@ index 1ec145b25c..b6e943f6ee 100644 android::base::GetExecutablePath().c_str()); } +diff --git a/adb/client/adb_wifi.cpp b/adb/client/adb_wifi.cpp +index fa71028115..8c460f24fb 100644 +--- a/adb/client/adb_wifi.cpp ++++ b/adb/client/adb_wifi.cpp +@@ -242,5 +242,6 @@ void adb_wifi_pair_device(const std::string& host, const std::string& password, + // Write to adb_known_hosts + write_known_host_to_file(device_guid); + // Try to auto-connect. +- adb_secure_connect_by_service_name(device_guid.c_str()); ++ // ARCH: following function requires mdns code that is not compatible with mdns system library ++ // adb_secure_connect_by_service_name(device_guid.c_str()); + } diff --git a/adb/client/main.cpp b/adb/client/main.cpp -index 0c5c28f1b3..b6a1281521 100644 +index 05e210f607..99192831c5 100644 --- a/adb/client/main.cpp +++ b/adb/client/main.cpp -@@ -118,10 +118,6 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply - init_transport_registration(); +@@ -126,9 +126,6 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply init_reconnect_handler(); + adb_wifi_init(); - if (!getenv("ADB_MDNS") || strcmp(getenv("ADB_MDNS"), "0") != 0) { - init_mdns_transport_discovery(); - } -- + if (!getenv("ADB_USB") || strcmp(getenv("ADB_USB"), "0") != 0) { usb_init(); - } else { diff --git a/adb/client/usb_libusb.cpp b/adb/client/usb_libusb.cpp -index 53f01a0ce5..b4c3aadc28 100644 +index 07cbc9418c..6145392194 100644 --- a/adb/client/usb_libusb.cpp +++ b/adb/client/usb_libusb.cpp @@ -30,7 +30,7 @@ @@ -52,8 +63,57 @@ index 53f01a0ce5..b4c3aadc28 100644 #include <android-base/file.h> #include <android-base/logging.h> +diff --git a/adb/crypto/x509_generator.cpp b/adb/crypto/x509_generator.cpp +index 43b8153048..6900b3a497 100644 +--- a/adb/crypto/x509_generator.cpp ++++ b/adb/crypto/x509_generator.cpp +@@ -17,6 +17,7 @@ + #include "adb/crypto/x509_generator.h" + + #include <vector> ++#include <string.h> + + #include <android-base/logging.h> + #include <crypto_utils/android_pubkey.h> +diff --git a/adb/pairing_auth/aes_128_gcm.cpp b/adb/pairing_auth/aes_128_gcm.cpp +index 51520d814d..2d5f86fa81 100644 +--- a/adb/pairing_auth/aes_128_gcm.cpp ++++ b/adb/pairing_auth/aes_128_gcm.cpp +@@ -23,6 +23,8 @@ + #include <openssl/hkdf.h> + #include <openssl/rand.h> + ++#include <string.h> ++ + namespace adb { + namespace pairing { + +diff --git a/adb/pairing_auth/pairing_auth.cpp b/adb/pairing_auth/pairing_auth.cpp +index 0ac04e6913..de2aa740ea 100644 +--- a/adb/pairing_auth/pairing_auth.cpp ++++ b/adb/pairing_auth/pairing_auth.cpp +@@ -21,6 +21,7 @@ + #include <openssl/curve25519.h> + #include <openssl/mem.h> + ++#include <string.h> + #include <iomanip> + #include <sstream> + #include <vector> +diff --git a/adb/tls/tls_connection.cpp b/adb/tls/tls_connection.cpp +index 853cdac08c..3613c3768b 100644 +--- a/adb/tls/tls_connection.cpp ++++ b/adb/tls/tls_connection.cpp +@@ -18,6 +18,7 @@ + + #include <algorithm> + #include <vector> ++#include <limits.h> + + #include <android-base/logging.h> + #include <android-base/strings.h> diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp -index 2fe3b1a9e0..a61b221ce3 100644 +index 7f6e7230f4..808f2e0671 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -59,10 +59,8 @@ @@ -67,7 +127,7 @@ index 2fe3b1a9e0..a61b221ce3 100644 #include <sparse/sparse.h> #include <ziparchive/zip_archive.h> -@@ -1783,7 +1781,7 @@ int FastBootTool::Main(int argc, char* argv[]) { +@@ -1799,7 +1797,7 @@ int FastBootTool::Main(int argc, char* argv[]) { setvbuf(stdout, nullptr, _IONBF, 0); setvbuf(stderr, nullptr, _IONBF, 0); } else if (name == "version") { @@ -102,3 +162,15 @@ index ba4846e33b..f3fccc4895 100644 // // Deprecated: use `_Thread_local` in C or `thread_local` in C++. // +diff --git a/libziparchive/zip_cd_entry_map.h b/libziparchive/zip_cd_entry_map.h +index 4957f754e7..1cfb74dd5b 100644 +--- a/libziparchive/zip_cd_entry_map.h ++++ b/libziparchive/zip_cd_entry_map.h +@@ -17,6 +17,7 @@ + #pragma once + + #include <stdint.h> ++#include <stdlib.h> + + #include <map> + #include <memory> diff --git a/generate_build.rb b/generate_build.rb index 33a3048..aff64ad 100755 --- a/generate_build.rb +++ b/generate_build.rb @@ -1,8 +1,8 @@ #!/usr/bin/ruby -# Android build system is complicated and does not allow to build -# separate parts easily. -# This script tries to mimic Android build rules. +# Android has a huge and monolithic build system that does not allow to build +# components separately. +# This script tries to mimic Android build system for a small subset of source. def expand(dir, files) files.map { |f| File.join(dir, f) } @@ -18,10 +18,8 @@ def compile(sources, cflags, params = {}) case ext when ".c" cc = "cc" - lang_flags = "-std=gnu11 $CFLAGS $CPPFLAGS" when ".cpp", ".cc" cc = "cxx" - lang_flags = "-std=gnu++2a $CXXFLAGS $CPPFLAGS" else raise "Unknown extension #{ext}" end @@ -34,7 +32,8 @@ def compile(sources, cflags, params = {}) "" end - puts "build #{output}: #{cc} #{s}#{order_deps}\n cflags = #{lang_flags} #{cflags}" + # TODO: try to build the tools with LLVM libc: -stdlib=libc++ + puts "build #{output}: #{cc} #{s}#{order_deps}\n cflags = #{cflags}" end return outputs @@ -47,7 +46,7 @@ def protoc(source) hfile = basename + ".pb.h" ofile = cfile + ".o" puts "build #{cfile} #{hfile}: protoc #{source}" - puts "build #{ofile}: cc #{cfile}\n cflags = -std=gnu++2a $CXXFLAGS $CPPFLAGS -I." + puts "build #{ofile}: cxx #{cfile}\n cflags = -I." return hfile, cfile, ofile end @@ -61,7 +60,8 @@ end # Links object files def link(output, objects, ldflags) - puts "build #{output}: link #{objects.join(" ")}\n ldflags = #{ldflags} $LDFLAGS" + # TODO: try to build the tools with LLVM libc: -stdlib=libc++ + puts "build #{output}: link #{objects.join(" ")}\n ldflags = #{ldflags}" end def genheader(input, variable, output) @@ -72,16 +72,17 @@ puts "# This set of commands generated by generate_build.rb script\n\n" puts "CC = #{ENV["CC"] || "clang"}" puts "CXX = #{ENV["CXX"] || "clang++"}\n\n" puts "CFLAGS = #{ENV["CFLAGS"]}" +puts "CPPFLAGS = #{ENV["CPPFLAGS"]}" puts "CXXFLAGS = #{ENV["CXXFLAGS"]}" puts "LDFLAGS = #{ENV["LDFLAGS"]}" puts "PLATFORM_TOOLS_VERSION = #{ENV["PLATFORM_TOOLS_VERSION"]}\n\n" puts "" " rule cc - command = $CC $cflags -c $in -o $out + command = $CC -std=gnu11 $CFLAGS $CPPFLAGS $cflags -c $in -o $out rule cxx - command = $CXX $cflags -c $in -o $out + command = $CXX -std=gnu++2a $CXXFLAGS $CPPFLAGS $cflags -c $in -o $out rule link command = $CXX $ldflags $LDFLAGS $in -o $out @@ -95,6 +96,8 @@ rule genheader " "" +key_type_h, key_type_c, key_type_o = protoc("core/adb/proto/key_type.proto") + adbdfiles = %w( adb.cpp adb_io.cpp @@ -108,12 +111,14 @@ adbdfiles = %w( sockets.cpp transport.cpp transport_local.cpp - transport_usb.cpp types.cpp ) -libadbd = compile(expand("core/adb", adbdfiles), '-DPLATFORM_TOOLS_VERSION="\"$PLATFORM_TOOLS_VERSION\"" -DADB_HOST=1 -Icore/include -Icore/base/include -Icore/adb -Icore/libcrypto_utils/include -Iboringssl/include -Icore/diagnose_usb/include') +libadbd = compile(expand("core/adb", adbdfiles), '-DPLATFORM_TOOLS_VERSION="\"$PLATFORM_TOOLS_VERSION\"" -DADB_HOST=1 -Icore/include -Icore/base/include -Icore/adb -Icore/libcrypto_utils/include -Iboringssl/include -Icore/diagnose_usb/include -Icore/adb/crypto/include -Icore/adb/proto -Icore/adb/tls/include', :order_deps => [key_type_h]) apkent_h, apkent_c, apkent_o = protoc("core/adb/fastdeploy/proto/ApkEntry.proto") +app_processes_h, app_processes_c, app_processes_o = protoc("core/adb/proto/app_processes.proto") +adb_known_hosts_h, adb_known_hosts_c, adb_known_hosts_o = protoc("core/adb/proto/adb_known_hosts.proto") +pairing_h, pairing_c, pairing_o = protoc("core/adb/proto/pairing.proto") deployagent_inc = "core/adb/client/deployagent.inc" genheader("deployagent.jar", "kDeployAgent", deployagent_inc) @@ -124,6 +129,7 @@ genheader("core/adb/fastdeploy/deployagent/deployagent.sh", "kDeployAgentScript" adbfiles = %w( client/adb_client.cpp client/adb_install.cpp + client/adb_wifi.cpp client/auth.cpp client/bugreport.cpp client/commandline.cpp @@ -131,22 +137,35 @@ adbfiles = %w( client/fastdeploy.cpp client/fastdeploycallbacks.cpp client/file_sync_client.cpp + client/incremental.cpp + client/incremental_server.cpp + client/incremental_utils.cpp client/line_printer.cpp client/main.cpp + client/pairing/pairing_client.cpp + client/transport_usb.cpp client/usb_dispatch.cpp client/usb_libusb.cpp client/usb_linux.cpp + crypto/key.cpp + crypto/rsa_2048_key.cpp + crypto/x509_generator.cpp fastdeploy/deploypatchgenerator/apk_archive.cpp fastdeploy/deploypatchgenerator/deploy_patch_generator.cpp fastdeploy/deploypatchgenerator/patch_utils.cpp + pairing_auth/aes_128_gcm.cpp + pairing_auth/pairing_auth.cpp + pairing_connection/pairing_connection.cpp services.cpp socket_spec.cpp sysdeps/errno.cpp sysdeps/posix/network.cpp sysdeps_unix.cpp + tls/adb_ca_list.cpp + tls/tls_connection.cpp ) -libadb = compile(expand("core/adb", adbfiles), "-D_GNU_SOURCE -DADB_HOST=1 -Icore/include -Icore/base/include -Icore/adb -Icore/libcrypto_utils/include -Iboringssl/include -Ibase/libs/androidfw/include -Inative/include", :order_deps => [apkent_h, deployagent_inc, deployagentscript_inc]) - +libadb = compile(expand("core/adb", adbfiles), "-D_GNU_SOURCE -DADB_HOST=1 -Icore/include -Icore/base/include -Icore/adb -Icore/libcrypto_utils/include -Iboringssl/include -Ibase/libs/androidfw/include -Inative/include -Icore/adb/crypto/include -Icore/adb/proto -Icore/adb/tls/include -Icore/adb/pairing_connection/include -Icore/libziparchive/include -Icore/adb/pairing_auth/include", + :order_deps => [apkent_h, key_type_h, app_processes_h, adb_known_hosts_h, pairing_h, deployagent_inc, deployagentscript_inc]) androidfwfiles = %w( LocaleData.cpp ResourceTypes.cpp @@ -162,6 +181,7 @@ basefiles = %w( liblog_symbols.cpp logging.cpp mapped_file.cpp + parsebool.cpp parsenetaddress.cpp stringprintf.cpp strings.cpp @@ -206,8 +226,9 @@ libcryptofiles = %w( libcrypto = compile(expand("core/libcrypto_utils", libcryptofiles), "-Icore/libcrypto_utils/include -Iboringssl/include") # TODO: make subninja working -#boringssl = subninja('boringssl/build/', ['crypto/libcrypto.a']) -boringssl = ["boringssl/build/crypto/libcrypto.a"] +#boringssl = subninja('boringssl/build/', ['ssl/libssl.a']) +boringssl = ["boringssl/build/crypto/libcrypto.a", "boringssl/build/ssl/libssl.a"] +boringssl_ldflags = "-Wl,--whole-archive " + boringssl.join(" ") + " -Wl,--no-whole-archive" fastbootfiles = %w( bootimg_utils.cpp @@ -248,8 +269,12 @@ f2fs = compile(expand("extras/f2fs_utils", f2fsfiles), "-DHAVE_LINUX_TYPES_H -If zipfiles = %w( zip_archive.cc + zip_error.cpp + zip_cd_entry_map.cc ) -libzip = compile(expand("core/libziparchive", zipfiles), "-Icore/base/include -Icore/include -Icore/libziparchive/include") +# we use -std=c++17 as this lib currently does not compile with c++20 standard due to +# https://stackoverflow.com/questions/37618213/when-is-a-private-constructor-not-a-private-constructor/57430419#57430419 +libzip = compile(expand("core/libziparchive", zipfiles), "-std=c++17 -Icore/base/include -Icore/include -Icore/libziparchive/include") utilfiles = %w( FileMap.cpp @@ -323,7 +348,7 @@ libsepolfiles = %w( ) libsepol = compile(expand("selinux/libsepol/src", libsepolfiles), "-Iselinux/libsepol/include -Iselinux/libsepol/src") -link("fastboot", libfsmgr + libsparse + libzip + libcutils + liblog + libutil + libbase + libext4 + f2fs + libselinux + libsepol + libfastboot + libdiagnoseusb + boringssl, "-lz -lpcre2-8 -lpthread -ldl") +link("fastboot", libfsmgr + libsparse + libzip + libcutils + liblog + libutil + libbase + libext4 + f2fs + libselinux + libsepol + libfastboot + libdiagnoseusb, boringssl_ldflags + " -lz -lpcre2-8 -lpthread") # mke2fs.android - a ustom version of mke2fs that supports --android_sparse (FS#56955) libext2fsfiles = %w( @@ -462,4 +487,4 @@ ext2simg = compile(expand("e2fsprogs", ext2simgfiles), "-Ie2fsprogs/lib -Icore/l link("ext2simg", ext2simg + libext2fs + libsparse + libbase + libzip + liblog + libutil, "-lz -lpthread") -link("adb", libbase + liblog + libcutils + libutil + libadbd + libadb + libdiagnoseusb + libcrypto + boringssl + libandroidfw + libzip + [apkent_o], "-lpthread -lusb-1.0 -lprotobuf-lite -lz") +link("adb", libbase + liblog + libcutils + libutil + libadbd + libadb + libdiagnoseusb + libcrypto + libandroidfw + libzip + [apkent_o, key_type_o, app_processes_o, adb_known_hosts_o, pairing_o], boringssl_ldflags + " -lpthread -lusb-1.0 -lprotobuf -lz -llz4 -lbrotlidec -lbrotlienc")