# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from buildbot.schedulers.basic import SingleBranchScheduler

from master import master_config
from master.factory import annotator_factory
from master.factory import chromium_factory

m_annotator = annotator_factory.AnnotatorFactory()

defaults = {}

helper = master_config.Helper(defaults)
B = helper.Builder
F = helper.Factory
S = helper.Scheduler
T = helper.Triggerable

def linux_android():
  return chromium_factory.ChromiumFactory(
    '', 'linux2', nohooks_on_update=True, target_os='android')

defaults['category'] = '5android'

android_dbg_archive = master_config.GetGSUtilUrl(
    'chromium-android', 'android_main_dbg')

android_rel_archive = master_config.GetGSUtilUrl(
    'chromium-android', 'android_main_rel')

#
# Main release scheduler for src/
#
S('android', branch='master', treeStableTimer=60)

#
# Triggerable scheduler for the builder
#
T('android_trigger_dbg')
T('android_trigger_rel')

#
# Android Builder
#
B('Android Arm64 Builder (dbg)', 'f_android_arm64_dbg', 'android', 'android',
  auto_reboot=False, notify_on_missing=True)
F('f_android_arm64_dbg',
  m_annotator.BaseFactory('android/builder'))

B('Android Builder (dbg)', 'f_android_dbg', 'android', 'android',
  auto_reboot=False, notify_on_missing=True)
F('f_android_dbg',
  m_annotator.BaseFactory('android/builder', triggers=['android_trigger_dbg']))

B('Android Tests (dbg)', 'f_android_dbg_tests', 'android',
  'android_trigger_dbg', notify_on_missing=True)
F('f_android_dbg_tests',
  m_annotator.BaseFactory('android/tester'))

B('Android Builder', 'f_android_rel', 'android', 'android',
  notify_on_missing=True)
F('f_android_rel',
  m_annotator.BaseFactory('android/builder', triggers=['android_trigger_rel']))

B('Android Tests', 'f_android_rel_tests', 'android', 'android_trigger_rel',
  notify_on_missing=True)
F('f_android_rel_tests',
  m_annotator.BaseFactory('android/tester'))

B('Android Clang Builder (dbg)', 'f_android_clang_dbg', 'android', 'android',
  notify_on_missing=True)
F('f_android_clang_dbg',
  m_annotator.BaseFactory('chromium'))

B('Android Webview AOSP Builder', 'f_android_webview_aosp_rel', 'android',
  'android', notify_on_missing=True)
F('f_android_webview_aosp_rel',
  m_annotator.BaseFactory('android_webview_aosp'))


def Update(_config_arg, _active_master, c):
  helper.Update(c)

  specs = [
    {'name': 'Android GN', 'recipe': 'chromium_gn'},
  ]

  c['schedulers'].extend([
      SingleBranchScheduler(name='android_gn',
                            branch='master',
                            treeStableTimer=60,
                            builderNames=['Android GN']),
  ])
  c['builders'].extend([
      {
        'name': spec['name'],
        'factory': m_annotator.BaseFactory(
              spec.get('recipe', 'chromium'),
              factory_properties=spec.get('factory_properties'),
              triggers=spec.get('triggers')),
        'notify_on_missing': True,
        'category': '5android',
      } for spec in specs
  ])

@@ -1441,39 +1441,32 @@
 aseFactory('
-android/builder
+chromium
 ', triggers=
@@ -1648,38 +1648,32 @@
 aseFactory('
-android/tester
+chromium
 '))%0A%0AB('Andr
@@ -1797,31 +1797,24 @@
 actory('
-android/builder
+chromium
 ', trigg
@@ -2002,22 +2002,16 @@
 ry('
-android/tester
+chromium
 '))%0A

Switch most chromium.linux android bots to the chromium recipe: