xref: /aosp_15_r20/external/pigweed/pw_build/project_builder.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_build-project_builder:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker===============
4*61c4878aSAndroid Build Coastguard WorkerProject Builder
5*61c4878aSAndroid Build Coastguard Worker===============
6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module-subpage::
7*61c4878aSAndroid Build Coastguard Worker   :name: pw_build
8*61c4878aSAndroid Build Coastguard Worker
9*61c4878aSAndroid Build Coastguard WorkerThe ``pw_build`` Python module contains a light-weight build command execution
10*61c4878aSAndroid Build Coastguard Workerlibrary used for projects that require running multiple commands to perform a
11*61c4878aSAndroid Build Coastguard Workerbuild. For example: running ``cmake`` alongside ``gn``.
12*61c4878aSAndroid Build Coastguard Worker
13*61c4878aSAndroid Build Coastguard Worker.. grid:: 3
14*61c4878aSAndroid Build Coastguard Worker
15*61c4878aSAndroid Build Coastguard Worker   .. grid-item-card:: :octicon:`rocket` Get started
16*61c4878aSAndroid Build Coastguard Worker      :link: module-pw_build-project_builder-start
17*61c4878aSAndroid Build Coastguard Worker      :link-type: ref
18*61c4878aSAndroid Build Coastguard Worker      :class-item: sales-pitch-cta-primary
19*61c4878aSAndroid Build Coastguard Worker
20*61c4878aSAndroid Build Coastguard Worker      How to write your own build script.
21*61c4878aSAndroid Build Coastguard Worker
22*61c4878aSAndroid Build Coastguard Worker   .. grid-item-card:: :octicon:`code-square` Reference
23*61c4878aSAndroid Build Coastguard Worker      :link: module-pw_build-project_builder-reference
24*61c4878aSAndroid Build Coastguard Worker      :link-type: ref
25*61c4878aSAndroid Build Coastguard Worker      :class-item: sales-pitch-cta-secondary
26*61c4878aSAndroid Build Coastguard Worker
27*61c4878aSAndroid Build Coastguard Worker      Reference details about the ``pw_build`` Python API.
28*61c4878aSAndroid Build Coastguard Worker
29*61c4878aSAndroid Build Coastguard Worker   .. grid-item-card:: :octicon:`terminal` ``pw build`` CLI
30*61c4878aSAndroid Build Coastguard Worker      :link: module-pw_build-project_builder-cli
31*61c4878aSAndroid Build Coastguard Worker      :link-type: ref
32*61c4878aSAndroid Build Coastguard Worker      :class-item: sales-pitch-cta-secondary
33*61c4878aSAndroid Build Coastguard Worker
34*61c4878aSAndroid Build Coastguard Worker      Command line interface usage.
35*61c4878aSAndroid Build Coastguard Worker
36*61c4878aSAndroid Build Coastguard Worker.. _module-pw_build-project_builder-start:
37*61c4878aSAndroid Build Coastguard Worker
38*61c4878aSAndroid Build Coastguard Worker-----------
39*61c4878aSAndroid Build Coastguard WorkerGet Started
40*61c4878aSAndroid Build Coastguard Worker-----------
41*61c4878aSAndroid Build Coastguard WorkerThe quickest way to get started with Project Builder is to create a build script
42*61c4878aSAndroid Build Coastguard Workerbased on existing examples.
43*61c4878aSAndroid Build Coastguard Worker
44*61c4878aSAndroid Build Coastguard WorkerExample Build Scripts
45*61c4878aSAndroid Build Coastguard Worker=====================
46*61c4878aSAndroid Build Coastguard WorkerExamples of Project Builder based ``pw build`` commands:
47*61c4878aSAndroid Build Coastguard Worker
48*61c4878aSAndroid Build Coastguard Worker- `Upstream Pigweed repo pigweed_upstream_build.py <https://cs.opensource.google/pigweed/pigweed/+/main:pw_build/py/pw_build/pigweed_upstream_build.py>`_
49*61c4878aSAndroid Build Coastguard Worker- `Examples repo build_project.py <https://cs.opensource.google/pigweed/examples/+/main:tools/sample_project_tools/build_project.py>`_
50*61c4878aSAndroid Build Coastguard Worker- `Kudzu repo build_project.py <https://pigweed.googlesource.com/pigweed/kudzu/+/refs/heads/main/tools/kudzu_tools/build_project.py>`_
51*61c4878aSAndroid Build Coastguard Worker
52*61c4878aSAndroid Build Coastguard Worker
53*61c4878aSAndroid Build Coastguard Worker.. _module-pw_build-project_builder-reference:
54*61c4878aSAndroid Build Coastguard Worker
55*61c4878aSAndroid Build Coastguard Worker---------
56*61c4878aSAndroid Build Coastguard WorkerReference
57*61c4878aSAndroid Build Coastguard Worker---------
58*61c4878aSAndroid Build Coastguard WorkerAt a high level:
59*61c4878aSAndroid Build Coastguard Worker
60*61c4878aSAndroid Build Coastguard Worker- A single :py:class:`BuildRecipe <pw_build.build_recipe.BuildRecipe>`
61*61c4878aSAndroid Build Coastguard Worker  contains many :py:class:`BuildCommands <pw_build.build_recipe.BuildCommand>`
62*61c4878aSAndroid Build Coastguard Worker  which are run sequentially.
63*61c4878aSAndroid Build Coastguard Worker- Multiple :py:class:`BuildRecipes <pw_build.build_recipe.BuildRecipe>` can be
64*61c4878aSAndroid Build Coastguard Worker  created and passed into the
65*61c4878aSAndroid Build Coastguard Worker  :py:class:`ProjectBuilder <pw_build.project_builder.ProjectBuilder>` class which
66*61c4878aSAndroid Build Coastguard Worker  provides logging and terminal output options.
67*61c4878aSAndroid Build Coastguard Worker- A :py:class:`ProjectBuilder <pw_build.project_builder.ProjectBuilder>` instance is
68*61c4878aSAndroid Build Coastguard Worker  then passed to the :py:func:`run_builds <pw_build.project_builder.run_builds>`
69*61c4878aSAndroid Build Coastguard Worker  function which allows specifying the number of parallel workers (the number of
70*61c4878aSAndroid Build Coastguard Worker  recipes which are executed in parallel).
71*61c4878aSAndroid Build Coastguard Worker
72*61c4878aSAndroid Build Coastguard Worker.. mermaid::
73*61c4878aSAndroid Build Coastguard Worker
74*61c4878aSAndroid Build Coastguard Worker   flowchart TB
75*61c4878aSAndroid Build Coastguard Worker       subgraph BuildRecipeA ["<strong>BuildRecipe</strong>: ninja"]
76*61c4878aSAndroid Build Coastguard Worker           buildCommandA1["<strong>BuildCommand</strong><br> gn gen out"]
77*61c4878aSAndroid Build Coastguard Worker           buildCommandA2["<strong>BuildCommand</strong><br> ninja -C out default"]
78*61c4878aSAndroid Build Coastguard Worker           buildCommandA1-->buildCommandA2
79*61c4878aSAndroid Build Coastguard Worker       end
80*61c4878aSAndroid Build Coastguard Worker
81*61c4878aSAndroid Build Coastguard Worker       subgraph BuildRecipeB ["<strong>BuildRecipe</strong>: bazel"]
82*61c4878aSAndroid Build Coastguard Worker           buildCommandB1["<strong>BuildCommand</strong><br> bazel build //...:all"]
83*61c4878aSAndroid Build Coastguard Worker           buildCommandB2["<strong>BuildCommand</strong><br> bazel test //...:all"]
84*61c4878aSAndroid Build Coastguard Worker           buildCommandB1-->buildCommandB2
85*61c4878aSAndroid Build Coastguard Worker       end
86*61c4878aSAndroid Build Coastguard Worker
87*61c4878aSAndroid Build Coastguard Worker       ProjectBuilder["<strong>ProjectBuilder</strong>(build_recipes=...)"]
88*61c4878aSAndroid Build Coastguard Worker       BuildRecipeA-->ProjectBuilder
89*61c4878aSAndroid Build Coastguard Worker       BuildRecipeB-->ProjectBuilder
90*61c4878aSAndroid Build Coastguard Worker
91*61c4878aSAndroid Build Coastguard Worker       run_builds["<strong>run_builds</strong>(project_builder=..., workers=1)"]
92*61c4878aSAndroid Build Coastguard Worker       ProjectBuilder-->run_builds
93*61c4878aSAndroid Build Coastguard Worker
94*61c4878aSAndroid Build Coastguard WorkerBuildCommand
95*61c4878aSAndroid Build Coastguard Worker============
96*61c4878aSAndroid Build Coastguard Worker.. autoclass:: pw_build.build_recipe.BuildCommand
97*61c4878aSAndroid Build Coastguard Worker
98*61c4878aSAndroid Build Coastguard WorkerBuildCommand Run Filters
99*61c4878aSAndroid Build Coastguard Worker------------------------
100*61c4878aSAndroid Build Coastguard Worker.. autofunction:: pw_build.build_recipe.should_gn_gen
101*61c4878aSAndroid Build Coastguard Worker
102*61c4878aSAndroid Build Coastguard Worker.. autofunction:: pw_build.build_recipe.should_gn_gen_with_args
103*61c4878aSAndroid Build Coastguard Worker
104*61c4878aSAndroid Build Coastguard Worker.. autofunction:: pw_build.build_recipe.should_regenerate_cmake
105*61c4878aSAndroid Build Coastguard Worker
106*61c4878aSAndroid Build Coastguard WorkerBuildRecipe
107*61c4878aSAndroid Build Coastguard Worker===========
108*61c4878aSAndroid Build Coastguard Worker.. autoclass:: pw_build.build_recipe.BuildRecipe
109*61c4878aSAndroid Build Coastguard Worker
110*61c4878aSAndroid Build Coastguard WorkerProjectBuilder
111*61c4878aSAndroid Build Coastguard Worker==============
112*61c4878aSAndroid Build Coastguard Worker.. autoclass:: pw_build.project_builder.ProjectBuilder
113*61c4878aSAndroid Build Coastguard Worker
114*61c4878aSAndroid Build Coastguard Worker.. autofunction:: pw_build.project_builder.run_builds
115*61c4878aSAndroid Build Coastguard Worker
116*61c4878aSAndroid Build Coastguard Worker
117*61c4878aSAndroid Build Coastguard Worker.. _module-pw_build-project_builder-cli:
118*61c4878aSAndroid Build Coastguard Worker
119*61c4878aSAndroid Build Coastguard Worker--------------------------------------------------
120*61c4878aSAndroid Build Coastguard WorkerUpstream ``pw build`` Command-Line Interface Usage
121*61c4878aSAndroid Build Coastguard Worker--------------------------------------------------
122*61c4878aSAndroid Build Coastguard Worker.. argparse::
123*61c4878aSAndroid Build Coastguard Worker   :module: pw_build.pigweed_upstream_build
124*61c4878aSAndroid Build Coastguard Worker   :func: _build_argument_parser
125*61c4878aSAndroid Build Coastguard Worker   :prog: pw build
126*61c4878aSAndroid Build Coastguard Worker
127*61c4878aSAndroid Build Coastguard Worker   This is the command line interface provided by the ``pw build`` command
128*61c4878aSAndroid Build Coastguard Worker   (`pigweed_upstream_build.py
129*61c4878aSAndroid Build Coastguard Worker   <https://cs.opensource.google/pigweed/pigweed/+/main:pw_build/py/pw_build/pigweed_upstream_build.py>`_)
130*61c4878aSAndroid Build Coastguard Worker   in upstream Pigweed.
131