1# Copyright 2017 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5from recipe_engine import post_process
6from recipe_engine import recipe_api
7
8
9DEPS = [
10  'recipe_engine/buildbucket',
11  'recipe_engine/path',
12  'recipe_engine/properties',
13
14  'gclient',
15]
16
17
18def RunSteps(api):
19  src_cfg = api.gclient.make_config(CACHE_DIR=api.path['cache'].join('git'))
20  soln = src_cfg.solutions.add()
21  soln.name = 'src'
22  soln.url = 'https://chromium.googlesource.com/chromium/src.git'
23  src_cfg.repo_path_map.update({
24      'https://chromium.googlesource.com/src': ('src', 'HEAD'),
25      'https://chromium.googlesource.com/v8/v8': ('src/v8', 'HEAD'),
26      # non-canonical URL
27      'https://webrtc.googlesource.com/src.git': (
28          'src/third_party/webrtc', 'HEAD'),
29  })
30  assert api.gclient.get_repo_path(
31      'https://chromium.googlesource.com/chromium/src.git',
32      gclient_config=src_cfg) == 'src'
33  assert api.gclient.get_repo_path(
34      'https://chromium.googlesource.com/chromium/src',
35      gclient_config=src_cfg) == 'src'
36  assert api.gclient.get_repo_path(
37      'https://chromium.googlesource.com/v8/v8',
38      gclient_config=src_cfg) == 'src/v8'
39  assert api.gclient.get_repo_path(
40      'https://webrtc.googlesource.com/src',
41      gclient_config=src_cfg) == 'src/third_party/webrtc'
42  assert api.gclient.get_repo_path(
43      'https://example.googlesource.com/unrecognized',
44      gclient_config=src_cfg) is None
45
46  api.gclient.c = src_cfg
47  patch_root = api.gclient.get_gerrit_patch_root(gclient_config=src_cfg)
48  assert patch_root == api.properties['expected_patch_root'], patch_root
49
50  api.gclient.set_patch_repo_revision()
51
52
53def GenTests(api):
54  yield (
55      api.test('chromium_ci') +
56      api.buildbucket.ci_build(
57          project='chromium',
58          builder='linux',
59          git_repo='https://chromium.googlesource.com/src') +
60      api.properties(expected_patch_root=None) +
61      api.post_process(post_process.DropExpectation)
62  )
63
64  yield (
65      api.test('chromium_try') +
66      api.buildbucket.try_build(
67          project='chromium',
68          builder='linux',
69          git_repo='https://chromium.googlesource.com/src') +
70      api.properties(expected_patch_root='src') +
71      api.post_process(post_process.DropExpectation)
72  )
73
74  yield (
75      api.test('v8_try') +
76      api.buildbucket.try_build(
77          project='chromium',
78          builder='linux',
79          git_repo='https://chromium.googlesource.com/v8/v8') +
80      api.properties(expected_patch_root='src/v8') +
81      api.post_process(post_process.DropExpectation)
82  )
83
84  yield (
85      api.test('webrtc_try') +
86      api.buildbucket.try_build(
87          project='chromium',
88          builder='linux',
89          git_repo='https://webrtc.googlesource.com/src') +
90      api.properties(expected_patch_root='src/third_party/webrtc')+
91      api.post_process(post_process.DropExpectation)
92  )
93