# vim: filetype=yaml sw=2
# FIXME: Rework this whole mess
filename: '[% project %]-[% c("version") %]-[% c("var/build_id") %].tar.[% c("compress_tar") %]'
version: '34.0.0'
var:
  setup: |
    mkdir -p /var/tmp/dist
    tar -C /var/tmp/dist -xf $rootdir/[% c("compiler_tarfile") %]
    export ANDROID_HOME=/var/tmp/dist/[% project %]/android-sdk-linux
    export PATH=$PATH:$ANDROID_HOME/build-tools/[% c("version") %]
    # By default we use the old NDK which is the one GeckoView is using.
    # However, we can overwrite that per project if needed (e.g.
    # application-services is currently on a newer NDK).
    # But an NDK is more than 1.5GB, so it does not make sense to copy one that
    # is not even used in all containers. Instead, we download the additional
    # NDK only in application-services, and adjust the other variables here.
    [% IF c("ndk_version") -%]
      export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/android-ndk-r[% c("ndk_version") %]
    [% ELSE -%]
      export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/android-ndk-r[% c("var/android_ndk_version") %][% c('var/android_ndk_revision') %]
    [% END -%]
    export ANDROID_NDK_ROOT=$ANDROID_NDK_HOME
    export NDK_HOST_TAG=linux-x86_64
    export PATH=$PATH:$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin
    [% IF c("gradle_tarfile") -%]
      tar -C /var/tmp/dist/[% project %] -xf $rootdir/[% c("gradle_tarfile") %]
      export GRADLE_HOME=/var/tmp/dist/[% project %]/gradle
      export GRADLE_USER_HOME=$GRADLE_HOME
      export PATH=$PATH:$GRADLE_HOME/bin
    [% END -%]
  google_repo: https://dl.google.com/android/repository
  android_api_level: 34
  android_release_dir: android-14
  android_platform_revision: '03'
  android_ndk_version: 26
  android_ndk_revision: c
  android_ndk_version_build: 26.2.11394342
  # We need the following two variables for get_build_tools, used by signing
  # scripts.
  build_tools_version: 34
  build_tools_filename: 'build-tools_r[% c("var/build_tools_version") %]-linux.zip'
  build_tools_sha512sum: c28dd52f8eca82996726905617f3cb4b0f0aee1334417b450d296991d7112cab1288f5fd42c48a079ba6788218079f81caa3e3e9108e4a6f27163a1eb7f32bd7
  commandlinetools_version: 11076708
  commandlinetools_version_string: 12.0
input_files:
  # Hashes can be compared with https://gitlab.com/fdroid/android-sdk-transparency-log/-/blob/master/checksums.json
  - URL: '[% c("var/google_repo") %]/commandlinetools-linux-[% c("var/commandlinetools_version") %]_latest.zip'
    name: android_commandlinetools
    sha256sum: 2d2d50857e4eb553af5a6dc3ad507a17adf43d115264b1afc116f95c92e5e258
  - URL: '[% c("var/google_repo") %]/android-ndk-r[% c("var/android_ndk_version") %][% c("var/android_ndk_revision") %]-linux.zip'
    name: android_ndk_compiler
    sha256sum: 6d6e659834d28bb24ba7ae66148ad05115ebbad7dabed1af9b3265674774fcf6
  - URL: '[% c("var/google_repo") %]/[% c("var/build_tools_filename") %]'
    name: build_tools
    sha512sum: '[% c("var/build_tools_sha512sum") %]'
  - URL: '[% c("var/google_repo") %]/platform-[% c("var/android_api_level") %]-ext7_r[% c("var/android_platform_revision") %].zip'
    name: platform
    sha256sum: 16fdb74c55e59ae3ef52def135aec713508467bd56d7dabcd8c9be31fa8b20f3
  # ./mach bootstrap is fetching the latest version, so it does not seem to
  # matter which particular version we are using. Pin to the one fitting best to
  # SDK version/build-tools version.
  - URL: '[% c("var/google_repo") %]/platform-tools_r[% c("version") %]-linux.zip'
    name: platform_tools
    sha256sum: 8137c2834dea05cb64c1a8bc041ea00fcd43e3a8a29429ad4f25b8ee51efebf6
steps:
  # The get_build_tools step is used by tools/signing/android-signing
  get_build_tools:
    filename: 'android-[% c("var/build_tools_filename") %]'
    get_build_tools: |
      #!/bin/bash
      set -e
      mv -v [% c("input_files_by_name/build_tools") %] [% dest_dir _ '/' _ c('filename') %]
    container:
      use_container: 0
    input_files:
      - URL: '[% c("var/google_repo") %]/[% c("var/build_tools_filename") %]'
        name: build_tools
        sha512sum: '[% c("var/build_tools_sha512sum") %]'
