*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / dev-util / android-tools / android-tools-9.0.0_p3.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="6"
5
6 PYTHON_COMPAT=( python2_7 python3_{6,7} )
7 CMAKE_MAKEFILE_GENERATOR="ninja"
8
9 inherit flag-o-matic bash-completion-r1 ninja-utils toolchain-funcs cmake-utils python-r1
10
11 MY_PV="${PV/_p/_r}"
12 MY_P=${PN}-${MY_PV}
13
14 DESCRIPTION="Android platform tools (adb, fastboot, and mkbootimg)"
15 HOMEPAGE="https://android.googlesource.com/platform/system/core.git/"
16 # See helper scripts in files/ for creating these tarballs and getting this hash.
17 BORINGSSL_SHA1="45210dd4e21ace9d28cb76b3f83303fcdd2efcce"
18 # The ninja file was created by running the ruby script from archlinux by hand and fixing the build vars.
19 # No point in depending on something large/uncommon like ruby just to generate a ninja file.
20 SRC_URI="https://git.archlinux.org/svntogit/community.git/snapshot/community-0ffb7b41d599741d100a6a00a4bb20e162cd3f90.tar.xz -> ${MY_P}-arch.tar.xz
21         https://github.com/android/platform_system_core/archive/android-${MY_PV}.tar.gz -> ${MY_P}-core.tar.gz
22         https://github.com/google/boringssl/archive/${BORINGSSL_SHA1}.tar.gz -> boringssl-${BORINGSSL_SHA1}.tar.gz
23         mirror://gentoo/${MY_P}-e2fsprogs.tar.xz https://dev.gentoo.org/~zmedico/dist/${MY_P}-e2fsprogs.tar.xz
24         mirror://gentoo/${MY_P}-extras.tar.xz https://dev.gentoo.org/~zmedico/dist/${MY_P}-extras.tar.xz
25         mirror://gentoo/${MY_P}-selinux.tar.xz https://dev.gentoo.org/~zmedico/dist/${MY_P}-selinux.tar.xz
26         mirror://gentoo/${MY_P}-f2fs-tools.tar.xz https://dev.gentoo.org/~zmedico/dist/${MY_P}-f2fs-tools.tar.xz
27         mirror://gentoo/${MY_P}.ninja.xz https://dev.gentoo.org/~zmedico/dist/${MY_P}.ninja.xz"
28
29 # The entire source code is Apache-2.0, except for fastboot which is BSD-2.
30 LICENSE="Apache-2.0 BSD-2"
31 SLOT="0"
32 KEYWORDS="amd64 ~arm x86 ~x86-linux"
33 IUSE="python"
34 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
35
36 DEPEND="sys-libs/zlib:=
37         dev-libs/libpcre2:=
38         virtual/libusb:1="
39 RDEPEND="${DEPEND}
40         python? ( ${PYTHON_DEPS} )"
41 DEPEND+="
42         dev-lang/go"
43
44 S=${WORKDIR}
45 CMAKE_USE_DIR="${S}/boringssl"
46
47 unpack_into() {
48         local archive="$1"
49         local dir="$2"
50
51         mkdir -p "${dir}"
52         pushd "${dir}" >/dev/null || die
53         unpack "${archive}"
54         if [[ ${dir} != ./* ]] ; then
55                 mv */* ./ || die
56         fi
57         popd >/dev/null
58 }
59
60 src_unpack() {
61         unpack_into "${MY_P}-arch.tar.xz" arch
62         unpack_into "${MY_P}-core.tar.gz" core
63         unpack_into "${MY_P}-e2fsprogs.tar.xz" ./e2fsprogs
64         unpack_into "${MY_P}-extras.tar.xz" extras
65         unpack_into "${MY_P}-f2fs-tools.tar.xz" ./f2fs-tools
66         unpack_into "${MY_P}-selinux.tar.xz" ./selinux
67         unpack_into boringssl-${BORINGSSL_SHA1}.tar.gz boringssl
68
69         unpack "${MY_P}.ninja.xz"
70         mv "${MY_P}.ninja" "build.ninja" || die
71
72         # Avoid depending on gtest just for its prod headers when boringssl bundles it.
73         ln -s ../../boringssl/third_party/googletest/include/gtest core/include/ || die
74 }
75
76 src_prepare() {
77         sed -e 's:elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386"):\0\n  set(ARCH "x86")\nelseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i586"):' \
78                 -i "${S}"/boringssl/CMakeLists.txt || die #668792
79
80         cd "${S}"/core || die
81         eapply "${WORKDIR}"/arch/trunk/fix_build_core.patch
82         eapply "${FILESDIR}"/android-tools-8.1.0_p1-build.patch
83
84         cd "${S}"/selinux || die
85         eapply "${WORKDIR}"/arch/trunk/fix_build_selinux.patch
86
87         cd "${S}"/e2fsprogs || die
88         eapply "${WORKDIR}"/arch/trunk/fix_build_e2fsprogs.patch
89
90         cd "${S}"/extras
91         sed -e 's|^#include <sys/cdefs.h>$|/*\0*/|' \
92                 -e 's|^__BEGIN_DECLS$|#ifdef __cplusplus\nextern "C" {\n#endif|' \
93                 -e 's|^__END_DECLS$|#ifdef __cplusplus\n}\n#endif|' \
94                 -i ext4_utils/include/ext4_utils/ext4_crypt{,_init_extensions}.h || die #580686
95
96         cd "${S}" || die
97         default
98
99         sed -E \
100                 -e "s|^(CC =).*|\\1 $(tc-getCC)|g" \
101                 -e "s|^(CXX =).*|\\1 $(tc-getCXX)|g" \
102                 -e "s|^(CFLAGS =).*|\\1 ${CFLAGS}|g" \
103                 -e "s|^(CPPFLAGS =).*|\\1 ${CPPFLAGS}|g" \
104                 -e "s|^(CXXFLAGS =).*|\\1 ${CXXFLAGS}|g" \
105                 -e "s|^(LDFLAGS =).*|\\1 ${LDFLAGS}|g" \
106                 -e "s|^(PKGVER =).*|\\1 ${MY_PV}|g" \
107                 -i build.ninja || die
108
109         # The pregenerated ninja file expects the build/ dir.
110         BUILD_DIR="${CMAKE_USE_DIR}/build"
111         cmake-utils_src_prepare
112 }
113
114 src_configure() {
115         append-lfs-flags
116
117         cmake-utils_src_configure
118 }
119
120 src_compile() {
121         # We only need a few libs from boringssl.
122         cmake-utils_src_compile libcrypto.a libssl.a
123
124         eninja
125 }
126
127 src_install() {
128         dobin adb e2fsdroid ext2simg fastboot mke2fs.android
129         dodoc core/adb/*.{txt,TXT} core/fastboot/README.md
130         use python && python_foreach_impl python_doexe core/mkbootimg/mkbootimg
131         newbashcomp arch/trunk/bash_completion.fastboot fastboot
132 }