# vim: filetype=yaml sw=2
version: '[% pc("firefox", "abbrev") %]'
filename: '[% project %]-[% c("var/osname") %]-[% c("version") %]-[% c("var/build_id") %]'
link_input_files: 1
# We need to specify git_url in the root to make this project recognized as a
# git project, we canoot specify the git_url only in the step.
# However, once we specify a git_url, we need to specify a valid git_hash for
# the final stage, even though we are not going to use it.
# Any hash will work, as long as we can run git archive on it.
git_url: https://github.com/mozilla-l10n/firefox-l10n.git
git_hash: c1523924f0e10259e1a80b8268556f6f7a0b29bf

steps:
  fetch_locale:
    filename: 'l10n-[% c("input_file_var/locale") %]-[% c("abbrev") %]-[% c("var/build_id") %].tar.xz'
    version: '[% c("git_hash") %]'
    fetch_locale: |
      [% c("var/set_default_env") -%]
      tar xf '[% project %]-[% c("version") %].tar.[% c("compress_tar") %]'
      cd [% project %]-[% c("version") %]
      tar caf '[% dest_dir %]/[% c("filename") %]' [% c("input_file_var/locale") %]
    input_files: []
--- |
  # This part of the file contains options written in perl
  use JSON;
  use Path::Tiny;
  (
    input_files => sub {
      my ($project, $options) = @_;
      my @input_files;
      my $is_android = project_config($project, 'var/android', $options);
      my $source_project = $is_android ? 'geckoview' : 'firefox';
      my $locales_key = $is_android ? 'var/locales_mobile' : 'var/locales';
      my $changesets_json = project_config($source_project, 'var/l10n-changesets', { %$options, origin_project => $project });
      my $d = decode_json $changesets_json;
      my $locales = project_config($project, $locales_key, $options);
      foreach my $loc (@$locales) {
        my $locale = process_template($project, $loc, '.');
        next unless $locale;
        $locale =~ s/-r/-/;
        $locale = "id" if ($is_android && $locale eq "in");
        $locale = "he" if ($is_android && $locale eq "iw");
        next unless my $revision = $d->{$locale}{revision};
        my $input_file = {
          name => $locale,
          project => 'firefox-l10n',
          pkg_type => 'fetch_locale',
          git_hash => $revision,
          input_file_var => {
            locale => $locale,
          },
        };
        push @input_files, $input_file;
      }
      return [@input_files];
    },
  )
