xref: /aosp_15_r20/external/crosvm/infra/recipes/build_docs.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    "recipe_engine/file",
10    "recipe_engine/buildbucket",
11    "recipe_engine/context",
12    "recipe_engine/step",
13    "depot_tools/gsutil",
14]
15
16BOOK_URL = "gs://crosvm-dot-dev/book"
17DOCS_URL = "gs://crosvm-dot-dev/doc"
18
19
20def RunSteps(api):
21    """
22    Builds crosvm mdbook and api docs, then uploads them to GCS.
23
24    This recipe requires ambient luci authentication. To test locally run:
25       $ luci-auth context ./infra/recipes.py run build_docs
26    """
27    with api.crosvm.container_build_context():
28        api.crosvm.step_in_container(
29            "Build mdbook", ["mdbook", "build", "docs/book/", "--dest-dir", "../target"]
30        )
31        api.crosvm.step_in_container(
32            "Run cargo docs",
33            ["./tools/cargo-doc", "--target-dir", "docs/target"],
34        )
35
36        # Container generated files are root-owned, we need to make sure they will be readable by
37        # gsutil (which has to run outside the container to run with proper authentication).
38        api.crosvm.step_in_container(
39            "Make docs readable by gsutil",
40            ["chmod", "-R", "o+r", "docs/target"],
41        )
42
43        api.gsutil(
44            ["rsync", "-r", "-d", "./docs/target/html", BOOK_URL],
45            name="Upload book",
46            multithreaded=True,
47        )
48        # TODO(b/239255064): Generate the redirect HTML so we can use cleanly mirror here too.
49        api.gsutil(
50            ["rsync", "-r", "./docs/target/doc", DOCS_URL],
51            name="Upload docs",
52            multithreaded=True,
53        )
54
55
56def GenTests(api):
57    filter_steps = Filter(
58        "Build mdbook", "Run cargo docs", "gsutil Upload book", "gsutil Upload docs"
59    )
60    yield (
61        api.test(
62            "build_docs",
63            api.buildbucket.ci_build(project="crosvm/crosvm"),
64        )
65        + api.post_process(filter_steps)
66    )
67