upload android base code part3

This commit is contained in:
August 2018-08-08 16:48:17 +08:00
parent 71b83c22f1
commit b9e30e05b1
15122 changed files with 2089659 additions and 0 deletions

View file

@ -0,0 +1,29 @@
#!/bin/bash -ex
if [ -z "${OUT_DIR}" ]; then
echo Must set OUT_DIR
exit 1
fi
TOP=$(pwd)
source build/envsetup.sh
PLATFORM_SDK_VERSION=$(get_build_var PLATFORM_SDK_VERSION)
SOONG_OUT=${OUT_DIR}/soong
SOONG_NDK_OUT=${OUT_DIR}/soong/ndk
rm -rf ${SOONG_OUT}
mkdir -p ${SOONG_OUT}
cat > ${SOONG_OUT}/soong.config << EOF
{
"Ndk_abis": true,
"Platform_sdk_version": ${PLATFORM_SDK_VERSION}
}
EOF
BUILDDIR=${SOONG_OUT} ./bootstrap.bash
${SOONG_OUT}/soong ${SOONG_OUT}/ndk.timestamp
if [ -n "${DIST_DIR}" ]; then
mkdir -p ${DIST_DIR} || true
tar cjf ${DIST_DIR}/ndk_platform.tar.bz2 -C ${SOONG_OUT} ndk
fi

View file

@ -0,0 +1,7 @@
#!/bin/bash -e
OUT=$1
shift
LIBPATH=$($@)
cp -f $LIBPATH $OUT
echo "$OUT: $LIBPATH" > ${OUT}.d

View file

@ -0,0 +1,40 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
# Find the best reverse path to reference the current directory from another
# directory. We use this to find relative paths to and from the source and build
# directories.
#
# If the directory is given as an absolute path, return an absolute path to the
# current directory.
#
# If there's a symlink involved, and the same relative path would not work if
# the symlink was replace with a regular directory, then return an absolute
# path. This handles paths like out -> /mnt/ssd/out
#
# For symlinks that can use the same relative path (out -> out.1), just return
# the relative path. That way out.1 can be renamed as long as the symlink is
# updated.
#
# For everything else, just return the relative path. That allows the source and
# output directories to be moved as long as they stay in the same position
# relative to each other.
def reverse_path(path):
if path.startswith("/"):
return os.path.abspath('.')
realpath = os.path.relpath(os.path.realpath('.'), os.path.realpath(path))
relpath = os.path.relpath('.', path)
if realpath != relpath:
return os.path.abspath('.')
return relpath
if __name__ == '__main__':
print(reverse_path(sys.argv[1]))

View file

