Skip to content

Instantly share code, notes, and snippets.

@wolkenschieber
Forked from J-Swift/generate_android_sources.sh
Last active September 30, 2017 07:47
Show Gist options
  • Select an option

  • Save wolkenschieber/d3c50d378b7981b816606c67c3323fff to your computer and use it in GitHub Desktop.

Select an option

Save wolkenschieber/d3c50d378b7981b816606c67c3323fff to your computer and use it in GitHub Desktop.

Revisions

  1. wolkenschieber revised this gist Sep 30, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions generate_android_sources.sh
    Original file line number Diff line number Diff line change
    @@ -52,6 +52,8 @@ package_sources() {
    maybe_install_sources() {
    local -r zip_name="${1}"

    cp "${zip_name}" "${CUR_DIR}/"

    local -r sources_dir="${ANDROID_HOME}/sources"
    local -r target_path="${sources_dir}/android-${API_LEVEL}"

    @@ -62,8 +64,6 @@ maybe_install_sources() {
    local -r zip_path="${CUR_DIR}/${zip_name}"
    if [ -f "${zip_path}" ]; then
    echo "WARN: nevermind, file exists [${zip_path}] skipping..."
    else
    cp "${zip_name}" "${CUR_DIR}/"
    fi
    else
    unzip "${zip_name}" -d "${sources_dir}"
    @@ -83,7 +83,7 @@ main() {
    package_sources "${zip_name}"
    maybe_install_sources "${zip_name}"

    #teardown
    teardown
    }

    main
  2. wolkenschieber revised this gist Sep 30, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion generate_android_sources.sh
    Original file line number Diff line number Diff line change
    @@ -83,7 +83,7 @@ main() {
    package_sources "${zip_name}"
    maybe_install_sources "${zip_name}"

    teardown
    #teardown
    }

    main
  3. wolkenschieber revised this gist Sep 30, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion generate_android_sources.sh
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ package_sources() {
    cat development/build/tools/mk_sources_zip.py | sed -e "s/TOP_FOLDER = .*/TOP_FOLDER = \"android-${API_LEVEL}\"/" > my_mk_sources_zip.py

    # Run the script to create android-26-sources.zip
    python my_mk_sources_zip.py -z source.properties "${zip_name}" .
    python2 my_mk_sources_zip.py -z source.properties "${zip_name}" .
    }

    maybe_install_sources() {
  4. wolkenschieber revised this gist Sep 30, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions generate_android_sources.sh
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@ set -euo pipefail

    readonly GIT_BRANCH='android-8.0.0_r12'
    readonly API_LEVEL='26'
    readonly ANDROID_HOME='/mnt/Storage/android/androidSDK'

    ###########
    # Helpers #
  5. wolkenschieber revised this gist Sep 30, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions generate_android_sources.sh
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    #!/usr/bin/env sh
    #!/usr/bin/env bash

    set -euo pipefail

    ##########
    # Config #
    ##########

    readonly GIT_BRANCH='android-8.0.0_r4'
    readonly GIT_BRANCH='android-8.0.0_r12'
    readonly API_LEVEL='26'

    ###########
  6. @J-Swift J-Swift created this gist Sep 15, 2017.
    88 changes: 88 additions & 0 deletions generate_android_sources.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    #!/usr/bin/env sh

    set -euo pipefail

    ##########
    # Config #
    ##########

    readonly GIT_BRANCH='android-8.0.0_r4'
    readonly API_LEVEL='26'

    ###########
    # Helpers #
    ###########

    readonly CUR_DIR=$( pwd )
    readonly WORKING_DIR=$( mktemp -d )

    setup() {
    pushd ${WORKING_DIR}
    mkdir -p frameworks/base
    }

    teardown() {
    popd
    rm -rf "${WORKING_DIR}"
    }

    fetch_sources() {
    local -r target_branch="${1}"

    # Fetch repositories that contain the sources we're interested in
    git clone --depth 1 https://android.googlesource.com/platform/frameworks/base -b "${target_branch}" frameworks/base
    git clone --depth 1 https://android.googlesource.com/platform/libcore -b "${target_branch}"
    git clone --depth 1 https://android.googlesource.com/platform/development -b "${target_branch}"
    }

    package_sources() {
    local -r zip_name="${1}"

    # Create a basic source.properties file
    echo -e "Pkg.UserSrc=false\nPkg.Revision=1\nAndroidVersion.ApiLevel=${API_LEVEL}" > source.properties

    # Modify the script to create a sources ZIP to use "android-26" as top-level directory
    cat development/build/tools/mk_sources_zip.py | sed -e "s/TOP_FOLDER = .*/TOP_FOLDER = \"android-${API_LEVEL}\"/" > my_mk_sources_zip.py

    # Run the script to create android-26-sources.zip
    python my_mk_sources_zip.py -z source.properties "${zip_name}" .
    }

    maybe_install_sources() {
    local -r zip_name="${1}"

    local -r sources_dir="${ANDROID_HOME}/sources"
    local -r target_path="${sources_dir}/android-${API_LEVEL}"

    if [ -d "${target_path}" ]; then
    echo ""
    echo "WARN: directory exists [${target_path}] copying instead..."

    local -r zip_path="${CUR_DIR}/${zip_name}"
    if [ -f "${zip_path}" ]; then
    echo "WARN: nevermind, file exists [${zip_path}] skipping..."
    else
    cp "${zip_name}" "${CUR_DIR}/"
    fi
    else
    unzip "${zip_name}" -d "${sources_dir}"
    fi
    }

    ###############
    # DO WORK SON #
    ###############

    main() {
    local -r zip_name="android-${API_LEVEL}-sources.zip"

    setup

    fetch_sources "${GIT_BRANCH}"
    package_sources "${zip_name}"
    maybe_install_sources "${zip_name}"

    teardown
    }

    main