xref: /aosp_15_r20/build/bazel/mkcompare/README.md (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1*7594170eSAndroid Build Coastguard Worker# mkcompare: Compare generated Android-TARGET.mk makefiles
2*7594170eSAndroid Build Coastguard Worker
3*7594170eSAndroid Build Coastguard Worker## Summary
4*7594170eSAndroid Build Coastguard Worker
5*7594170eSAndroid Build Coastguard WorkerThis tool shows the differences between two `Android-`_target_`.mk` makefile.
6*7594170eSAndroid Build Coastguard WorkerThis makefile contains information about the Soong build graph that is exposed
7*7594170eSAndroid Build Coastguard Workerto Make (Android.mk) and packaging rules.
8*7594170eSAndroid Build Coastguard Worker
9*7594170eSAndroid Build Coastguard Worker## Usage
10*7594170eSAndroid Build Coastguard Worker
11*7594170eSAndroid Build Coastguard Worker```shell
12*7594170eSAndroid Build Coastguard Worker# run product config
13*7594170eSAndroid Build Coastguard Worker$ lunch ${target}
14*7594170eSAndroid Build Coastguard Worker
15*7594170eSAndroid Build Coastguard Worker# run soong for reference build
16*7594170eSAndroid Build Coastguard Worker$ m nothing && cp out/soong/Android-${target}.mk Android-${target}.mk.ref
17*7594170eSAndroid Build Coastguard Worker
18*7594170eSAndroid Build Coastguard Worker# apply your local changes..
19*7594170eSAndroid Build Coastguard Worker$ m nothing && cp out/soong/Android-${target}.mk Android-${target}.mk.new
20*7594170eSAndroid Build Coastguard Worker
21*7594170eSAndroid Build Coastguard Worker# compare!
22*7594170eSAndroid Build Coastguard Worker$ GOWORK=$PWD/build/bazel/mkcompare/go.work go run android/bazel/mkcompare/cmd \
23*7594170eSAndroid Build Coastguard Worker    -json \
24*7594170eSAndroid Build Coastguard Worker    Android-${target}.mk.ref \
25*7594170eSAndroid Build Coastguard Worker    Android-${target}.mk.new > ${target}.mk.json
26*7594170eSAndroid Build Coastguard Worker```
27*7594170eSAndroid Build Coastguard Worker
28*7594170eSAndroid Build Coastguard Worker## Options ##
29*7594170eSAndroid Build Coastguard Worker
30*7594170eSAndroid Build Coastguard WorkerThe comparator optionally:
31*7594170eSAndroid Build Coastguard Worker
32*7594170eSAndroid Build Coastguard Worker* Generates a JSON file with all the differences (`-json`). This option turns off all out output.
33*7594170eSAndroid Build Coastguard Worker* Stops after finding given _N_ different modules `-m N`)
34*7594170eSAndroid Build Coastguard Worker* Ignores variables with given names (`--ignore_variables=VAR,...`)
35*7594170eSAndroid Build Coastguard Worker* Shows per-variable value difference (`--show_module_diffs`)
36*7594170eSAndroid Build Coastguard Worker* For each module type, shows the names of the modules with this difference (`--show_type_modules`)
37*7594170eSAndroid Build Coastguard Worker
38*7594170eSAndroid Build Coastguard Worker## How it works
39*7594170eSAndroid Build Coastguard Worker
40*7594170eSAndroid Build Coastguard WorkerWe assume that both makefiles were generated for the same configuration (i.e.,
41*7594170eSAndroid Build Coastguard Workerthe same  _target_ value, and our goal is thus to find out the difference that
42*7594170eSAndroid Build Coastguard Workera change contributes to the Makefile interface between Soong and Make.
43*7594170eSAndroid Build Coastguard Worker
44*7594170eSAndroid Build Coastguard WorkerCurrently, the comparator inspects only the module sections of a file.
45*7594170eSAndroid Build Coastguard Worker
46*7594170eSAndroid Build Coastguard WorkerA _module section_ looks something like this:
47*7594170eSAndroid Build Coastguard Worker```makefile
48*7594170eSAndroid Build Coastguard Workerinclude $(CLEAR_VARS)   # <module type>
49*7594170eSAndroid Build Coastguard WorkerLOCAL_MODULE := mymod
50*7594170eSAndroid Build Coastguard WorkerLOCAL_MODULE_CLASS := ETC
51*7594170eSAndroid Build Coastguard Workerinclude $(BUILD_PREBUILT)
52*7594170eSAndroid Build Coastguard Worker```
53*7594170eSAndroid Build Coastguard Worker
54*7594170eSAndroid Build Coastguard Workeri.e., it always starts with `include $(CLEAR_VARS)` ('module header') line
55*7594170eSAndroid Build Coastguard Workerand spans until the blank line. Before a blank line there is an
56*7594170eSAndroid Build Coastguard Worker`include <mkfile>` line ('module footer'), which may be followed by a few extra
57*7594170eSAndroid Build Coastguard Workervariable assignments. Between those two `include ` lines are the assignment lines.
58*7594170eSAndroid Build Coastguard Worker
59*7594170eSAndroid Build Coastguard WorkerThe name of the module is synthesized from the value of the `LOCAL_MODULE` variable
60*7594170eSAndroid Build Coastguard Workerand target configuration, e.g, `apex_tzdata.com.android.tzdata|cls:ETC|target_arch:arm64`
61*7594170eSAndroid Build Coastguard Workeror `aac_dec_fuzzer|cls:EXECUTABLES|host_arch:x86_64`
62*7594170eSAndroid Build Coastguard Worker
63*7594170eSAndroid Build Coastguard WorkerThe module header includes the module type as a comment (the plan was to use the
64*7594170eSAndroid Build Coastguard Worker_mkfile_ on the footer line, but it proved to be common to most of the modules,
65*7594170eSAndroid Build Coastguard Workerso Soong was modified to provide a module detailed module type as a comment
66*7594170eSAndroid Build Coastguard Workeron the header line).
67*7594170eSAndroid Build Coastguard Worker
68*7594170eSAndroid Build Coastguard WorkerA module section in the reference file is compared with the
69*7594170eSAndroid Build Coastguard Workeridentically named module section of our file. The following items are compared:
70*7594170eSAndroid Build Coastguard Worker
71*7594170eSAndroid Build Coastguard Worker*   module types
72*7594170eSAndroid Build Coastguard Worker*   the number of extra lines following the section footer
73*7594170eSAndroid Build Coastguard Worker*   the variables and their values
74*7594170eSAndroid Build Coastguard Worker
75*7594170eSAndroid Build Coastguard Worker## Summary Output
76*7594170eSAndroid Build Coastguard Worker
77*7594170eSAndroid Build Coastguard WorkerThe default outputs look as follows:
78*7594170eSAndroid Build Coastguard Worker```
79*7594170eSAndroid Build Coastguard Worker159 missing modules, by type:
80*7594170eSAndroid Build Coastguard Worker  apex.apexBundle.files (159 modules)
81*7594170eSAndroid Build Coastguard Worker
82*7594170eSAndroid Build Coastguard WorkerMissing variables (14):
83*7594170eSAndroid Build Coastguard Worker  ...
84*7594170eSAndroid Build Coastguard Worker  LOCAL_REQUIRED_MODULES, by type:
85*7594170eSAndroid Build Coastguard Worker    art_cc_library (2 modules)
86*7594170eSAndroid Build Coastguard Worker    art_cc_library_static (4 modules)
87*7594170eSAndroid Build Coastguard Worker    cc_library (28 modules)
88*7594170eSAndroid Build Coastguard Worker    cc_library_shared (2 modules)
89*7594170eSAndroid Build Coastguard Worker  LOCAL_SHARED_LIBRARIES, by type:
90*7594170eSAndroid Build Coastguard Worker    art_cc_library (60 modules)
91*7594170eSAndroid Build Coastguard Worker    ....
92*7594170eSAndroid Build Coastguard WorkerExtra variables (7):
93*7594170eSAndroid Build Coastguard Worker  LOCAL_EXPORT_CFLAGS, by type:
94*7594170eSAndroid Build Coastguard Worker    cc_library (4 modules)
95*7594170eSAndroid Build Coastguard Worker  LOCAL_EXPORT_C_INCLUDE_DEPS, by type:
96*7594170eSAndroid Build Coastguard Worker    art_cc_library (28 modules)
97*7594170eSAndroid Build Coastguard Worker    ...
98*7594170eSAndroid Build Coastguard WorkerDiff variables: (18)
99*7594170eSAndroid Build Coastguard Worker  LOCAL_EXPORT_C_INCLUDE_DEPS, by type:
100*7594170eSAndroid Build Coastguard Worker    aidl_interface.go_android/soong/aidl.wrapLibraryFactory.func1__topDownMutatorModule (1721 modules)
101*7594170eSAndroid Build Coastguard Worker    art_cc_library (12 modules)
102*7594170eSAndroid Build Coastguard Worker  LOCAL_PREBUILT_MODULE_FILE, by type:
103*7594170eSAndroid Build Coastguard Worker    apex.apexBundle (7 modules)
104*7594170eSAndroid Build Coastguard Worker    apex.apexBundle.files (625 modules)
105*7594170eSAndroid Build Coastguard Worker   ...
106*7594170eSAndroid Build Coastguard Worker```
107*7594170eSAndroid Build Coastguard Worker
108*7594170eSAndroid Build Coastguard Worker## JSON Output ##
109*7594170eSAndroid Build Coastguard Worker
110*7594170eSAndroid Build Coastguard WorkerIt looks like this:
111*7594170eSAndroid Build Coastguard Worker```JSON
112*7594170eSAndroid Build Coastguard Worker{
113*7594170eSAndroid Build Coastguard Worker  "RefPath": "<...>/out/soong/Android-aosp_arm64.mk",
114*7594170eSAndroid Build Coastguard Worker  "OurPath": "<...>/out.mixed/soong/Android-aosp_arm64.mk",
115*7594170eSAndroid Build Coastguard Worker  "MissingModules": [
116*7594170eSAndroid Build Coastguard Worker    "adbd.com.android.adbd|cls:EXECUTABLES|target_arch:arm64",
117*7594170eSAndroid Build Coastguard Worker    "android.hardware.common-V2-ndk.com.android.media.swcodec|cls:SHARED_LIBRARIES|target_arch:arm64",
118*7594170eSAndroid Build Coastguard Worker    "android.hardware.graphics.allocator-V1-ndk.com.android.media.swcodec|cls:SHARED_LIBRARIES|target_arch:arm64",
119*7594170eSAndroid Build Coastguard Worker    "android.hardware.graphics.allocator@2.0.com.android.media.swcodec|cls:SHARED_LIBRARIES|target_arch:arm64",
120*7594170eSAndroid Build Coastguard Worker    ...
121*7594170eSAndroid Build Coastguard Worker  ],
122*7594170eSAndroid Build Coastguard Worker  "DiffModules": [
123*7594170eSAndroid Build Coastguard Worker    {
124*7594170eSAndroid Build Coastguard Worker      "Name": "_makenames|cls:EXECUTABLES|target_arch:arm64",
125*7594170eSAndroid Build Coastguard Worker      "RefLocation": 137674,
126*7594170eSAndroid Build Coastguard Worker      "OurLocation": 137673,
127*7594170eSAndroid Build Coastguard Worker      "MissingVars": [ "LOCAL_SHARED_LIBRARIES", "LOCAL_STATIC_LIBRARIES" ],
128*7594170eSAndroid Build Coastguard Worker      "DiffVars": [
129*7594170eSAndroid Build Coastguard Worker        {
130*7594170eSAndroid Build Coastguard Worker          "Name": "LOCAL_PREBUILT_MODULE_FILE",
131*7594170eSAndroid Build Coastguard Worker          "MissingItems": [ "out/soong/.intermediates/external/libcap/_makenames/android_arm64_armv8-a/_makenames" ],
132*7594170eSAndroid Build Coastguard Worker          "ExtraItems": [ "out/bazel-bin/external/libcap/_makenames" ]
133*7594170eSAndroid Build Coastguard Worker        },
134*7594170eSAndroid Build Coastguard Worker        {
135*7594170eSAndroid Build Coastguard Worker          "Name": "LOCAL_SOONG_UNSTRIPPED_BINARY",
136*7594170eSAndroid Build Coastguard Worker          "MissingItems": [ "out/soong/.intermediates/external/libcap/_makenames/android_arm64_armv8-a/unstripped/_makenames" ],
137*7594170eSAndroid Build Coastguard Worker          "ExtraItems": [ "out/bazel-bin/external/libcap/_makenames_unstripped" ]
138*7594170eSAndroid Build Coastguard Worker        }
139*7594170eSAndroid Build Coastguard Worker      ]
140*7594170eSAndroid Build Coastguard Worker    },
141*7594170eSAndroid Build Coastguard Worker    ...
142*7594170eSAndroid Build Coastguard Worker  ]
143*7594170eSAndroid Build Coastguard Worker}
144*7594170eSAndroid Build Coastguard Worker```
145*7594170eSAndroid Build Coastguard WorkerUse JSON query tool like [`jq`](https://github.com/stedolan/jq) to slice and dice it.
146