@ -0,0 +1,47 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import shutil
import tempfile
import unittest
from reverse_path import reverse_path
class TestReversePath(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
os.chdir(self.tmpdir)
def tearDown(self):
shutil.rmtree(self.tmpdir)
def test_absolute(self):
self.assertEqual(self.tmpdir, reverse_path('/out'))
def test_relative(self):
os.mkdir('a')
os.mkdir('b')
self.assertEqual('..', reverse_path('a'))
os.chdir('a')
self.assertEqual('a', reverse_path('..'))
self.assertEqual('.', reverse_path('../a'))
self.assertEqual('../a', reverse_path('../b'))
def test_symlink(self):
os.mkdir('b')
os.symlink('b', 'a')
os.mkdir('b/d')
os.symlink('b/d', 'c')
self.assertEqual('..', reverse_path('a'))
self.assertEqual('..', reverse_path('b'))
self.assertEqual(self.tmpdir, reverse_path('c'))
self.assertEqual('../..', reverse_path('b/d'))
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,67 @@
#!/bin/bash
set -e
#mounts the components of soong into a directory structure that Go tools and editors expect
#move to the script's directory
cd "$(dirname $0)"
SCRIPT_PATH="$PWD"
#find the root of the Repo checkout
cd "${SCRIPT_PATH}"/../../..
ANDROID_PATH="${PWD}"
OUTPUT_PATH="$(echo ${GOPATH} | sed 's/\:.*//')" #if GOPATH contains multiple paths, use the first one
if [ -z "${OUTPUT_PATH}" ]; then
echo "Error; could not determine the desired location at which to create a Go-compatible workspace. Please update GOPATH to specify the desired destination directory"
exit 1
fi
function confirm() {
while true; do
echo "Will create GOPATH-compatible directory structure at ${OUTPUT_PATH}"
echo -n "Ok [Y/n]?"
read decision
if [ "${decision}" == "y" -o "${decision}" == "Y" -o "${decision}" == "" ]; then
return 0
else
if [ "${decision}" == "n" ]; then
return 1
else
echo "Invalid choice ${decision}; choose either 'y' or 'n'"
fi
fi
done
}
function bindAll() {
bindOne "${ANDROID_PATH}/build/blueprint" "${OUTPUT_PATH}/src/github.com/google/blueprint"
bindOne "${ANDROID_PATH}/build/soong" "${OUTPUT_PATH}/src/android/soong"
bindOne "${ANDROID_PATH}/art/build" "${OUTPUT_PATH}/src/android/soong/art"
bindOne "${ANDROID_PATH}/external/llvm/soong" "${OUTPUT_PATH}/src/android/soong/llvm"
bindOne "${ANDROID_PATH}/external/clang/soong" "${OUTPUT_PATH}/src/android/soong/clang"
echo
echo "Created GOPATH-compatible directory structure at ${OUTPUT_PATH}"
}
function bindOne() {
#causes $newPath to mirror $existingPath
existingPath="$1"
newPath="$2"
mkdir -p "$newPath"
echoAndDo bindfs "${existingPath}" "${newPath}"
}
function echoAndDo() {
echo "$@"
eval "$@"
}
if confirm; then
echo
bindAll
else
echo "skipping due to user request"
exit 1
fi

View file

@ -0,0 +1,125 @@
#!/bin/bash -e
# Script to handle the various ways soong may need to strip binaries
# Inputs:
# Environment:
# CROSS_COMPILE: prefix added to readelf, objcopy tools
# Arguments:
# -i ${file}: input file (required)
# -o ${file}: output file (required)
# -d ${file}: deps file (required)
# --keep-symbols
# --keep-mini-debug-info
# --add-gnu-debuglink
OPTSTRING=d:i:o:-:
usage() {
cat <<EOF
Usage: strip.sh [options] -i in-file -o out-file -d deps-file
Options:
--keep-symbols Keep symbols in out-file
--keep-mini-debug-info Keep compressed debug info in out-file
--add-gnu-debuglink Add a gnu-debuglink section to out-file
EOF
exit 1
}
do_strip() {
"${CROSS_COMPILE}strip" --strip-all "${infile}" -o "${outfile}.tmp"
}
do_strip_keep_symbols() {
"${CROSS_COMPILE}objcopy" "${infile}" "${outfile}.tmp" \
`"${CROSS_COMPILE}readelf" -S "${infile}" | awk '/.debug_/ {print "-R " $2}' | xargs`
}
do_strip_keep_mini_debug_info() {
rm -f "${outfile}.dynsyms" "${outfile}.funcsyms" "${outfile}.keep_symbols" "${outfile}.debug" "${outfile}.mini_debuginfo" "${outfile}.mini_debuginfo.xz"
if "${CROSS_COMPILE}strip" --strip-all -R .comment "${infile}" -o "${outfile}.tmp"; then
"${CROSS_COMPILE}objcopy" --only-keep-debug "${infile}" "${outfile}.debug"
"${CROSS_COMPILE}nm" -D "${infile}" --format=posix --defined-only | awk '{ print $$1 }' | sort >"${outfile}.dynsyms"
"${CROSS_COMPILE}nm" "${infile}" --format=posix --defined-only | awk '{ if ($$2 == "T" || $$2 == "t" || $$2 == "D") print $$1 }' | sort > "${outfile}.funcsyms"
comm -13 "${outfile}.dynsyms" "${outfile}.funcsyms" > "${outfile}.keep_symbols"
"${CROSS_COMPILE}objcopy" --rename-section .debug_frame=saved_debug_frame "${outfile}.debug" "${outfile}.mini_debuginfo"
"${CROSS_COMPILE}objcopy" -S --remove-section .gdb_index --remove-section .comment --keep-symbols="${outfile}.keep_symbols" "${outfile}.mini_debuginfo"
"${CROSS_COMPILE}objcopy" --rename-section saved_debug_frame=.debug_frame "${outfile}.mini_debuginfo"
xz "${outfile}.mini_debuginfo"
"${CROSS_COMPILE}objcopy" --add-section .gnu_debugdata="${outfile}.mini_debuginfo.xz" "${outfile}.tmp"
else
cp -f "${infile}" "${outfile}.tmp"
fi
}
do_add_gnu_debuglink() {
"${CROSS_COMPILE}objcopy" --add-gnu-debuglink="${infile}" "${outfile}.tmp"
}
while getopts $OPTSTRING opt; do
case "$opt" in
d) depsfile="${OPTARG}" ;;
i) infile="${OPTARG}" ;;
o) outfile="${OPTARG}" ;;
-)
case "${OPTARG}" in
keep-symbols) keep_symbols=true ;;
keep-mini-debug-info) keep_mini_debug_info=true ;;
add-gnu-debuglink) add_gnu_debuglink=true ;;
*) echo "Unknown option --${OPTARG}"; usage ;;
esac;;
?) usage ;;
*) echo "'${opt}' '${OPTARG}'"
esac
done
if [ -z "${infile}" ]; then
echo "-i argument is required"
usage
fi
if [ -z "${outfile}" ]; then
echo "-o argument is required"
usage
fi
if [ -z "${depsfile}" ]; then
echo "-d argument is required"
usage
fi
if [ ! -z "${keep_symbols}" -a ! -z "${keep_mini_debug_info}" ]; then
echo "--keep-symbols and --keep-mini-debug-info cannot be used together"
usage
fi
if [ ! -z "${add_gnu_debuglink}" -a ! -z "${keep_mini_debug_info}" ]; then
echo "--add-gnu-debuglink cannot be used with --keep-mini-debug-info"
usage
fi
rm -f "${outfile}.tmp"
if [ ! -z "${keep_symbols}" ]; then
do_strip_keep_symbols
elif [ ! -z "${keep_mini_debug_info}" ]; then
do_strip_keep_mini_debug_info
else
do_strip
fi
if [ ! -z "${add_gnu_debuglink}" ]; then
do_add_gnu_debuglink
fi
rm -f "${outfile}"
mv "${outfile}.tmp" "${outfile}"
cat <<EOF > "${depsfile}"
${outfile}: \
${infile} \
${CROSS_COMPILE}nm \
${CROSS_COMPILE}objcopy \
${CROSS_COMPILE}readelf \
${CROSS_COMPILE}strip
EOF

