# vim: filetype=yaml sw=2
version: '[% c("var/webrtc_tag") %]'
filename: 'webrtc-[% c("version") %]-[% c("var/osname") %]-[% c("var/build_id") %].tar.gz'

var:
  container:
    use_container: 1
  webrtc_tag: 88f5d9180eae78a6162cccd78850ff416eb82483

input_files:
  - project: container-image
  - project: webrtc
    pkg_type: fetch_sources
  - project: depot_tools
    name: depot_tools
  - name: '[% c("var/compiler") %]'
    project: '[% c("var/compiler") %]'
  - project: binutils
    name: binutils
    enable: '[% c("var/linux") %]'
  - filename: webrtc-linux.patch
    enable: '[% c("var/linux") %]'
  - filename: webrtc-mac.patch
    enable: '[% c("var/osx") %]'

targets:
  linux:
    var:
      webrtc:
        os: linux
  linux-i686:
    var:
      webrtc:
        lib_path: lib/libwebrtc-linux-386-magic.a
      sort_deps: 0
      arch_deps:
        - lib32asound2-dev
        - lib64expat1
        - libexpat1-dev:i386
        - libglib2.0-dev:i386
        - libgtk2.0-dev:i386
        - libgtk-3-dev:i386
        - libudev-dev:i386
        - libx11-dev:i386
        - libxext-dev:i386
        - libxrandr-dev:i386
        - pkg-config
        - hardening-wrapper
  linux-x86_64:
    var:
      webrtc:
        lib_path: lib/libwebrtc-linux-amd64-magic.a
      arch_deps:
        - libasound2-dev
        - libexpat1-dev
        - libglib2.0-dev
        - libgtk2.0-dev
        - libgtk-3-dev
        - libudev-dev
        - libx11-dev
        - libxext-dev
        - libxrandr-dev
        - pkg-config
  osx-x86_64:
    var:
      webrtc:
        lib_path: lib/libwebrtc-darwin-amd64-magic.a
      arch_deps:
        - libglib2.0-dev
        - libgtk2.0-dev
        - pkg-config
        - python-biplist

steps:
  fetch_sources:
    var:
      container:
        use_container: 0
    filename: 'webrtc-sources-[% c("var/webrtc_tag") %].tar.gz'
    fetch_sources: |
      #!/bin/bash
      [% c("var/set_default_env") -%]
      # WebRTC is special, having its own build system that brings in lots of Chromium dependencies.
      # https://webrtc.org/native-code/development/
      tar xf [% c('input_files_by_name/depot_tools') %]
      export PATH="$rootdir/depot_tools:$PATH"
      # Use --no-history because the whole checkout with history is about 12 GB.
      # JAVA_HOME is needed in a hook for libjingle. The readlink line tries to find the current JRE.
      # default-java comes from the package default-jdk-headless.
      export JAVA_HOME=/usr/lib/jvm/default-java
      clone_dir='[% c("basedir") %]/gclient/webrtc'
      mkdir -p "$clone_dir"
      cd "$clone_dir"
      if [ ! -d "src" ];
      then
        # "fetch" is part of depot_tools.
        #fetch --nohooks --no-history webrtc
        # FIXME: To avoid the unconditional `gclient sync` in the call to fetch,
        # we inline the result of a `fetch --dry-run`
        gclient root
        gclient config --spec 'solutions = [
          {
            "managed": False,
            "name": "src",
            "url": "https://chromium.googlesource.com/external/webrtc.git",
            "custom_deps": {},
            "deps_file": "DEPS",
            "safesync_url": "",
          },
        ]
        '
        gclient sync --nohooks --no-history --with_branch_heads -r [% c("var/webrtc_tag") %]
        cd src
        git submodule foreach 'git config -f $toplevel/.git/config submodule.$name.ignore all'
        git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*'
        git config diff.ignoreSubmodules all
        cd ..
      fi
      # "gclient" is part of depot_tools. This download takes a long time the first time.
      gclient sync --force --delete_unversioned_trees --reset --no-history --with_branch_heads -r [% c("var/webrtc_tag") %]
      cd ..
      tar --exclude .git -czf [% dest_dir _ '/' _ c('filename') %] webrtc
    input_files:
      - project: depot_tools
        name: depot_tools
        pkg_type: build
