xref: /aosp_15_r20/external/crosvm/infra/recipes/build_chromeos_hatch.py (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1# Copyright 2022 The ChromiumOS Authors
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.post_process import Filter
6
7DEPS = [
8    "crosvm",
9    "depot_tools/depot_tools",
10    "recipe_engine/buildbucket",
11    "recipe_engine/context",
12    "recipe_engine/properties",
13    "recipe_engine/step",
14]
15
16
17def RunSteps(api):
18    with api.crosvm.cros_container_build_context():
19        gitilies = api.buildbucket.build.input.gitiles_commit
20        upstream_url = "https://chromium.googlesource.com/crosvm/crosvm"
21        revision = gitilies.id or "upstream/main"
22
23        api.crosvm.step_in_container(
24            "Sync repo",
25            [
26                "repo",
27                "sync",
28                "-j8",
29            ],
30            cros=True,
31        )
32
33        api.crosvm.step_in_container(
34            "Add crosvm upstream remote",
35            ["git", "remote", "add", "upstream", upstream_url],
36            cros=True,
37        )
38
39        # Ignore errors from unshallow as repo sync sometimes resulted in full git history
40        api.crosvm.step_in_container(
41            "Unshallow crosvm as needed",
42            [
43                "bash",
44                "-c",
45                "for i in $(seq 1 5);do if [[ $(git rev-parse --is-shallow-repository) == 'true' ]]; then git fetch cros --unshallow; else break; fi; done",
46            ],
47            cros=True,
48        )
49
50        api.crosvm.step_in_container("Print current git log", ["git", "log"], cros=True)
51
52        api.crosvm.step_in_container(
53            "Fetch upstream crosvm", ["git", "fetch", "upstream"], cros=True
54        )
55
56        # Apply unmerged commit from upstream to crOS tree
57        api.crosvm.step_in_container(
58            "Cherry-pick from upstream revision", ["git", "cherry-pick", ".." + revision], cros=True
59        )
60
61        api.crosvm.step_in_container(
62            "cros-workon-hatch crosvm",
63            ["cros_sdk", "cros-workon-hatch", "start", "crosvm"],
64            cros=True,
65        )
66
67        api.crosvm.step_in_container(
68            "Build crosvm",
69            [
70                "cros_sdk",
71                "build_packages",
72                "--board=hatch",
73                "crosvm",
74            ],
75            cros=True,
76        )
77
78
79def GenTests(api):
80    filter_steps = Filter("Build crosvm")
81    yield (
82        api.test(
83            "build_chromeos_hatch",
84            api.buildbucket.ci_build(project="crosvm/crosvm"),
85        )
86        + api.post_process(filter_steps)
87    )
88