# vim: filetype=yaml sw=2
version: '[% c("abbrev") %]'
filename: 'geckoview-[% c("version") %]-[% c("var/osname") %]-[% c("var/build_id") %].tar.gz'
git_hash: 'tor-browser-[% c("var/geckoview_version") %]-[% c("var/torbrowser_branch") %]-1-build2'
tag_gpg_id: 1
git_url: https://git.torproject.org/tor-browser.git
git_submodule: 1
gpg_keyring: torbutton.gpg

var:
  geckoview_version: '81.0b[% c("var/beta_version") %]'
  beta_version: 2
  torbrowser_branch: 10.0
  copyright_year: '[% exec("git show -s --format=%ci").remove("-.*") %]'
  deps:
    - build-essential
    - unzip
    - zip
    - autoconf2.13
    - yasm
    # We are building our own version of Python 3.6, which is required
    # for the build. However mach still requires Python 2.7, so we
    # install this version using the package.
    - python
    - pkg-config
  container:
    use_container: 1
  # this should be updated when the list of gradle dependencies is changed
  gradle_dependencies_version: 2

steps:
  merge_aars:
    filename: 'geckoview-[% c("version") %]-[% c("var/build_id") %].tar.gz'
    version: '[% c("abbrev") %]'
    merge_aars: |
      #!/bin/bash
      [% c("var/set_default_env") -%]
      [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
      distdir=/var/tmp/dist
      builddir=/var/tmp/build
      mkdir -p /var/tmp/build
      mkdir -p $distdir/[% project %]

      cat > get-moz-build-date << "EOF"
      [% INCLUDE "get-moz-build-date" %]
      EOF

      tar -C $distdir -xf [% c('input_files_by_name/node') %]
      tar -C $distdir -xf [% c('input_files_by_name/python') %]
      export PATH="/var/tmp/dist/node/bin:/var/tmp/dist/python/bin:$PATH"

      tar -C $builddir -xf [% c('input_files_by_name/geckoview_armv7') %]
      tar -C $builddir -xf [% c('input_files_by_name/geckoview_aarch64') %]
      tar -C $builddir -xf [% c('input_files_by_name/geckoview_x86') %]
      tar -C $builddir -xf [% c('input_files_by_name/geckoview_x86_64') %]
      tar -C $builddir -xf [% project %]-[% c('version') %].tar.gz

      # Specify the architectures we want to merge
      export MOZ_ANDROID_FAT_AAR_ARCHITECTURES=armeabi-v7a,arm64-v8a,x86,x86_64
      export MOZ_ANDROID_FAT_AAR_ARMEABI_V7A=$builddir/geckoview/*armeabi-v7a*.aar
      export MOZ_ANDROID_FAT_AAR_ARM64_V8A=$builddir/geckoview/*arm64-v8a*.aar
      # Specifying just "x86" is not differentiating enough
      export MOZ_ANDROID_FAT_AAR_X86=$builddir/geckoview/*x86-*.aar
      export MOZ_ANDROID_FAT_AAR_X86_64=$builddir/geckoview/*x86_64*.aar

      cd $builddir/[% project %]-[% c("version") %]
      mv -f $rootdir/[% c('input_files_by_name/mozconfig') %] .mozconfig

      eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
      if [ -z $MOZ_BUILD_DATE ]
      then
          echo "MOZ_BUILD_DATE is not set"
          exit 1
      fi

      gradle_repo=/var/tmp/dist/gradle-dependencies
      export GRADLE_MAVEN_REPOSITORIES="file://$gradle_repo"
      export GRADLE_FLAGS="--no-daemon --offline"
      mv $rootdir/[% c('input_files_by_name/gradle-dependencies') %] $gradle_repo
      cp -r $gradle_repo/m2/* $gradle_repo

      # We unbreak mach, see: https://bugzilla.mozilla.org/show_bug.cgi?id=1656993.
      export MACH_USE_SYSTEM_PYTHON=1
      # We still need to specify --tor-browser-version due to bug 34005.
      ./mach configure --with-tor-browser-version=[% c("var/torbrowser_version") %]
      ./mach build --verbose
      find obj-* -regex '.*geckoview.*[0-9].\(aar\|pom\)' -exec cp {} $distdir/[% project %] \;

      cd $distdir/
      [% c('tar', {
              tar_src => [ project ],
              tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
         }) %]


    input_files:
      - project: container-image
        pkg_type: build
      - name: '[% c("var/compiler") %]'
        project: '[% c("var/compiler") %]'
        pkg_type: build
      - project: node
        name: node
        pkg_type: build
      - project: python
        name: python
        pkg_type: build
      - filename: mozconfig-android-all
        name: mozconfig
      - filename: 'gradle-dependencies-[% c("var/gradle_dependencies_version") %]'
        name: gradle-dependencies
        exec: '[% INCLUDE "fetch-gradle-dependencies" %]'
      - name: geckoview_armv7
        project: geckoview
        pkg_type: build
        target_prepend:
          - torbrowser-android-armv7
      - name: geckoview_aarch64
        project: geckoview
        pkg_type: build
        target_prepend:
          - torbrowser-android-aarch64
      - name: geckoview_x86
        project: geckoview
        pkg_type: build
        target_prepend:
          - torbrowser-android-x86
      - name: geckoview_x86_64
        project: geckoview
        pkg_type: build
        target_prepend:
          - torbrowser-android-x86_64


targets:
  nightly:
    git_hash: 'tor-browser-[% c("var/geckoview_version") %]-[% c("var/torbrowser_branch") %]-1'
    tag_gpg_id: 0

input_files:
  - project: container-image
  - name: '[% c("var/compiler") %]'
    project: '[% c("var/compiler") %]'
  - filename: 'mozconfig-[% c("var/osname") %]'
    name: mozconfig
  - project: binutils
    name: binutils
  - project: fenix-rust
    name: rust
  - project: fenix-cbindgen
    name: cbindgen
  - project: node
    name: node
  - project: nasm
    name: nasm
  - project: python
    name: python
  - project: fenix-clang
    name: clang
  - filename: 'gradle-dependencies-[% c("var/gradle_dependencies_version") %]'
    name: gradle-dependencies
    exec: '[% INCLUDE "fetch-gradle-dependencies" %]'