View file

@ -0,0 +1,75 @@
#!/bin/bash -eu
# Script to handle generating a .toc file from a .so file
# Inputs:
# Environment:
# CROSS_COMPILE: prefix added to readelf tool
# Arguments:
# -i ${file}: input file (required)
# -o ${file}: output file (required)
# -d ${file}: deps file (required)
OPTSTRING=d:i:o:-:
usage() {
cat <<EOF
Usage: toc.sh [options] -i in-file -o out-file -d deps-file
Options:
EOF
exit 1
}
do_elf() {
("${CROSS_COMPILE}readelf" -d "${infile}" | grep SONAME || echo "No SONAME for ${infile}") > "${outfile}.tmp"
"${CROSS_COMPILE}readelf" --dyn-syms "${infile}" | awk '{$2=""; $3=""; print}' >> "${outfile}.tmp"
}
do_macho() {
otool -l "${infile}" | grep LC_ID_DYLIB -A 5 > "${outfile}.tmp"
nm -gP "${infile}" | cut -f1-2 -d" " | grep -v 'U$' >> "${outfile}.tmp"
}
while getopts $OPTSTRING opt; do
case "$opt" in
d) depsfile="${OPTARG}" ;;
i) infile="${OPTARG}" ;;
o) outfile="${OPTARG}" ;;
-)
case "${OPTARG}" in
*) echo "Unknown option --${OPTARG}"; usage ;;
esac;;
?) usage ;;
*) echo "'${opt}' '${OPTARG}'"
esac
done
if [ -z "${infile}" ]; then
echo "-i argument is required"
usage
fi
if [ -z "${outfile}" ]; then
echo "-o argument is required"
usage
fi
if [ -z "${depsfile}" ]; then
echo "-d argument is required"
usage
fi
rm -f "${outfile}.tmp"
cat <<EOF > "${depsfile}"
${outfile}: \\
${CROSS_COMPILE}readelf \\
EOF
do_elf
if cmp "${outfile}" "${outfile}.tmp" > /dev/null 2> /dev/null; then
rm -f "${outfile}.tmp"
else
mv -f "${outfile}.tmp" "${outfile}"
fi