xref: /aosp_15_r20/tools/treble/split/README.md (revision 105f628577ac4ba0e277a494fbb614ed8c12a994)
1*105f6285SAndroid Build Coastguard Worker# Manifest Split
2*105f6285SAndroid Build Coastguard Worker
3*105f6285SAndroid Build Coastguard Worker## Overview
4*105f6285SAndroid Build Coastguard Worker
5*105f6285SAndroid Build Coastguard WorkerSplit manifests are Android repo manifests that contain the minimum set of
6*105f6285SAndroid Build Coastguard Workerprojects necessary to build a given target. If a project isn't used for building
7*105f6285SAndroid Build Coastguard Workerthe target, it shouldn't be in the split manifest. This smaller manifest can be
8*105f6285SAndroid Build Coastguard Workerused to sync the Android source tree and build the specific target. This sync
9*105f6285SAndroid Build Coastguard Workershould be faster and smaller than a sync of a full manifest because it is
10*105f6285SAndroid Build Coastguard Workersyncing less projects.
11*105f6285SAndroid Build Coastguard Worker
12*105f6285SAndroid Build Coastguard WorkerThe `treble_manifest_split` tool is used to automatically create a split
13*105f6285SAndroid Build Coastguard Workermanifest from a full manifest using dependency information from the source tree
14*105f6285SAndroid Build Coastguard Workerand the build outputs. The tool attempts to infer as many dependencies as it
15*105f6285SAndroid Build Coastguard Workercan, but some will be missed due to implicit dependencies in the build system
16*105f6285SAndroid Build Coastguard Workerand source tree. This is solved by manually fine-tuning a tool configuration XML
17*105f6285SAndroid Build Coastguard Workerspecific to your target.
18*105f6285SAndroid Build Coastguard Worker
19*105f6285SAndroid Build Coastguard Worker## Example for aosp_arm64
20*105f6285SAndroid Build Coastguard Worker
21*105f6285SAndroid Build Coastguard Worker### 1. Run a full build using a full manifest
22*105f6285SAndroid Build Coastguard Worker
23*105f6285SAndroid Build Coastguard WorkerThe `treble_manifest_split` tool needs the ninja build graph and deps log from a
24*105f6285SAndroid Build Coastguard Workercompleted build in order to have a full view of the dependency graph. While the
25*105f6285SAndroid Build Coastguard Workerbuild graph is created at the beginning of a ninja build, the deps log is not
26*105f6285SAndroid Build Coastguard Workercomplete until the build finishes.
27*105f6285SAndroid Build Coastguard Worker
28*105f6285SAndroid Build Coastguard WorkerUse standard Android build commands to build your target.
29*105f6285SAndroid Build Coastguard Worker
30*105f6285SAndroid Build Coastguard Worker### 2. Use the treble_manifest_split tool
31*105f6285SAndroid Build Coastguard Worker
32*105f6285SAndroid Build Coastguard Worker```shell
33*105f6285SAndroid Build Coastguard Worker# Change to the directory where you ran the full build.
34*105f6285SAndroid Build Coastguard Workercd /path/to/android
35*105f6285SAndroid Build Coastguard Worker
36*105f6285SAndroid Build Coastguard Worker# Set command line variables for the Android target you are using and the build
37*105f6285SAndroid Build Coastguard Worker# target that should be buildable from your split manifest.
38*105f6285SAndroid Build Coastguard WorkerANDROID_TARGET=aosp_arm64-userdebug
39*105f6285SAndroid Build Coastguard WorkerBUILD_TARGET=droid
40*105f6285SAndroid Build Coastguard Worker
41*105f6285SAndroid Build Coastguard Worker# Build treble_manifest_split as a python binary.
42*105f6285SAndroid Build Coastguard Workerlunch $ANDROID_TARGET
43*105f6285SAndroid Build Coastguard Workerm treble_manifest_split
44*105f6285SAndroid Build Coastguard Worker
45*105f6285SAndroid Build Coastguard Worker# Create the split manifest using a sample config XML specific to aosp_arm64.
46*105f6285SAndroid Build Coastguard Workerout/host/linux-x86/bin/treble_manifest_split \
47*105f6285SAndroid Build Coastguard Worker  --manifest .repo/manifests/default.xml \
48*105f6285SAndroid Build Coastguard Worker  --split-manifest split_default.xml \
49*105f6285SAndroid Build Coastguard Worker  --debug-file debug.json \
50*105f6285SAndroid Build Coastguard Worker  --config tools/treble/split/sample_config.xml \
51*105f6285SAndroid Build Coastguard Worker  $BUILD_TARGET
52*105f6285SAndroid Build Coastguard Worker```
53*105f6285SAndroid Build Coastguard Worker
54*105f6285SAndroid Build Coastguard Worker### 3. Build using the split manifest
55*105f6285SAndroid Build Coastguard Worker
56*105f6285SAndroid Build Coastguard WorkerYou should test that the split manifest created by the tool can be used to build
57*105f6285SAndroid Build Coastguard Workerthe partial target files package.
58*105f6285SAndroid Build Coastguard Worker
59*105f6285SAndroid Build Coastguard Worker1.  Initialize a new repo directory using the steps in
60*105f6285SAndroid Build Coastguard Worker    https://source.android.com/setup/build/downloading#initializing-a-repo-client.
61*105f6285SAndroid Build Coastguard Worker1.  Replace the `.repo/manifests/default.xml` full manifest with the
62*105f6285SAndroid Build Coastguard Worker    newly-generated split manifest.
63*105f6285SAndroid Build Coastguard Worker1.  Use standard `repo sync` commands to sync your repo.
64*105f6285SAndroid Build Coastguard Worker1.  Attempt a build of your target.
65*105f6285SAndroid Build Coastguard Worker
66*105f6285SAndroid Build Coastguard Worker### 4. Fix build errors
67*105f6285SAndroid Build Coastguard Worker
68*105f6285SAndroid Build Coastguard WorkerBuild errors may arise due to missing dependencies that were previously provided
69*105f6285SAndroid Build Coastguard Workerby now-removed projects. These dependencies may be implicit in the source code,
70*105f6285SAndroid Build Coastguard Workeror an explicit dependency type that is not yet able to be automatically detected
71*105f6285SAndroid Build Coastguard Workerby the tool.
72*105f6285SAndroid Build Coastguard Worker
73*105f6285SAndroid Build Coastguard Worker1.  Find the dependency source project in your full-manifest repo directory.
74*105f6285SAndroid Build Coastguard Worker1.  Update your config XML to manually add projects to your split manifest.
75*105f6285SAndroid Build Coastguard Worker
76*105f6285SAndroid Build Coastguard Worker    -   For example, the following line in `sample_config.xml` in this tool
77*105f6285SAndroid Build Coastguard Worker        directory specifies a project that should be included in the split
78*105f6285SAndroid Build Coastguard Worker        manifest even if the tool doesn't automatically detect that it is
79*105f6285SAndroid Build Coastguard Worker        necessary.
80*105f6285SAndroid Build Coastguard Worker
81*105f6285SAndroid Build Coastguard Worker    ```
82*105f6285SAndroid Build Coastguard Worker        <add_project name="platform/external/python/cpython3" />
83*105f6285SAndroid Build Coastguard Worker    ```
84*105f6285SAndroid Build Coastguard Worker
85*105f6285SAndroid Build Coastguard Worker1.  Regenerate the split manifest using `treble_manifest_split` in your
86*105f6285SAndroid Build Coastguard Worker    full-manifest directory. Remember to pass the path of your config XML to the
87*105f6285SAndroid Build Coastguard Worker    script's `--config` flag.
88*105f6285SAndroid Build Coastguard Worker
89*105f6285SAndroid Build Coastguard Worker### 5. Compare built artifacts
90*105f6285SAndroid Build Coastguard Worker
91*105f6285SAndroid Build Coastguard WorkerA successful build alone is not sufficient to have full confidence in the split
92*105f6285SAndroid Build Coastguard Workermanifest. You should diff the output artifacts of the split-manifest build
93*105f6285SAndroid Build Coastguard Workeragainst the output artifacts of the full-manifest build.
94*105f6285SAndroid Build Coastguard Worker
95*105f6285SAndroid Build Coastguard WorkerSuggestions for viewing diffs:
96*105f6285SAndroid Build Coastguard Worker
97*105f6285SAndroid Build Coastguard Worker-   Use an external directory diffing tool on the output directories for each
98*105f6285SAndroid Build Coastguard Worker    partition, such as `out/target/product/<device>/system`.
99*105f6285SAndroid Build Coastguard Worker-   Use `development/vndk/tools/image-diff-tool/diff.py` on output directories,
100*105f6285SAndroid Build Coastguard Worker    or on a zipped target-files archive if you are creating `dist` builds.
101*105f6285SAndroid Build Coastguard Worker
102*105f6285SAndroid Build Coastguard WorkerThe following may cause differences between output artifacts:
103*105f6285SAndroid Build Coastguard Worker
104*105f6285SAndroid Build Coastguard Worker-   Non-hermetic inputs used in the module build rule, such as timestamps. Can
105*105f6285SAndroid Build Coastguard Worker    be fixed by removing the timestamp from the build rule.
106*105f6285SAndroid Build Coastguard Worker-   An implicit and optional source dependency. Can be fixed by manually adding
107*105f6285SAndroid Build Coastguard Worker    the project that defines the missing source.
108