1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
|
// Copyright 2015 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package android
import (
"errors"
"fmt"
"net/url"
"path/filepath"
"reflect"
"slices"
"sort"
"strconv"
"strings"
"github.com/google/blueprint"
"github.com/google/blueprint/depset"
"github.com/google/blueprint/gobtools"
"github.com/google/blueprint/proptools"
)
var (
DeviceSharedLibrary = "shared_library"
DeviceStaticLibrary = "static_library"
jarJarPrefixHandler func(ctx ModuleContext)
)
type Module interface {
blueprint.Module
// GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
// but GenerateAndroidBuildActions also has access to Android-specific information.
// For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
GenerateAndroidBuildActions(ModuleContext)
// CleanupAfterBuildActions is called after ModuleBase.GenerateBuildActions is finished.
// If all interactions with this module are handled via providers instead of direct access
// to the module then it can free memory attached to the module.
// This is a temporary measure to reduce memory usage, eventually blueprint's reference
// to the Module should be dropped after GenerateAndroidBuildActions once all accesses
// can be done through providers.
CleanupAfterBuildActions()
// Add dependencies to the components of a module, i.e. modules that are created
// by the module and which are considered to be part of the creating module.
//
// This is called before prebuilts are renamed so as to allow a dependency to be
// added directly to a prebuilt child module instead of depending on a source module
// and relying on prebuilt processing to switch to the prebuilt module if preferred.
//
// A dependency on a prebuilt must include the "prebuilt_" prefix.
ComponentDepsMutator(ctx BottomUpMutatorContext)
DepsMutator(BottomUpMutatorContext)
base() *ModuleBase
Disable()
Enabled(ctx ConfigurableEvaluatorContext) bool
Target() Target
MultiTargets() []Target
// ImageVariation returns the image variation of this module.
//
// The returned structure has its Mutator field set to "image" and its Variation field set to the
// image variation, e.g. recovery, ramdisk, etc.. The Variation field is "" for host modules and
// device modules that have no image variation.
ImageVariation() blueprint.Variation
Owner() string
InstallInData() bool
InstallInTestcases() bool
InstallInSanitizerDir() bool
InstallInRamdisk() bool
InstallInVendorRamdisk() bool
InstallInDebugRamdisk() bool
InstallInRecovery() bool
InstallInRoot() bool
InstallInOdm() bool
InstallInProduct() bool
InstallInVendor() bool
InstallInSystemExt() bool
InstallInSystemDlkm() bool
InstallInVendorDlkm() bool
InstallInOdmDlkm() bool
InstallForceOS() (*OsType, *ArchType)
PartitionTag(DeviceConfig) string
HideFromMake()
IsHideFromMake() bool
SkipInstall()
IsSkipInstall() bool
MakeUninstallable()
ReplacedByPrebuilt()
IsReplacedByPrebuilt() bool
ExportedToMake() bool
EffectiveLicenseFiles() Paths
AddProperties(props ...interface{})
GetProperties() []interface{}
BuildParamsForTests() []BuildParams
RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
VariablesForTests() map[string]string
// String returns a string that includes the module name and variants for printing during debugging.
String() string
// Get the qualified module id for this module.
qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
// Get information about the properties that can contain visibility rules.
visibilityProperties() []visibilityProperty
RequiredModuleNames(ctx ConfigurableEvaluatorContext) []string
HostRequiredModuleNames() []string
TargetRequiredModuleNames() []string
VintfFragmentModuleNames(ctx ConfigurableEvaluatorContext) []string
VintfFragments(ctx ConfigurableEvaluatorContext) []string
ConfigurableEvaluator(ctx ConfigurableEvaluatorContext) proptools.ConfigurableEvaluator
// The usage of this method is experimental and should not be used outside of fsgen package.
// This will be removed once product packaging migration to Soong is complete.
DecodeMultilib(ctx ConfigContext) (string, string)
// WARNING: This should not be used outside build/soong/fsgen
// Overrides returns the list of modules which should not be installed if this module is installed.
Overrides() []string
// If this is true, the module must not read product-specific configurations.
UseGenericConfig() bool
}
// Qualified id for a module
type qualifiedModuleName struct {
// The package (i.e. directory) in which the module is defined, without trailing /
pkg string
// The name of the module, empty string if package.
name string
}
func (q qualifiedModuleName) String() string {
if q.name == "" {
return "//" + q.pkg
}
return "//" + q.pkg + ":" + q.name
}
func (q qualifiedModuleName) isRootPackage() bool {
return q.pkg == "" && q.name == ""
}
// Get the id for the package containing this module.
func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
pkg := q.pkg
if q.name == "" {
if pkg == "" {
panic(fmt.Errorf("Cannot get containing package id of root package"))
}
index := strings.LastIndex(pkg, "/")
if index == -1 {
pkg = ""
} else {
pkg = pkg[:index]
}
}
return newPackageId(pkg)
}
func newPackageId(pkg string) qualifiedModuleName {
// A qualified id for a package module has no name.
return qualifiedModuleName{pkg: pkg, name: ""}
}
type Dist struct {
// Copy the output of this module to the $DIST_DIR when `dist` is specified on the
// command line and any of these targets are also on the command line, or otherwise
// built
Targets []string `android:"arch_variant"`
// The name of the output artifact. This defaults to the basename of the output of
// the module.
Dest *string `android:"arch_variant"`
// The directory within the dist directory to store the artifact. Defaults to the
// top level directory ("").
Dir *string `android:"arch_variant"`
// A suffix to add to the artifact file name (before any extension).
Suffix *string `android:"arch_variant"`
// If true, then the artifact file will be appended with _<product name>. For
// example, if the product is coral and the module is an android_app module
// of name foo, then the artifact would be foo_coral.apk. If false, there is
// no change to the artifact file name.
Append_artifact_with_product *bool `android:"arch_variant"`
// A string tag to select the OutputFiles associated with the tag.
//
// If no tag is specified then it will select the default dist paths provided
// by the module type. If a tag of "" is specified then it will return the
// default output files provided by the modules, i.e. the result of calling
// OutputFiles("").
Tag *string `android:"arch_variant"`
}
// NamedPath associates a path with a name. e.g. a license text path with a package name
type NamedPath struct {
Path Path
Name string
}
// String returns an escaped string representing the `NamedPath`.
func (p NamedPath) String() string {
if len(p.Name) > 0 {
return p.Path.String() + ":" + url.QueryEscape(p.Name)
}
return p.Path.String()
}
// NamedPaths describes a list of paths each associated with a name.
type NamedPaths []NamedPath
// Strings returns a list of escaped strings representing each `NamedPath` in the list.
func (l NamedPaths) Strings() []string {
result := make([]string, 0, len(l))
for _, p := range l {
result = append(result, p.String())
}
return result
}
// SortedUniqueNamedPaths modifies `l` in place to return the sorted unique subset.
func SortedUniqueNamedPaths(l NamedPaths) NamedPaths {
if len(l) == 0 {
return l
}
sort.Slice(l, func(i, j int) bool {
return l[i].String() < l[j].String()
})
k := 0
for i := 1; i < len(l); i++ {
if l[i].String() == l[k].String() {
continue
}
k++
if k < i {
l[k] = l[i]
}
}
return l[:k+1]
}
type nameProperties struct {
// The name of the module. Must be unique across all modules.
Name *string
}
// Properties common to all modules inheriting from ModuleBase. These properties are automatically
// inherited by sub-modules created with ctx.CreateModule()
type commonProperties struct {
// emit build rules for this module
//
// Disabling a module should only be done for those modules that cannot be built
// in the current environment. Modules that can build in the current environment
// but are not usually required (e.g. superceded by a prebuilt) should not be
// disabled as that will prevent them from being built by the checkbuild target
// and so prevent early detection of changes that have broken those modules.
Enabled proptools.Configurable[bool] `android:"arch_variant,replace_instead_of_append"`
// Controls the visibility of this module to other modules. Allowable values are one or more of
// these formats:
//
// ["//visibility:public"]: Anyone can use this module.
// ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
// this module.
// ["//visibility:override"]: Discards any rules inherited from defaults or a creating module.
// Can only be used at the beginning of a list of visibility rules.
// ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
// other/package (defined in some/package/*.bp and other/package/*.bp) have access to
// this module. Note that sub-packages do not have access to the rule; for example,
// //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
// is a special module and must be used verbatim. It represents all of the modules in the
// package.
// ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
// or other or in one of their sub-packages have access to this module. For example,
// //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
// to depend on this rule (but not //independent:evil)
// ["//project"]: This is shorthand for ["//project:__pkg__"]
// [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
// //project is the module's package. e.g. using [":__subpackages__"] in
// packages/apps/Settings/Android.bp is equivalent to
// //packages/apps/Settings:__subpackages__.
// ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
// for now. It is an error if it is used in a module.
//
// If a module does not specify the `visibility` property then it uses the
// `default_visibility` property of the `package` module in the module's package.
//
// If the `default_visibility` property is not set for the module's package then
// it will use the `default_visibility` of its closest ancestor package for which
// a `default_visibility` property is specified.
//
// If no `default_visibility` property can be found then the module uses the
// global default of `//visibility:legacy_public`.
//
// The `visibility` property has no effect on a defaults module although it does
// apply to any non-defaults module that uses it. To set the visibility of a
// defaults module, use the `defaults_visibility` property on the defaults module;
// not to be confused with the `default_visibility` property on the package module.
//
// See https://android.googlesource.com/platform/build/soong/+/main/README.md#visibility for
// more details.
Visibility []string
// Describes the licenses applicable to this module. Must reference license modules.
Licenses []string
// Override of module name when reporting licenses
Effective_package_name *string `blueprint:"mutated"`
// Notice files
Effective_license_text NamedPaths `blueprint:"mutated"`
// License names
Effective_license_kinds []string `blueprint:"mutated"`
// License conditions
Effective_license_conditions []string `blueprint:"mutated"`
// control whether this module compiles for 32-bit, 64-bit, or both. Possible values
// are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
// architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
// platform).
Compile_multilib *string `android:"arch_variant"`
Target struct {
Host struct {
Compile_multilib *string
}
Android struct {
Compile_multilib *string
Enabled *bool
}
}
// If set to true then the archMutator will create variants for each arch specific target
// (e.g. 32/64) that the module is required to produce. If set to false then it will only
// create a variant for the architecture and will list the additional arch specific targets
// that the variant needs to produce in the CompileMultiTargets property.
UseTargetVariants bool `blueprint:"mutated"`
Default_multilib string `blueprint:"mutated"`
// whether this is a proprietary vendor module, and should be installed into /vendor
Proprietary *bool
// vendor who owns this module
Owner *string
// whether this module is specific to an SoC (System-On-a-Chip). When set to true,
// it is installed into /vendor (or /system/vendor if vendor partition does not exist).
// Use `soc_specific` instead for better meaning.
Vendor *bool
// whether this module is specific to an SoC (System-On-a-Chip). When set to true,
// it is installed into /vendor (or /system/vendor if vendor partition does not exist).
Soc_specific *bool
// whether this module is specific to a device, not only for SoC, but also for off-chip
// peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
// does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
// This implies `soc_specific:true`.
Device_specific *bool
// whether this module is specific to a software configuration of a product (e.g. country,
// network operator, etc). When set to true, it is installed into /product (or
// /system/product if product partition does not exist).
Product_specific *bool
// whether this module extends system. When set to true, it is installed into /system_ext
// (or /system/system_ext if system_ext partition does not exist).
System_ext_specific *bool
// Whether this module is installed to recovery partition
Recovery *bool
// Whether this module is installed to ramdisk
Ramdisk *bool
// Whether this module is installed to vendor ramdisk
Vendor_ramdisk *bool
// Whether this module is installed to debug ramdisk
Debug_ramdisk *bool
// Install to partition system_dlkm when set to true.
System_dlkm_specific *bool
// Install to partition vendor_dlkm when set to true.
Vendor_dlkm_specific *bool
// Install to partition odm_dlkm when set to true.
Odm_dlkm_specific *bool
// Whether this module is built for non-native architectures (also known as native bridge binary)
Native_bridge_supported *bool `android:"arch_variant"`
// init.rc files to be installed if this module is installed
Init_rc proptools.Configurable[[]string] `android:"arch_variant,path"`
// VINTF manifest fragments to be installed if this module is installed
Vintf_fragments proptools.Configurable[[]string] `android:"path"`
// The OsType of artifacts that this module variant is responsible for creating.
//
// Set by osMutator
CompileOS OsType `blueprint:"mutated"`
// Set to true after the arch mutator has run on this module and set CompileTarget,
// CompileMultiTargets, and CompilePrimary
ArchReady bool `blueprint:"mutated"`
// The Target of artifacts that this module variant is responsible for creating.
//
// Set by archMutator
CompileTarget Target `blueprint:"mutated"`
// The additional arch specific targets (e.g. 32/64 bit) that this module variant is
// responsible for creating.
//
// By default this is nil as, where necessary, separate variants are created for the
// different multilib types supported and that information is encapsulated in the
// CompileTarget so the module variant simply needs to create artifacts for that.
//
// However, if UseTargetVariants is set to false (e.g. by
// InitAndroidMultiTargetsArchModule) then no separate variants are created for the
// multilib targets. Instead a single variant is created for the architecture and
// this contains the multilib specific targets that this variant should create.
//
// Set by archMutator
CompileMultiTargets []Target `blueprint:"mutated"`
// True if the module variant's CompileTarget is the primary target
//
// Set by archMutator
CompilePrimary bool `blueprint:"mutated"`
// Set by InitAndroidModule
HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
ArchSpecific bool `blueprint:"mutated"`
// If set to true then a CommonOS variant will be created which will have dependencies
// on all its OsType specific variants. Used by sdk/module_exports to create a snapshot
// that covers all os and architecture variants.
//
// The OsType specific variants can be retrieved by calling
// GetOsSpecificVariantsOfCommonOSVariant
//
// Set at module initialization time by calling InitCommonOSAndroidMultiTargetsArchModule
CreateCommonOSVariant bool `blueprint:"mutated"`
// When set to true, this module is not installed to the full install path (ex: under
// out/target/product/<name>/<partition>). It can be installed only to the packaging
// modules like android_filesystem.
No_full_install *bool
// When HideFromMake is set to true, no entry for this variant will be emitted in the
// generated Android.mk file.
HideFromMake bool `blueprint:"mutated"`
// When SkipInstall is set to true, calls to ctx.InstallFile, ctx.InstallExecutable,
// ctx.InstallSymlink and ctx.InstallAbsoluteSymlink act like calls to ctx.PackageFile
// and don't create a rule to install the file.
SkipInstall bool `blueprint:"mutated"`
// UninstallableApexPlatformVariant is set by MakeUninstallable called by the apex
// mutator. MakeUninstallable also sets HideFromMake. UninstallableApexPlatformVariant
// is used to avoid adding install or packaging dependencies into libraries provided
// by apexes.
UninstallableApexPlatformVariant bool `blueprint:"mutated"`
// Whether the module has been replaced by a prebuilt
ReplacedByPrebuilt bool `blueprint:"mutated"`
// Disabled by mutators. If set to true, it overrides Enabled property.
ForcedDisabled bool `blueprint:"mutated"`
NamespaceExportedToMake bool `blueprint:"mutated"`
MissingDeps []string `blueprint:"mutated"`
CheckedMissingDeps bool `blueprint:"mutated"`
// Name and variant strings stored by mutators to enable Module.String()
DebugName string `blueprint:"mutated"`
DebugMutators []string `blueprint:"mutated"`
DebugVariations []string `blueprint:"mutated"`
// ImageVariation is set by ImageMutator to specify which image this variation is for,
// for example "" for core or "recovery" for recovery. It will often be set to one of the
// constants in image.go, but can also be set to a custom value by individual module types.
ImageVariation string `blueprint:"mutated"`
// The team (defined by the owner/vendor) who owns the property.
Team *string `android:"path"`
// vintf_fragment Modules required from this module.
Vintf_fragment_modules proptools.Configurable[[]string] `android:"path"`
// List of module names that are prevented from being installed when this module gets
// installed.
Overrides []string
// Set to true if this module must be generic and does not require product-specific information.
// To be included in the system image, this property must be set to true.
Use_generic_config *bool
}
// Properties common to all modules inheriting from ModuleBase. Unlike commonProperties, these
// properties are NOT automatically inherited by sub-modules created with ctx.CreateModule()
type baseProperties struct {
// names of other modules to install if this module is installed
Required proptools.Configurable[[]string] `android:"arch_variant"`
// names of other modules to install on host if this module is installed
Host_required []string `android:"arch_variant"`
// names of other modules to install on target if this module is installed
Target_required []string `android:"arch_variant"`
// If this is a soong config module, this property will be set to the name of the original
// module type. This is used by neverallow to ensure you can't bypass a ModuleType() matcher
// just by creating a soong config module type.
Soong_config_base_module_type *string `blueprint:"mutated"`
}
type distProperties struct {
// configuration to distribute output files from this module to the distribution
// directory (default: $OUT/dist, configurable with $DIST_DIR)
Dist Dist `android:"arch_variant"`
// a list of configurations to distribute output files from this module to the
// distribution directory (default: $OUT/dist, configurable with $DIST_DIR)
Dists []Dist `android:"arch_variant"`
}
type TeamDepTagType struct {
blueprint.BaseDependencyTag
}
var teamDepTag = TeamDepTagType{}
// Dependency tag for required, host_required, and target_required modules.
var RequiredDepTag = struct {
blueprint.BaseDependencyTag
InstallAlwaysNeededDependencyTag
// Requiring disabled module has been supported (as a side effect of this being implemented
// in Make). We may want to make it an error, but for now, let's keep the existing behavior.
AlwaysAllowDisabledModuleDependencyTag
}{}
// CommonTestOptions represents the common `test_options` properties in
// Android.bp.
type CommonTestOptions struct {
// If the test is a hostside (no device required) unittest that shall be run
// during presubmit check.
Unit_test *bool
// Tags provide additional metadata to customize test execution by downstream
// test runners. The tags have no special meaning to Soong.
Tags []string
}
// SetAndroidMkEntries sets AndroidMkEntries according to the value of base
// `test_options`.
func (t *CommonTestOptions) SetAndroidMkEntries(entries *AndroidMkEntries) {
entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(t.Unit_test))
if len(t.Tags) > 0 {
entries.AddStrings("LOCAL_TEST_OPTIONS_TAGS", t.Tags...)
}
}
func (t *CommonTestOptions) SetAndroidMkInfoEntries(entries *AndroidMkInfo) {
entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(t.Unit_test))
if len(t.Tags) > 0 {
entries.AddStrings("LOCAL_TEST_OPTIONS_TAGS", t.Tags...)
}
}
// The key to use in TaggedDistFiles when a Dist structure does not specify a
// tag property. This intentionally does not use "" as the default because that
// would mean that an empty tag would have a different meaning when used in a dist
// structure that when used to reference a specific set of output paths using the
// :module{tag} syntax, which passes tag to the OutputFiles(tag) method.
const DefaultDistTag = "<default-dist-tag>"
// A map of OutputFile tag keys to Paths, for disting purposes.
type TaggedDistFiles map[string]Paths
// addPathsForTag adds a mapping from the tag to the paths. If the map is nil
// then it will create a map, update it and then return it. If a mapping already
// exists for the tag then the paths are appended to the end of the current list
// of paths, ignoring any duplicates.
func (t TaggedDistFiles) addPathsForTag(tag string, paths ...Path) TaggedDistFiles {
if t == nil {
t = make(TaggedDistFiles)
}
for _, distFile := range paths {
if distFile != nil && !t[tag].containsPath(distFile) {
t[tag] = append(t[tag], distFile)
}
}
return t
}
// merge merges the entries from the other TaggedDistFiles object into this one.
// If the TaggedDistFiles is nil then it will create a new instance, merge the
// other into it, and then return it.
func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles {
for tag, paths := range other {
t = t.addPathsForTag(tag, paths...)
}
return t
}
type hostAndDeviceProperties struct {
// If set to true, build a variant of the module for the host. Defaults to false.
Host_supported *bool
// If set to true, build a variant of the module for the device. Defaults to true.
Device_supported *bool
}
type hostCrossProperties struct {
// If set to true, build a variant of the module for the host cross. Defaults to true.
Host_cross_supported *bool
}
type Multilib string
const (
MultilibBoth Multilib = "both"
MultilibFirst Multilib = "first"
MultilibCommon Multilib = "common"
)
type HostOrDeviceSupported int
const (
hostSupported = 1 << iota
hostCrossSupported
deviceSupported
hostDefault
deviceDefault
// Host and HostCross are built by default. Device is not supported.
HostSupported = hostSupported | hostCrossSupported | hostDefault
// Host is built by default. HostCross and Device are not supported.
HostSupportedNoCross = hostSupported | hostDefault
// Device is built by default. Host and HostCross are not supported.
DeviceSupported = deviceSupported | deviceDefault
// By default, _only_ device variant is built. Device variant can be disabled with `device_supported: false`
// Host and HostCross are disabled by default and can be enabled with `host_supported: true`
HostAndDeviceSupported = hostSupported | hostCrossSupported | deviceSupported | deviceDefault
// Host, HostCross, and Device are built by default.
// Building Device can be disabled with `device_supported: false`
// Building Host and HostCross can be disabled with `host_supported: false`
HostAndDeviceDefault = hostSupported | hostCrossSupported | hostDefault |
deviceSupported | deviceDefault
// Nothing is supported. This is not exposed to the user, but used to mark a
// host only module as unsupported when the module type is not supported on
// the host OS. E.g. benchmarks are supported on Linux but not Darwin.
NeitherHostNorDeviceSupported = 0
)
type moduleKind int
const (
platformModule moduleKind = iota
deviceSpecificModule
socSpecificModule
productSpecificModule
systemExtSpecificModule
)
func (k moduleKind) String() string {
switch k {
case platformModule:
return "platform"
case deviceSpecificModule:
return "device-specific"
case socSpecificModule:
return "soc-specific"
case productSpecificModule:
return "product-specific"
case systemExtSpecificModule:
return "systemext-specific"
default:
panic(fmt.Errorf("unknown module kind %d", k))
}
}
func initAndroidModuleBase(m Module) {
m.base().module = m
}
// InitAndroidModule initializes the Module as an Android module that is not architecture-specific.
// It adds the common properties, for example "name" and "enabled".
func InitAndroidModule(m Module) {
initAndroidModuleBase(m)
base := m.base()
m.AddProperties(
&base.nameProperties,
&base.commonProperties,
&base.baseProperties,
&base.distProperties)
initProductVariableModule(m)
// The default_visibility property needs to be checked and parsed by the visibility module during
// its checking and parsing phases so make it the primary visibility property.
setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility)
// The default_applicable_licenses property needs to be checked and parsed by the licenses module during
// its checking and parsing phases so make it the primary licenses property.
setPrimaryLicensesProperty(m, "licenses", &base.commonProperties.Licenses)
}
// InitAndroidArchModule initializes the Module as an Android module that is architecture-specific.
// It adds the common properties, for example "name" and "enabled", as well as runtime generated
// property structs for architecture-specific versions of generic properties tagged with
// `android:"arch_variant"`.
//
// InitAndroidModule should not be called if InitAndroidArchModule was called.
func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
InitAndroidModule(m)
base := m.base()
base.commonProperties.HostOrDeviceSupported = hod
base.commonProperties.Default_multilib = string(defaultMultilib)
base.commonProperties.ArchSpecific = true
base.commonProperties.UseTargetVariants = true
if hod&hostSupported != 0 && hod&deviceSupported != 0 {
m.AddProperties(&base.hostAndDeviceProperties)
}
if hod&hostCrossSupported != 0 {
m.AddProperties(&base.hostCrossProperties)
}
initArchModule(m)
}
// InitAndroidMultiTargetsArchModule initializes the Module as an Android module that is
// architecture-specific, but will only have a single variant per OS that handles all the
// architectures simultaneously. The list of Targets that it must handle will be available from
// ModuleContext.MultiTargets. It adds the common properties, for example "name" and "enabled", as
// well as runtime generated property structs for architecture-specific versions of generic
// properties tagged with `android:"arch_variant"`.
//
// InitAndroidModule or InitAndroidArchModule should not be called if
// InitAndroidMultiTargetsArchModule was called.
func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
InitAndroidArchModule(m, hod, defaultMultilib)
m.base().commonProperties.UseTargetVariants = false
}
// InitCommonOSAndroidMultiTargetsArchModule initializes the Module as an Android module that is
// architecture-specific, but will only have a single variant per OS that handles all the
// architectures simultaneously, and will also have an additional CommonOS variant that has
// dependencies on all the OS-specific variants. The list of Targets that it must handle will be
// available from ModuleContext.MultiTargets. It adds the common properties, for example "name" and
// "enabled", as well as runtime generated property structs for architecture-specific versions of
// generic properties tagged with `android:"arch_variant"`.
//
// InitAndroidModule, InitAndroidArchModule or InitAndroidMultiTargetsArchModule should not be
// called if InitCommonOSAndroidMultiTargetsArchModule was called.
func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
InitAndroidArchModule(m, hod, defaultMultilib)
m.base().commonProperties.UseTargetVariants = false
m.base().commonProperties.CreateCommonOSVariant = true
}
// A ModuleBase object contains the properties that are common to all Android
// modules. It should be included as an anonymous field in every module
// struct definition. InitAndroidModule should then be called from the module's
// factory function, and the return values from InitAndroidModule should be
// returned from the factory function.
//
// The ModuleBase type is responsible for implementing the GenerateBuildActions
// method to support the blueprint.Module interface. This method will then call
// the module's GenerateAndroidBuildActions method once for each build variant
// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
// rather than the usual blueprint.ModuleContext.
// ModuleContext exposes extra functionality specific to the Android build
// system including details about the particular build variant that is to be
// generated.
//
// For example:
//
// import (
// "android/soong/android"
// )
//
// type myModule struct {
// android.ModuleBase
// properties struct {
// MyProperty string
// }
// }
//
// func NewMyModule() android.Module {
// m := &myModule{}
// m.AddProperties(&m.properties)
// android.InitAndroidModule(m)
// return m
// }
//
// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// // Get the CPU architecture for the current build variant.
// variantArch := ctx.Arch()
//
// // ...
// }
type ModuleBase struct {
// Putting the curiously recurring thing pointing to the thing that contains
// the thing pattern to good use.
// TODO: remove this
module Module
nameProperties nameProperties
commonProperties commonProperties
baseProperties baseProperties
distProperties distProperties
variableProperties interface{}
hostAndDeviceProperties hostAndDeviceProperties
hostCrossProperties hostCrossProperties
// Arch specific versions of structs in GetProperties() prior to
// initialization in InitAndroidArchModule, lets call it `generalProperties`.
// The outer index has the same order as generalProperties and the inner index
// chooses the props specific to the architecture. The interface{} value is an
// archPropRoot that is filled with arch specific values by the arch mutator.
archProperties [][]interface{}
// Information about all the properties on the module that contains visibility rules that need
// checking.
visibilityPropertyInfo []visibilityProperty
// The primary visibility property, may be nil, that controls access to the module.
primaryVisibilityProperty visibilityProperty
// The primary licenses property, may be nil, records license metadata for the module.
primaryLicensesProperty applicableLicensesProperty
noAddressSanitizer bool
hooks hooks
registerProps []interface{}
// For tests
buildParams []BuildParams
ruleParams map[blueprint.Rule]blueprint.RuleParams
variables map[string]string
}
func (m *ModuleBase) AddJSONData(d *map[string]interface{}) {
(*d)["Android"] = map[string]interface{}{
// Properties set in Blueprint or in blueprint of a defaults modules
"SetProperties": m.propertiesWithValues(),
}
}
type propInfo struct {
Name string
Type string
Value string
Values []string
}
func (m *ModuleBase) propertiesWithValues() []propInfo {
var info []propInfo
props := m.GetProperties()
var propsWithValues func(name string, v reflect.Value)
propsWithValues = func(name string, v reflect.Value) {
kind := v.Kind()
switch kind {
case reflect.Ptr, reflect.Interface:
if v.IsNil() {
return
}
propsWithValues(name, v.Elem())
case reflect.Struct:
if v.IsZero() {
return
}
for i := 0; i < v.NumField(); i++ {
namePrefix := name
sTyp := v.Type().Field(i)
if proptools.ShouldSkipProperty(sTyp) {
continue
}
if name != "" && !strings.HasSuffix(namePrefix, ".") {
namePrefix += "."
}
if !proptools.IsEmbedded(sTyp) {
namePrefix += sTyp.Name
}
sVal := v.Field(i)
propsWithValues(namePrefix, sVal)
}
case reflect.Array, reflect.Slice:
if v.IsNil() {
return
}
elKind := v.Type().Elem().Kind()
info = append(info, propInfo{Name: name, Type: elKind.String() + " " + kind.String(), Values: sliceReflectionValue(v)})
default:
info = append(info, propInfo{Name: name, Type: kind.String(), Value: reflectionValue(v)})
}
}
for _, p := range props {
propsWithValues("", reflect.ValueOf(p).Elem())
}
sort.Slice(info, func(i, j int) bool {
return info[i].Name < info[j].Name
})
return info
}
func reflectionValue(value reflect.Value) string {
switch value.Kind() {
case reflect.Bool:
return fmt.Sprintf("%t", value.Bool())
case reflect.Int64:
return fmt.Sprintf("%d", value.Int())
case reflect.String:
return fmt.Sprintf("%s", value.String())
case reflect.Struct:
if value.IsZero() {
return "{}"
}
length := value.NumField()
vals := make([]string, length, length)
for i := 0; i < length; i++ {
sTyp := value.Type().Field(i)
if proptools.ShouldSkipProperty(sTyp) {
continue
}
name := sTyp.Name
vals[i] = fmt.Sprintf("%s: %s", name, reflectionValue(value.Field(i)))
}
return fmt.Sprintf("%s{%s}", value.Type(), strings.Join(vals, ", "))
case reflect.Array, reflect.Slice:
vals := sliceReflectionValue(value)
return fmt.Sprintf("[%s]", strings.Join(vals, ", "))
}
return ""
}
func sliceReflectionValue(value reflect.Value) []string {
length := value.Len()
vals := make([]string, length, length)
for i := 0; i < length; i++ {
vals[i] = reflectionValue(value.Index(i))
}
return vals
}
func (m *ModuleBase) ComponentDepsMutator(BottomUpMutatorContext) {}
func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
func (m *ModuleBase) baseDepsMutator(ctx BottomUpMutatorContext) {
if m.Team() != "" {
ctx.AddDependency(ctx.Module(), teamDepTag, m.Team())
}
// TODO(jiyong): remove below case. This is to work around build errors happening
// on branches with reduced manifest like aosp_kernel-build-tools.
// In the branch, a build error occurs as follows.
// 1. aosp_kernel-build-tools is a reduced manifest branch. It doesn't have some git
// projects like external/bouncycastle
// 2. `boot_signer` is `required` by modules like `build_image` which is explicitly list as
// the top-level build goal (in the shell file that invokes Soong).
// 3. `boot_signer` depends on `bouncycastle-unbundled` which is in the missing git project.
// 4. aosp_kernel-build-tools invokes soong with `--soong-only`. Therefore, the absence of
// ALLOW_MISSING_DEPENDENCIES didn't cause a problem, as previously only make processed required
// dependencies.
// 5. Now, since Soong understands `required` deps, it tries to build `boot_signer` and the
// absence of external/bouncycastle fails the build.
//
// Unfortunately, there's no way for Soong to correctly determine if it's running in a
// reduced manifest branch. Instead, here, we use the absence of DeviceArch or DeviceName as
// a strong signal, because that's very common across reduced manifest branches.
pv := ctx.Config().productVariables
fullManifest := pv.DeviceArch != nil && pv.DeviceName != nil
if fullManifest {
addVintfFragmentDeps(ctx)
}
}
// required property can be overridden too; handle it separately
func (m *ModuleBase) baseOverridablePropertiesDepsMutator(ctx BottomUpMutatorContext) {
pv := ctx.Config().productVariables
fullManifest := pv.DeviceArch != nil && pv.DeviceName != nil
if fullManifest {
addRequiredDeps(ctx)
}
}
// addRequiredDeps adds required, target_required, and host_required as dependencies.
func addRequiredDeps(ctx BottomUpMutatorContext) {
addDep := func(target Target, depName string) {
if !ctx.OtherModuleExists(depName) {
if ctx.Config().AllowMissingDependencies() {
return
}
}
// If Android native module requires another Android native module, ensure that
// they have the same bitness. This mimics the policy in select-bitness-of-required-modules
// in build/make/core/main.mk.
// TODO(jiyong): the Make-side does this only when the required module is a shared
// library or a native test.
bothInAndroid := ctx.Device() && target.Os.Class == Device
nativeArch := InList(ctx.Arch().ArchType.Multilib, []string{"lib32", "lib64"}) &&
InList(target.Arch.ArchType.Multilib, []string{"lib32", "lib64"})
sameBitness := ctx.Arch().ArchType.Multilib == target.Arch.ArchType.Multilib
if bothInAndroid && nativeArch && !sameBitness {
return
}
// ... also don't make a dependency between native bridge arch and non-native bridge
// arches. b/342945184
if ctx.Target().NativeBridge != target.NativeBridge {
return
}
variation := target.Variations()
if ctx.OtherModuleFarDependencyVariantExists(variation, depName) {
ctx.AddFarVariationDependencies(variation, RequiredDepTag, depName)
}
}
var deviceTargets []Target
deviceTargets = append(deviceTargets, ctx.Config().Targets[Android]...)
deviceTargets = append(deviceTargets, ctx.Config().AndroidCommonTarget)
var hostTargets []Target
hostTargets = append(hostTargets, ctx.Config().Targets[ctx.Config().BuildOS]...)
hostTargets = append(hostTargets, ctx.Config().BuildOSCommonTarget)
if ctx.Device() {
for _, depName := range append(ctx.Module().RequiredModuleNames(ctx), ctx.Module().VintfFragmentModuleNames(ctx)...) {
for _, target := range deviceTargets {
addDep(target, depName)
}
}
for _, depName := range ctx.Module().HostRequiredModuleNames() {
for _, target := range hostTargets {
addDep(target, depName)
}
}
}
if ctx.Host() {
for _, depName := range append(ctx.Module().RequiredModuleNames(ctx), ctx.Module().VintfFragmentModuleNames(ctx)...) {
for _, target := range hostTargets {
// When a host module requires another host module, don't make a
// dependency if they have different OSes (i.e. hostcross).
if ctx.Target().HostCross != target.HostCross {
continue
}
addDep(target, depName)
}
}
for _, depName := range ctx.Module().TargetRequiredModuleNames() {
for _, target := range deviceTargets {
addDep(target, depName)
}
}
}
}
var vintfDepTag = struct {
blueprint.BaseDependencyTag
InstallAlwaysNeededDependencyTag
}{}
func IsVintfDepTag(depTag blueprint.DependencyTag) bool {
return depTag == vintfDepTag
}
func addVintfFragmentDeps(ctx BottomUpMutatorContext) {
// Vintf manifests in the recovery partition will be ignored.
if !ctx.Device() || ctx.Module().InstallInRecovery() {
return
}
deviceConfig := ctx.DeviceConfig()
mod := ctx.Module()
vintfModules := ctx.AddDependency(mod, vintfDepTag, mod.VintfFragmentModuleNames(ctx)...)
modPartition := mod.PartitionTag(deviceConfig)
for _, vintf := range vintfModules {
if vintf == nil {
// TODO(b/372091092): Remove this. Having it gives us missing dependency errors instead
// of nil pointer dereference errors, but we should resolve the missing dependencies.
continue
}
if vintfModule, ok := vintf.(*VintfFragmentModule); ok {
vintfPartition := vintfModule.PartitionTag(deviceConfig)
if modPartition != vintfPartition {
ctx.ModuleErrorf("Module %q(%q) and Vintf_fragment %q(%q) are installed to different partitions.",
mod.Name(), modPartition,
vintfModule.Name(), vintfPartition)
}
} else {
ctx.ModuleErrorf("Only vintf_fragment type module should be listed in vintf_fragment_modules : %q", vintf.Name())
}
}
}
// AddProperties "registers" the provided props
// each value in props MUST be a pointer to a struct
func (m *ModuleBase) AddProperties(props ...interface{}) {
m.registerProps = append(m.registerProps, props...)
}
func (m *ModuleBase) GetProperties() []interface{} {
return m.registerProps
}
func (m *ModuleBase) BuildParamsForTests() []BuildParams {
// Expand the references to module variables like $flags[0-9]*,
// so we do not need to change many existing unit tests.
// This looks like undoing the shareFlags optimization in cc's
// transformSourceToObj, and should only affects unit tests.
vars := m.VariablesForTests()
buildParams := append([]BuildParams(nil), m.buildParams...)
for i := range buildParams {
newArgs := make(map[string]string)
for k, v := range buildParams[i].Args {
newArgs[k] = v
// Replaces both ${flags1} and $flags1 syntax.
if strings.HasPrefix(v, "${") && strings.HasSuffix(v, "}") {
if value, found := vars[v[2:len(v)-1]]; found {
newArgs[k] = value
}
} else if strings.HasPrefix(v, "$") {
if value, found := vars[v[1:]]; found {
newArgs[k] = value
}
}
}
buildParams[i].Args = newArgs
}
return buildParams
}
func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
return m.ruleParams
}
func (m *ModuleBase) VariablesForTests() map[string]string {
return m.variables
}
// Name returns the name of the module. It may be overridden by individual module types, for
// example prebuilts will prepend prebuilt_ to the name.
func (m *ModuleBase) Name() string {
return String(m.nameProperties.Name)
}
// String returns a string that includes the module name and variants for printing during debugging.
func (m *ModuleBase) String() string {
sb := strings.Builder{}
sb.WriteString(m.commonProperties.DebugName)
sb.WriteString("{")
for i := range m.commonProperties.DebugMutators {
if i != 0 {
sb.WriteString(",")
}
sb.WriteString(m.commonProperties.DebugMutators[i])
sb.WriteString(":")
sb.WriteString(m.commonProperties.DebugVariations[i])
}
sb.WriteString("}")
return sb.String()
}
// BaseModuleName returns the name of the module as specified in the blueprints file.
func (m *ModuleBase) BaseModuleName() string {
return String(m.nameProperties.Name)
}
func (m *ModuleBase) base() *ModuleBase {
return m
}
func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
}
func (m *ModuleBase) visibilityProperties() []visibilityProperty {
return m.visibilityPropertyInfo
}
func (m *ModuleBase) Dists() []Dist {
if len(m.distProperties.Dist.Targets) > 0 {
// Make a copy of the underlying Dists slice to protect against
// backing array modifications with repeated calls to this method.
distsCopy := append([]Dist(nil), m.distProperties.Dists...)
return append(distsCopy, m.distProperties.Dist)
} else {
return m.distProperties.Dists
}
}
func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFiles {
var distFiles TaggedDistFiles
for _, dist := range m.Dists() {
// If no tag is specified then it means to use the default dist paths so use
// the special tag name which represents that.
tag := proptools.StringDefault(dist.Tag, DefaultDistTag)
distFileForTagFromProvider, err := outputFilesForModuleFromProvider(ctx, m.module, tag)
// If the module doesn't define output files for the DefaultDistTag, try the files under
// the "" tag.
if tag == DefaultDistTag && errors.Is(err, ErrUnsupportedOutputTag) {
distFileForTagFromProvider, err = outputFilesForModuleFromProvider(ctx, m.module, "")
}
if err != OutputFilesProviderNotSet {
if err != nil && tag != DefaultDistTag {
ctx.PropertyErrorf("dist.tag", "%s", err.Error())
} else {
distFiles = distFiles.addPathsForTag(tag, distFileForTagFromProvider...)
continue
}
}
}
return distFiles
}
func (m *ModuleBase) ArchReady() bool {
return m.commonProperties.ArchReady
}
func (m *ModuleBase) Target() Target {
return m.commonProperties.CompileTarget
}
func (m *ModuleBase) TargetPrimary() bool {
return m.commonProperties.CompilePrimary
}
func (m *ModuleBase) MultiTargets() []Target {
return m.commonProperties.CompileMultiTargets
}
func (m *ModuleBase) Os() OsType {
return m.Target().Os
}
func (m *ModuleBase) Host() bool {
return m.Os().Class == Host
}
func (m *ModuleBase) Device() bool {
return m.Os().Class == Device
}
func (m *ModuleBase) Arch() Arch {
return m.Target().Arch
}
func (m *ModuleBase) ArchSpecific() bool {
return m.commonProperties.ArchSpecific
}
// True if the current variant is a CommonOS variant, false otherwise.
func (m *ModuleBase) IsCommonOSVariant() bool {
return m.commonProperties.CompileOS == CommonOS
}
// supportsTarget returns true if the given Target is supported by the current module.
func (m *ModuleBase) supportsTarget(target Target) bool {
switch target.Os.Class {
case Host:
if target.HostCross {
return m.HostCrossSupported()
} else {
return m.HostSupported()
}
case Device:
return m.DeviceSupported()
default:
return false
}
}
// DeviceSupported returns true if the current module is supported and enabled for device targets,
// i.e. the factory method set the HostOrDeviceSupported value to include device support and
// the device support is enabled by default or enabled by the device_supported property.
func (m *ModuleBase) DeviceSupported() bool {
hod := m.commonProperties.HostOrDeviceSupported
// deviceEnabled is true if the device_supported property is true or the HostOrDeviceSupported
// value has the deviceDefault bit set.
deviceEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Device_supported, hod&deviceDefault != 0)
return hod&deviceSupported != 0 && deviceEnabled
}
// HostSupported returns true if the current module is supported and enabled for host targets,
// i.e. the factory method set the HostOrDeviceSupported value to include host support and
// the host support is enabled by default or enabled by the host_supported property.
func (m *ModuleBase) HostSupported() bool {
hod := m.commonProperties.HostOrDeviceSupported
// hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
// value has the hostDefault bit set.
hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
return hod&hostSupported != 0 && hostEnabled
}
// HostCrossSupported returns true if the current module is supported and enabled for host cross
// targets, i.e. the factory method set the HostOrDeviceSupported value to include host cross
// support and the host cross support is enabled by default or enabled by the
// host_supported property.
func (m *ModuleBase) HostCrossSupported() bool {
hod := m.commonProperties.HostOrDeviceSupported
// hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
// value has the hostDefault bit set.
hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
// Default true for the Host_cross_supported property
hostCrossEnabled := proptools.BoolDefault(m.hostCrossProperties.Host_cross_supported, true)
return hod&hostCrossSupported != 0 && hostEnabled && hostCrossEnabled
}
func (m *ModuleBase) Platform() bool {
return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
}
func (m *ModuleBase) DeviceSpecific() bool {
return Bool(m.commonProperties.Device_specific)
}
func (m *ModuleBase) SocSpecific() bool {
return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
}
func (m *ModuleBase) ProductSpecific() bool {
return Bool(m.commonProperties.Product_specific)
}
func (m *ModuleBase) SystemExtSpecific() bool {
return Bool(m.commonProperties.System_ext_specific)
}
// RequiresStableAPIs returns true if the module will be installed to a partition that may
// be updated separately from the system image.
func (m *ModuleBase) RequiresStableAPIs(ctx BaseModuleContext) bool {
return m.SocSpecific() || m.DeviceSpecific() ||
(m.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface())
}
func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
partition := "system"
if m.SocSpecific() {
// A SoC-specific module could be on the vendor partition at
// "vendor" or the system partition at "system/vendor".
if config.VendorPath() == "vendor" {
partition = "vendor"
}
} else if m.DeviceSpecific() {
// A device-specific module could be on the odm partition at
// "odm", the vendor partition at "vendor/odm", or the system
// partition at "system/vendor/odm".
if config.OdmPath() == "odm" {
partition = "odm"
} else if strings.HasPrefix(config.OdmPath(), "vendor/") {
partition = "vendor"
}
} else if m.ProductSpecific() {
// A product-specific module could be on the product partition
// at "product" or the system partition at "system/product".
if config.ProductPath() == "product" {
partition = "product"
}
} else if m.SystemExtSpecific() {
// A system_ext-specific module could be on the system_ext
// partition at "system_ext" or the system partition at
// "system/system_ext".
if config.SystemExtPath() == "system_ext" {
partition = "system_ext"
}
} else if m.InstallInRamdisk() {
partition = "ramdisk"
} else if m.InstallInVendorRamdisk() {
partition = "vendor_ramdisk"
} else if m.InstallInRecovery() {
partition = "recovery"
}
return partition
}
func (m *ModuleBase) Enabled(ctx ConfigurableEvaluatorContext) bool {
if m.commonProperties.ForcedDisabled {
return false
}
return m.commonProperties.Enabled.GetOrDefault(m.ConfigurableEvaluator(ctx), !m.Os().DefaultDisabled)
}
// Returns a copy of the enabled property, useful for passing it on to sub-modules
func (m *ModuleBase) EnabledProperty() proptools.Configurable[bool] {
if m.commonProperties.ForcedDisabled {
return proptools.NewSimpleConfigurable(false)
}
return m.commonProperties.Enabled.Clone()
}
func (m *ModuleBase) Disable() {
m.commonProperties.ForcedDisabled = true
}
// HideFromMake marks this variant so that it is not emitted in the generated Android.mk file.
func (m *ModuleBase) HideFromMake() {
m.commonProperties.HideFromMake = true
}
// IsHideFromMake returns true if HideFromMake was previously called.
func (m *ModuleBase) IsHideFromMake() bool {
return m.commonProperties.HideFromMake == true
}
// SkipInstall marks this variant to not create install rules when ctx.Install* are called.
func (m *ModuleBase) SkipInstall() {
m.commonProperties.SkipInstall = true
}
// IsSkipInstall returns true if this variant is marked to not create install
// rules when ctx.Install* are called.
func (m *ModuleBase) IsSkipInstall() bool {
return m.commonProperties.SkipInstall
}
// Similar to HideFromMake, but if the AndroidMk entry would set
// LOCAL_UNINSTALLABLE_MODULE then this variant may still output that entry
// rather than leaving it out altogether. That happens in cases where it would
// have other side effects, in particular when it adds a NOTICE file target,
// which other install targets might depend on.
func (m *ModuleBase) MakeUninstallable() {
m.commonProperties.UninstallableApexPlatformVariant = true
m.HideFromMake()
m.SkipInstall()
}
func (m *ModuleBase) ReplacedByPrebuilt() {
m.commonProperties.ReplacedByPrebuilt = true
m.HideFromMake()
}
func (m *ModuleBase) IsReplacedByPrebuilt() bool {
return m.commonProperties.ReplacedByPrebuilt
}
func (m *ModuleBase) ExportedToMake() bool {
return m.commonProperties.NamespaceExportedToMake
}
func (m *ModuleBase) EffectiveLicenseFiles() Paths {
result := make(Paths, 0, len(m.commonProperties.Effective_license_text))
for _, p := range m.commonProperties.Effective_license_text {
result = append(result, p.Path)
}
return result
}
// computeInstallDeps finds the installed paths of all dependencies that have a dependency
// tag that is annotated as needing installation via the isInstallDepNeeded method.
func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]depset.DepSet[InstallPath], []depset.DepSet[PackagingSpec]) {
var installDeps []depset.DepSet[InstallPath]
var packagingSpecs []depset.DepSet[PackagingSpec]
ctx.VisitDirectDepsProxy(func(dep ModuleProxy) {
if isInstallDepNeeded(ctx, dep) {
// Installation is still handled by Make, so anything hidden from Make is not
// installable.
info := OtherModuleProviderOrDefault(ctx, dep, InstallFilesProvider)
commonInfo := OtherModulePointerProviderOrDefault(ctx, dep, CommonModuleInfoProvider)
if !commonInfo.HideFromMake && !commonInfo.SkipInstall {
installDeps = append(installDeps, info.TransitiveInstallFiles)
}
// Add packaging deps even when the dependency is not installed so that uninstallable
// modules can still be packaged. Often the package will be installed instead.
packagingSpecs = append(packagingSpecs, info.TransitivePackagingSpecs)
}
})
return installDeps, packagingSpecs
}
// isInstallDepNeeded returns true if installing the output files of the current module
// should also install the output files of the given dependency and dependency tag.
func isInstallDepNeeded(ctx ModuleContext, dep ModuleProxy) bool {
// Don't add a dependency from the platform to a library provided by an apex.
if OtherModulePointerProviderOrDefault(ctx, dep, CommonModuleInfoProvider).UninstallableApexPlatformVariant {
return false
}
// Only install modules if the dependency tag is an InstallDepNeeded tag.
return IsInstallDepNeededTag(ctx.OtherModuleDependencyTag(dep))
}
func (m *ModuleBase) NoAddressSanitizer() bool {
return m.noAddressSanitizer
}
func (m *ModuleBase) InstallInData() bool {
return false
}
func (m *ModuleBase) InstallInTestcases() bool {
return false
}
func (m *ModuleBase) InstallInSanitizerDir() bool {
return false
}
func (m *ModuleBase) InstallInRamdisk() bool {
return Bool(m.commonProperties.Ramdisk)
}
func (m *ModuleBase) InstallInVendorRamdisk() bool {
return Bool(m.commonProperties.Vendor_ramdisk)
}
func (m *ModuleBase) InstallInDebugRamdisk() bool {
return Bool(m.commonProperties.Debug_ramdisk)
}
func (m *ModuleBase) InstallInRecovery() bool {
return Bool(m.commonProperties.Recovery)
}
func (m *ModuleBase) InstallInOdm() bool {
return false
}
func (m *ModuleBase) InstallInProduct() bool {
return false
}
func (m *ModuleBase) InstallInVendor() bool {
return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Soc_specific) || Bool(m.commonProperties.Proprietary)
}
func (m *ModuleBase) InstallInSystemExt() bool {
return Bool(m.commonProperties.System_ext_specific)
}
func (m *ModuleBase) InstallInRoot() bool {
return false
}
func (m *ModuleBase) InstallInSystemDlkm() bool {
return Bool(m.commonProperties.System_dlkm_specific)
}
func (m *ModuleBase) InstallInVendorDlkm() bool {
return Bool(m.commonProperties.Vendor_dlkm_specific)
}
func (m *ModuleBase) InstallInOdmDlkm() bool {
return Bool(m.commonProperties.Odm_dlkm_specific)
}
func (m *ModuleBase) InstallForceOS() (*OsType, *ArchType) {
return nil, nil
}
func (m *ModuleBase) Owner() string {
return String(m.commonProperties.Owner)
}
func (m *ModuleBase) Team() string {
return String(m.commonProperties.Team)
}
func (m *ModuleBase) setImageVariation(variant string) {
m.commonProperties.ImageVariation = variant
}
func (m *ModuleBase) ImageVariation() blueprint.Variation {
return blueprint.Variation{
Mutator: "image",
Variation: m.base().commonProperties.ImageVariation,
}
}
func (m *ModuleBase) getVariationByMutatorName(mutator string) string {
for i, v := range m.commonProperties.DebugMutators {
if v == mutator {
return m.commonProperties.DebugVariations[i]
}
}
return ""
}
func (m *ModuleBase) InRamdisk() bool {
return m.base().commonProperties.ImageVariation == RamdiskVariation
}
func (m *ModuleBase) InVendorRamdisk() bool {
return m.base().commonProperties.ImageVariation == VendorRamdiskVariation
}
func (m *ModuleBase) InDebugRamdisk() bool {
return m.base().commonProperties.ImageVariation == DebugRamdiskVariation
}
func (m *ModuleBase) InRecovery() bool {
return m.base().commonProperties.ImageVariation == RecoveryVariation
}
func (m *ModuleBase) RequiredModuleNames(ctx ConfigurableEvaluatorContext) []string {
return m.base().baseProperties.Required.GetOrDefault(m.ConfigurableEvaluator(ctx), nil)
}
func (m *ModuleBase) HostRequiredModuleNames() []string {
return m.base().baseProperties.Host_required
}
func (m *ModuleBase) TargetRequiredModuleNames() []string {
return m.base().baseProperties.Target_required
}
func (m *ModuleBase) VintfFragmentModuleNames(ctx ConfigurableEvaluatorContext) []string {
return m.base().commonProperties.Vintf_fragment_modules.GetOrDefault(m.ConfigurableEvaluator(ctx), nil)
}
func (m *ModuleBase) VintfFragments(ctx ConfigurableEvaluatorContext) []string {
return m.base().commonProperties.Vintf_fragments.GetOrDefault(m.ConfigurableEvaluator(ctx), nil)
}
func (m *ModuleBase) generateVariantTarget(ctx *moduleContext) {
namespacePrefix := ctx.Namespace().id
if namespacePrefix != "" {
namespacePrefix = namespacePrefix + "-"
}
if !ctx.uncheckedModule {
name := namespacePrefix + ctx.ModuleName() + "-" + ctx.ModuleSubDir() + "-checkbuild"
ctx.Phony(name, ctx.checkbuildFiles...)
ctx.checkbuildTarget = PathForPhony(ctx, name)
}
}
// generateModuleTarget generates phony targets so that you can do `m <module-name>`.
// It will be run on every variant of the module, so it relies on the fact that phony targets
// are deduped to merge all the deps from different variants together.
func (m *ModuleBase) generateModuleTarget(ctx *moduleContext) {
var namespacePrefix string
nameSpace := ctx.Namespace().Path
if nameSpace != "." {
namespacePrefix = strings.ReplaceAll(nameSpace, "/", ".") + "-"
}
var deps Paths
var info ModuleBuildTargetsInfo
if len(ctx.installFiles) > 0 {
name := namespacePrefix + ctx.ModuleName() + "-install"
installFiles := ctx.installFiles.Paths()
ctx.Phony(name, installFiles...)
info.InstallTarget = PathForPhony(ctx, name)
deps = append(deps, installFiles...)
}
// A module's -checkbuild phony targets should
// not be created if the module is not exported to make.
// Those could depend on the build target and fail to compile
// for the current build target.
if (!ctx.Config().KatiEnabled() || !shouldSkipAndroidMkProcessing(ctx, m)) && !ctx.uncheckedModule && ctx.checkbuildTarget != nil {
name := namespacePrefix + ctx.ModuleName() + "-checkbuild"
ctx.Phony(name, ctx.checkbuildTarget)
deps = append(deps, ctx.checkbuildTarget)
}
if outputFiles, err := outputFilesForModule(ctx, ctx.Module(), ""); err == nil && len(outputFiles) > 0 {
name := namespacePrefix + ctx.ModuleName() + "-outputs"
ctx.Phony(name, outputFiles...)
deps = append(deps, outputFiles...)
}
if len(deps) > 0 {
suffix := ""
if ctx.Config().KatiEnabled() {
suffix = "-soong"
}
ctx.Phony(namespacePrefix+ctx.ModuleName()+suffix, deps...)
if ctx.Device() {
// Generate a target suffix for use in atest etc.
ctx.Phony(namespacePrefix+ctx.ModuleName()+"-target"+suffix, deps...)
} else {
// Generate a host suffix for use in atest etc.
ctx.Phony(namespacePrefix+ctx.ModuleName()+"-host"+suffix, deps...)
if ctx.Target().HostCross {
// Generate a host-cross suffix for use in atest etc.
ctx.Phony(namespacePrefix+ctx.ModuleName()+"-host-cross"+suffix, deps...)
}
}
info.BlueprintDir = ctx.ModuleDir()
SetProvider(ctx, ModuleBuildTargetsProvider, info)
}
}
func determineModuleKind(m *ModuleBase, ctx ModuleErrorContext) moduleKind {
var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
var deviceSpecific = Bool(m.commonProperties.Device_specific)
var productSpecific = Bool(m.commonProperties.Product_specific)
var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
msg := "conflicting value set here"
if socSpecific && deviceSpecific {
ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
if Bool(m.commonProperties.Vendor) {
ctx.PropertyErrorf("vendor", msg)
}
if Bool(m.commonProperties.Proprietary) {
ctx.PropertyErrorf("proprietary", msg)
}
if Bool(m.commonProperties.Soc_specific) {
ctx.PropertyErrorf("soc_specific", msg)
}
}
if productSpecific && systemExtSpecific {
ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
ctx.PropertyErrorf("system_ext_specific", msg)
}
if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
if productSpecific {
ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
} else {
ctx.PropertyErrorf("system_ext_specific", "a module cannot be specific to SoC or device and system_ext at the same time.")
}
if deviceSpecific {
ctx.PropertyErrorf("device_specific", msg)
} else {
if Bool(m.commonProperties.Vendor) {
ctx.PropertyErrorf("vendor", msg)
}
if Bool(m.commonProperties.Proprietary) {
ctx.PropertyErrorf("proprietary", msg)
}
if Bool(m.commonProperties.Soc_specific) {
ctx.PropertyErrorf("soc_specific", msg)
}
}
}
if productSpecific {
return productSpecificModule
} else if systemExtSpecific {
return systemExtSpecificModule
} else if deviceSpecific {
return deviceSpecificModule
} else if socSpecific {
return socSpecificModule
} else {
return platformModule
}
}
func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
return earlyModuleContext{
EarlyModuleContext: ctx,
kind: determineModuleKind(m, ctx),
config: ctx.Config().(Config),
}
}
func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
return baseModuleContext{
bp: ctx,
archModuleContext: m.archModuleContextFactory(ctx),
earlyModuleContext: m.earlyModuleContextFactory(ctx),
}
}
type archModuleContextFactoryContext interface {
Config() interface{}
}
func (m *ModuleBase) archModuleContextFactory(ctx archModuleContextFactoryContext) archModuleContext {
config := ctx.Config().(Config)
target := m.Target()
primaryArch := false
if len(config.Targets[target.Os]) <= 1 {
primaryArch = true
} else {
primaryArch = target.Arch.ArchType == config.Targets[target.Os][0].Arch.ArchType
}
return archModuleContext{
ready: m.commonProperties.ArchReady,
os: m.commonProperties.CompileOS,
target: m.commonProperties.CompileTarget,
targetPrimary: m.commonProperties.CompilePrimary,
multiTargets: m.commonProperties.CompileMultiTargets,
primaryArch: primaryArch,
}
}
type InstallFilesInfo struct {
InstallFiles InstallPaths
CheckbuildFiles Paths
CheckbuildTarget Path
UncheckedModule bool
PackagingSpecs []PackagingSpec
// katiInstalls tracks the install rules that were created by Soong but are being exported
// to Make to convert to ninja rules so that Make can add additional dependencies.
KatiInstalls katiInstalls
KatiSymlinks katiInstalls
TestData []DataPath
TransitivePackagingSpecs depset.DepSet[PackagingSpec]
LicenseMetadataFile WritablePath
// The following fields are private before, make it private again once we have
// better solution.
TransitiveInstallFiles depset.DepSet[InstallPath]
// katiInitRcInstalls and katiVintfInstalls track the install rules created by Soong that are
// allowed to have duplicates across modules and variants.
KatiInitRcInstalls katiInstalls
KatiVintfInstalls katiInstalls
InitRcPaths Paths
VintfFragmentsPaths Paths
InstalledInitRcPaths InstallPaths
InstalledVintfFragmentsPaths InstallPaths
// The files to copy to the dist as explicitly specified in the .bp file.
DistFiles TaggedDistFiles
}
var InstallFilesProvider = blueprint.NewProvider[InstallFilesInfo]()
type SourceFilesInfo struct {
Srcs Paths
}
var SourceFilesInfoProvider = blueprint.NewProvider[SourceFilesInfo]()
// ModuleBuildTargetsInfo is used by buildTargetSingleton to create checkbuild and
// per-directory build targets.
type ModuleBuildTargetsInfo struct {
InstallTarget WritablePath
CheckbuildTarget WritablePath
BlueprintDir string
}
var ModuleBuildTargetsProvider = blueprint.NewProvider[ModuleBuildTargetsInfo]()
type CommonModuleInfo struct {
Enabled bool
// Whether the module has been replaced by a prebuilt
ReplacedByPrebuilt bool
// The Target of artifacts that this module variant is responsible for creating.
Target Target
SkipAndroidMkProcessing bool
BaseModuleName string
CanHaveApexVariants bool
MinSdkVersion ApiLevelOrPlatform
SdkVersion string
NotAvailableForPlatform bool
// There some subtle differences between this one and the one above.
NotInPlatform bool
// UninstallableApexPlatformVariant is set by MakeUninstallable called by the apex
// mutator. MakeUninstallable also sets HideFromMake. UninstallableApexPlatformVariant
// is used to avoid adding install or packaging dependencies into libraries provided
// by apexes.
UninstallableApexPlatformVariant bool
MinSdkVersionSupported ApiLevel
ModuleWithMinSdkVersionCheck bool
// Tests if this module can be installed to APEX as a file. For example, this would return
// true for shared libs while return false for static libs because static libs are not
// installable module (but it can still be mutated for APEX)
IsInstallableToApex bool
HideFromMake bool
SkipInstall bool
IsStubsModule bool
Host bool
IsApexModule bool
// The primary licenses property, may be nil, records license metadata for the module.
PrimaryLicensesProperty applicableLicensesProperty
Owner string
Vendor bool
Proprietary bool
SocSpecific bool
ProductSpecific bool
SystemExtSpecific bool
DeviceSpecific bool
// When set to true, this module is not installed to the full install path (ex: under
// out/target/product/<name>/<partition>). It can be installed only to the packaging
// modules like android_filesystem.
NoFullInstall bool
InVendorRamdisk bool
ExemptFromRequiredApplicableLicensesProperty bool
RequiredModuleNames []string
HostRequiredModuleNames []string
TargetRequiredModuleNames []string
VintfFragmentModuleNames []string
Dists []Dist
ExportedToMake bool
Team string
PartitionTag string
}
type ApiLevelOrPlatform struct {
ApiLevel *ApiLevel
IsPlatform bool
}
var CommonModuleInfoProvider = blueprint.NewProvider[*CommonModuleInfo]()
type PrebuiltModuleInfo struct {
SourceExists bool
UsePrebuilt bool
}
var PrebuiltModuleInfoProvider = blueprint.NewProvider[PrebuiltModuleInfo]()
type HostToolProviderInfo struct {
HostToolPath OptionalPath
}
var HostToolProviderInfoProvider = blueprint.NewProvider[HostToolProviderInfo]()
type DistInfo struct {
Dists []dist
}
var DistProvider = blueprint.NewProvider[DistInfo]()
type SourceFileGenerator interface {
GeneratedSourceFiles() Paths
GeneratedHeaderDirs() Paths
GeneratedDeps() Paths
}
type GeneratedSourceInfo struct {
GeneratedSourceFiles Paths
GeneratedHeaderDirs Paths
GeneratedDeps Paths
}
var GeneratedSourceInfoProvider = blueprint.NewProvider[GeneratedSourceInfo]()
func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
ctx := &moduleContext{
module: m.module,
bp: blueprintCtx,
baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
variables: make(map[string]string),
phonies: make(map[string]Paths),
}
setContainerInfo(ctx)
if ctx.Config().Getenv("DISABLE_CONTAINER_CHECK") != "true" {
checkContainerViolations(ctx)
}
ctx.licenseMetadataFile = PathForModuleOut(ctx, "meta_lic")
dependencyInstallFiles, dependencyPackagingSpecs := m.computeInstallDeps(ctx)
// set the TransitiveInstallFiles to only the transitive dependencies to be used as the dependencies
// of installed files of this module. It will be replaced by a depset including the installed
// files of this module at the end for use by modules that depend on this one.
ctx.TransitiveInstallFiles = depset.New[InstallPath](depset.TOPOLOGICAL, nil, dependencyInstallFiles)
// Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
// reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
// TODO: This will be removed once defaults modules handle missing dependency errors
blueprintCtx.GetMissingDependencies()
// For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
// are enabled. Unless the module is a CommonOS variant which may have dependencies on disabled variants
// (because the dependencies are added before the modules are disabled). The
// GetOsSpecificVariantsOfCommonOSVariant(...) method will ensure that the disabled variants are
// ignored.
ctx.baseModuleContext.strictVisitDeps = !m.IsCommonOSVariant()
if ctx.config.captureBuild {
ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
}
desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
var suffix []string
if ctx.Os().Class != Device && ctx.Os().Class != Generic {
suffix = append(suffix, ctx.Os().String())
}
if !ctx.PrimaryArch() {
suffix = append(suffix, ctx.Arch().ArchType.String())
}
if apexInfo, _ := ModuleProvider(ctx, ApexInfoProvider); !apexInfo.IsForPlatform() {
suffix = append(suffix, apexInfo.ApexVariationName)
}
ctx.Variable(pctx, "moduleDesc", desc)
s := ""
if len(suffix) > 0 {
s = " [" + strings.Join(suffix, " ") + "]"
}
ctx.Variable(pctx, "moduleDescSuffix", s)
// Some common property checks for properties that will be used later in androidmk.go
checkDistProperties(ctx, "dist", &m.distProperties.Dist)
for i := range m.distProperties.Dists {
checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i])
}
var installFiles InstallFilesInfo
if m.Enabled(ctx) {
// ensure all direct android.Module deps are enabled
ctx.VisitDirectDepsProxy(func(m ModuleProxy) {})
if m.Device() {
// Handle any init.rc and vintf fragment files requested by the module. All files installed by this
// module will automatically have a dependency on the installed init.rc or vintf fragment file.
// The same init.rc or vintf fragment file may be requested by multiple modules or variants,
// so instead of installing them now just compute the install path and store it for later.
// The full list of all init.rc and vintf fragment install rules will be deduplicated later
// so only a single rule is created for each init.rc or vintf fragment file.
if !m.InVendorRamdisk() {
ctx.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc.GetOrDefault(ctx, nil))
rcDir := PathForModuleInstall(ctx, "etc", "init")
for _, src := range ctx.initRcPaths {
installedInitRc := rcDir.Join(ctx, src.Base())
ctx.katiInitRcInstalls = append(ctx.katiInitRcInstalls, katiInstall{
from: src,
to: installedInitRc,
})
ctx.PackageFile(rcDir, src.Base(), src)
ctx.installedInitRcPaths = append(ctx.installedInitRcPaths, installedInitRc)
}
installFiles.InitRcPaths = ctx.initRcPaths
installFiles.KatiInitRcInstalls = ctx.katiInitRcInstalls
installFiles.InstalledInitRcPaths = ctx.installedInitRcPaths
}
ctx.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments.GetOrDefault(ctx, nil))
vintfDir := PathForModuleInstall(ctx, "etc", "vintf", "manifest")
for _, src := range ctx.vintfFragmentsPaths {
installedVintfFragment := vintfDir.Join(ctx, src.Base())
ctx.katiVintfInstalls = append(ctx.katiVintfInstalls, katiInstall{
from: src,
to: installedVintfFragment,
})
ctx.PackageFile(vintfDir, src.Base(), src)
ctx.installedVintfFragmentsPaths = append(ctx.installedVintfFragmentsPaths, installedVintfFragment)
}
installFiles.VintfFragmentsPaths = ctx.vintfFragmentsPaths
installFiles.KatiVintfInstalls = ctx.katiVintfInstalls
installFiles.InstalledVintfFragmentsPaths = ctx.installedVintfFragmentsPaths
}
licensesPropertyFlattener(ctx)
if ctx.Failed() {
return
}
if jarJarPrefixHandler != nil {
jarJarPrefixHandler(ctx)
if ctx.Failed() {
return
}
}
// Call aconfigUpdateAndroidBuildActions to collect merged aconfig files before being used
// in m.module.GenerateAndroidBuildActions
aconfigUpdateAndroidBuildActions(ctx)
if ctx.Failed() {
return
}
m.module.GenerateAndroidBuildActions(ctx)
if ctx.Failed() {
return
}
if x, ok := m.module.(IDEInfo); ok {
var result IdeInfo
x.IDEInfo(ctx, &result)
result.BaseModuleName = x.BaseModuleName()
SetProvider(ctx, IdeInfoProviderKey, result)
}
// Create the set of tagged dist files after calling GenerateAndroidBuildActions
// as GenerateTaggedDistFiles() calls OutputFiles(tag) and so relies on the
// output paths being set which must be done before or during
// GenerateAndroidBuildActions.
installFiles.DistFiles = m.GenerateTaggedDistFiles(ctx)
if ctx.Failed() {
return
}
m.generateVariantTarget(ctx)
installFiles.LicenseMetadataFile = ctx.licenseMetadataFile
installFiles.InstallFiles = ctx.installFiles
installFiles.CheckbuildFiles = ctx.checkbuildFiles
installFiles.CheckbuildTarget = ctx.checkbuildTarget
installFiles.UncheckedModule = ctx.uncheckedModule
installFiles.PackagingSpecs = ctx.packagingSpecs
installFiles.KatiInstalls = ctx.katiInstalls
installFiles.KatiSymlinks = ctx.katiSymlinks
installFiles.TestData = ctx.testData
} else if ctx.Config().AllowMissingDependencies() {
// If the module is not enabled it will not create any build rules, nothing will call
// ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
// and report them as an error even when AllowMissingDependencies = true. Call
// ctx.GetMissingDependencies() here to tell blueprint not to handle them.
ctx.GetMissingDependencies()
}
if sourceFileProducer, ok := m.module.(SourceFileProducer); ok {
srcs := sourceFileProducer.Srcs()
for _, src := range srcs {
if src == nil {
ctx.ModuleErrorf("SourceFileProducer cannot return nil srcs")
return
}
}
SetProvider(ctx, SourceFilesInfoProvider, SourceFilesInfo{Srcs: sourceFileProducer.Srcs()})
}
m.generateModuleTarget(ctx)
if ctx.Failed() {
return
}
ctx.TransitiveInstallFiles = depset.New[InstallPath](depset.TOPOLOGICAL, ctx.installFiles, dependencyInstallFiles)
installFiles.TransitiveInstallFiles = ctx.TransitiveInstallFiles
installFiles.TransitivePackagingSpecs = depset.New[PackagingSpec](depset.TOPOLOGICAL, ctx.packagingSpecs, dependencyPackagingSpecs)
SetProvider(ctx, InstallFilesProvider, installFiles)
buildLicenseMetadata(ctx, ctx.licenseMetadataFile)
if len(ctx.moduleInfoJSON) > 0 {
for _, moduleInfoJSON := range ctx.moduleInfoJSON {
if moduleInfoJSON.Disabled {
continue
}
var installed InstallPaths
installed = append(installed, ctx.katiInstalls.InstallPaths()...)
installed = append(installed, ctx.katiSymlinks.InstallPaths()...)
installed = append(installed, ctx.katiInitRcInstalls.InstallPaths()...)
installed = append(installed, ctx.katiVintfInstalls.InstallPaths()...)
installedStrings := installed.Strings()
var targetRequired, hostRequired []string
if ctx.Host() {
targetRequired = m.baseProperties.Target_required
} else {
hostRequired = m.baseProperties.Host_required
}
hostRequired = append(hostRequired, moduleInfoJSON.ExtraHostRequired...)
var data []string
for _, d := range ctx.testData {
data = append(data, d.ToRelativeInstallPath())
}
if moduleInfoJSON.Uninstallable {
installedStrings = nil
if len(moduleInfoJSON.CompatibilitySuites) == 1 && moduleInfoJSON.CompatibilitySuites[0] == "null-suite" {
moduleInfoJSON.CompatibilitySuites = nil
moduleInfoJSON.TestConfig = nil
moduleInfoJSON.AutoTestConfig = nil
data = nil
}
}
// M(C)TS supports a full test suite and partial per-module MTS test suites, with naming mts-${MODULE}.
// To reduce repetition, if we find a partial M(C)TS test suite without an full M(C)TS test suite,
// we add the full test suite to our list. This was inherited from
// AndroidMkEntries.AddCompatibilityTestSuites.
suites := moduleInfoJSON.CompatibilitySuites
if PrefixInList(suites, "mts-") && !InList("mts", suites) {
suites = append(suites, "mts")
}
if PrefixInList(suites, "mcts-") && !InList("mcts", suites) {
suites = append(suites, "mcts")
}
moduleInfoJSON.CompatibilitySuites = suites
required := append(m.RequiredModuleNames(ctx), m.VintfFragmentModuleNames(ctx)...)
required = append(required, moduleInfoJSON.ExtraRequired...)
registerName := moduleInfoJSON.RegisterNameOverride
if len(registerName) == 0 {
registerName = m.moduleInfoRegisterName(ctx, moduleInfoJSON.SubName)
}
moduleName := moduleInfoJSON.ModuleNameOverride
if len(moduleName) == 0 {
moduleName = m.BaseModuleName() + moduleInfoJSON.SubName
}
supportedVariants := moduleInfoJSON.SupportedVariantsOverride
if moduleInfoJSON.SupportedVariantsOverride == nil {
supportedVariants = []string{m.moduleInfoVariant(ctx)}
}
moduleInfoJSON.core = CoreModuleInfoJSON{
RegisterName: registerName,
Path: []string{ctx.ModuleDir()},
Installed: installedStrings,
ModuleName: moduleName,
SupportedVariants: supportedVariants,
TargetDependencies: targetRequired,
HostDependencies: hostRequired,
Data: data,
Required: required,
}
}
SetProvider(ctx, ModuleInfoJSONProvider, ctx.moduleInfoJSON)
}
m.buildParams = ctx.buildParams
m.ruleParams = ctx.ruleParams
m.variables = ctx.variables
outputFiles := ctx.GetOutputFiles()
if outputFiles.DefaultOutputFiles != nil || outputFiles.TaggedOutputFiles != nil {
SetProvider(ctx, OutputFilesProvider, outputFiles)
}
if len(ctx.phonies) > 0 {
SetProvider(ctx, ModulePhonyProvider, ModulePhonyInfo{
Phonies: ctx.phonies,
})
}
if len(ctx.dists) > 0 {
SetProvider(ctx, DistProvider, DistInfo{
Dists: ctx.dists,
})
}
buildComplianceMetadataProvider(ctx, m)
commonData := CommonModuleInfo{
Enabled: m.Enabled(ctx),
ReplacedByPrebuilt: m.commonProperties.ReplacedByPrebuilt,
Target: m.commonProperties.CompileTarget,
SkipAndroidMkProcessing: shouldSkipAndroidMkProcessing(ctx, m),
UninstallableApexPlatformVariant: m.commonProperties.UninstallableApexPlatformVariant,
HideFromMake: m.commonProperties.HideFromMake,
SkipInstall: m.commonProperties.SkipInstall,
Host: m.Host(),
PrimaryLicensesProperty: m.primaryLicensesProperty,
Owner: m.module.Owner(),
SocSpecific: Bool(m.commonProperties.Soc_specific),
Vendor: Bool(m.commonProperties.Vendor),
Proprietary: Bool(m.commonProperties.Proprietary),
ProductSpecific: Bool(m.commonProperties.Product_specific),
SystemExtSpecific: Bool(m.commonProperties.System_ext_specific),
DeviceSpecific: Bool(m.commonProperties.Device_specific),
NoFullInstall: proptools.Bool(m.commonProperties.No_full_install),
InVendorRamdisk: m.InVendorRamdisk(),
ExemptFromRequiredApplicableLicensesProperty: exemptFromRequiredApplicableLicensesProperty(m.module),
RequiredModuleNames: m.module.RequiredModuleNames(ctx),
HostRequiredModuleNames: m.module.HostRequiredModuleNames(),
TargetRequiredModuleNames: m.module.TargetRequiredModuleNames(),
VintfFragmentModuleNames: m.module.VintfFragmentModuleNames(ctx),
Dists: m.Dists(),
ExportedToMake: m.ExportedToMake(),
Team: m.Team(),
PartitionTag: m.PartitionTag(ctx.DeviceConfig()),
}
if mm, ok := m.module.(interface {
MinSdkVersion(ctx EarlyModuleContext) ApiLevel
}); ok {
ver := mm.MinSdkVersion(ctx)
commonData.MinSdkVersion.ApiLevel = &ver
} else if mm, ok := m.module.(interface{ MinSdkVersion() string }); ok {
ver := mm.MinSdkVersion()
// Compile against the current platform
if ver == "" {
commonData.MinSdkVersion.IsPlatform = true
} else {
api := ApiLevelFrom(ctx, ver)
commonData.MinSdkVersion.ApiLevel = &api
}
}
if mm, ok := m.module.(interface {
SdkVersion(ctx EarlyModuleContext) ApiLevel
}); ok {
ver := mm.SdkVersion(ctx)
if !ver.IsNone() {
commonData.SdkVersion = ver.String()
}
} else if mm, ok := m.module.(interface{ SdkVersion() string }); ok {
commonData.SdkVersion = mm.SdkVersion()
}
if am, ok := m.module.(ApexModule); ok {
commonData.CanHaveApexVariants = am.CanHaveApexVariants()
commonData.NotAvailableForPlatform = am.NotAvailableForPlatform()
commonData.NotInPlatform = am.NotInPlatform()
commonData.MinSdkVersionSupported = am.MinSdkVersionSupported(ctx)
commonData.IsInstallableToApex = am.IsInstallableToApex()
commonData.IsApexModule = true
}
if _, ok := m.module.(ModuleWithMinSdkVersionCheck); ok {
commonData.ModuleWithMinSdkVersionCheck = true
}
if st, ok := m.module.(StubsAvailableModule); ok {
commonData.IsStubsModule = st.IsStubsModule()
}
if mm, ok := m.module.(interface{ BaseModuleName() string }); ok {
commonData.BaseModuleName = mm.BaseModuleName()
}
SetProvider(ctx, CommonModuleInfoProvider, &commonData)
if p, ok := m.module.(PrebuiltInterface); ok && p.Prebuilt() != nil {
SetProvider(ctx, PrebuiltModuleInfoProvider, PrebuiltModuleInfo{
SourceExists: p.Prebuilt().SourceExists(),
UsePrebuilt: p.Prebuilt().UsePrebuilt(),
})
}
if h, ok := m.module.(HostToolProvider); ok {
SetProvider(ctx, HostToolProviderInfoProvider, HostToolProviderInfo{
HostToolPath: h.HostToolPath()})
}
if p, ok := m.module.(AndroidMkProviderInfoProducer); ok && !commonData.SkipAndroidMkProcessing {
SetProvider(ctx, AndroidMkInfoProvider, p.PrepareAndroidMKProviderInfo(ctx.Config()))
}
if s, ok := m.module.(SourceFileGenerator); ok {
SetProvider(ctx, GeneratedSourceInfoProvider, GeneratedSourceInfo{
GeneratedSourceFiles: s.GeneratedSourceFiles(),
GeneratedHeaderDirs: s.GeneratedHeaderDirs(),
GeneratedDeps: s.GeneratedDeps(),
})
}
if m.Enabled(ctx) {
if v, ok := m.module.(ModuleMakeVarsProvider); ok {
SetProvider(ctx, ModuleMakeVarsInfoProvider, v.MakeVars(ctx))
}
if am, ok := m.module.(AndroidMkDataProvider); ok {
SetProvider(ctx, AndroidMkDataInfoProvider, AndroidMkDataInfo{
Class: am.AndroidMk().Class,
})
}
}
m.module.CleanupAfterBuildActions()
}
func (m *ModuleBase) CleanupAfterBuildActions() {}
func SetJarJarPrefixHandler(handler func(ModuleContext)) {
if jarJarPrefixHandler != nil {
panic("jarJarPrefixHandler already set")
}
jarJarPrefixHandler = handler
}
func (m *ModuleBase) moduleInfoRegisterName(ctx ModuleContext, subName string) string {
name := m.BaseModuleName()
prefix := ""
if ctx.Host() {
if ctx.Os() != ctx.Config().BuildOS {
prefix = "host_cross_"
}
}
suffix := ""
arches := slices.Clone(ctx.Config().Targets[ctx.Os()])
arches = slices.DeleteFunc(arches, func(target Target) bool {
return target.NativeBridge != ctx.Target().NativeBridge
})
if len(arches) > 0 && ctx.Arch().ArchType != arches[0].Arch.ArchType && ctx.Arch().ArchType != Common {
if ctx.Arch().ArchType.Multilib == "lib32" {
suffix = "_32"
} else {
suffix = "_64"
}
}
return prefix + name + subName + suffix
}
func (m *ModuleBase) moduleInfoVariant(ctx ModuleContext) string {
variant := "DEVICE"
if ctx.Host() {
if ctx.Os() != ctx.Config().BuildOS {
variant = "HOST_CROSS"
} else {
variant = "HOST"
}
}
return variant
}
// Check the supplied dist structure to make sure that it is valid.
//
// property - the base property, e.g. dist or dists[1], which is combined with the
// name of the nested property to produce the full property, e.g. dist.dest or
// dists[1].dir.
func checkDistProperties(ctx *moduleContext, property string, dist *Dist) {
if dist.Dest != nil {
_, err := validateSafePath(*dist.Dest)
if err != nil {
ctx.PropertyErrorf(property+".dest", "%s", err.Error())
}
}
if dist.Dir != nil {
_, err := validateSafePath(*dist.Dir)
if err != nil {
ctx.PropertyErrorf(property+".dir", "%s", err.Error())
}
}
if dist.Suffix != nil {
if strings.Contains(*dist.Suffix, "/") {
ctx.PropertyErrorf(property+".suffix", "Suffix may not contain a '/' character.")
}
}
}
// katiInstall stores a request from Soong to Make to create an install rule.
type katiInstall struct {
from Path
to InstallPath
implicitDeps Paths
orderOnlyDeps Paths
executable bool
extraFiles *extraFilesZip
absFrom string
}
type katiInstallGob struct {
From Path
To InstallPath
ImplicitDeps Paths
OrderOnlyDeps Paths
Executable bool
ExtraFiles *extraFilesZip
AbsFrom string
}
func (k *katiInstall) ToGob() *katiInstallGob {
return &katiInstallGob{
From: k.from,
To: k.to,
ImplicitDeps: k.implicitDeps,
OrderOnlyDeps: k.orderOnlyDeps,
Executable: k.executable,
ExtraFiles: k.extraFiles,
AbsFrom: k.absFrom,
}
}
func (k *katiInstall) FromGob(data *katiInstallGob) {
k.from = data.From
k.to = data.To
k.implicitDeps = data.ImplicitDeps
k.orderOnlyDeps = data.OrderOnlyDeps
k.executable = data.Executable
k.extraFiles = data.ExtraFiles
k.absFrom = data.AbsFrom
}
func (k *katiInstall) GobEncode() ([]byte, error) {
return gobtools.CustomGobEncode[katiInstallGob](k)
}
func (k *katiInstall) GobDecode(data []byte) error {
return gobtools.CustomGobDecode[katiInstallGob](data, k)
}
type extraFilesZip struct {
zip Path
dir InstallPath
}
type extraFilesZipGob struct {
Zip Path
Dir InstallPath
}
func (e *extraFilesZip) ToGob() *extraFilesZipGob {
return &extraFilesZipGob{
Zip: e.zip,
Dir: e.dir,
}
}
func (e *extraFilesZip) FromGob(data *extraFilesZipGob) {
e.zip = data.Zip
e.dir = data.Dir
}
func (e *extraFilesZip) GobEncode() ([]byte, error) {
return gobtools.CustomGobEncode[extraFilesZipGob](e)
}
func (e *extraFilesZip) GobDecode(data []byte) error {
return gobtools.CustomGobDecode[extraFilesZipGob](data, e)
}
type katiInstalls []katiInstall
// BuiltInstalled returns the katiInstalls in the form used by $(call copy-many-files) in Make, a
// space separated list of from:to tuples.
func (installs katiInstalls) BuiltInstalled() string {
sb := strings.Builder{}
for i, install := range installs {
if i != 0 {
sb.WriteRune(' ')
}
sb.WriteString(install.from.String())
sb.WriteRune(':')
sb.WriteString(install.to.String())
}
return sb.String()
}
// InstallPaths returns the install path of each entry.
func (installs katiInstalls) InstallPaths() InstallPaths {
paths := make(InstallPaths, 0, len(installs))
for _, install := range installs {
paths = append(paths, install.to)
}
return paths
}
// Makes this module a platform module, i.e. not specific to soc, device,
// product, or system_ext.
func (m *ModuleBase) MakeAsPlatform() {
m.commonProperties.Vendor = boolPtr(false)
m.commonProperties.Proprietary = boolPtr(false)
m.commonProperties.Soc_specific = boolPtr(false)
m.commonProperties.Product_specific = boolPtr(false)
m.commonProperties.System_ext_specific = boolPtr(false)
}
func (m *ModuleBase) MakeAsSystemExt() {
m.commonProperties.Vendor = boolPtr(false)
m.commonProperties.Proprietary = boolPtr(false)
m.commonProperties.Soc_specific = boolPtr(false)
m.commonProperties.Product_specific = boolPtr(false)
m.commonProperties.System_ext_specific = boolPtr(true)
}
// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
func (m *ModuleBase) IsNativeBridgeSupported() bool {
return proptools.Bool(m.commonProperties.Native_bridge_supported)
}
func (m *ModuleBase) DecodeMultilib(ctx ConfigContext) (string, string) {
return decodeMultilib(ctx, m)
}
func (m *ModuleBase) Overrides() []string {
return m.commonProperties.Overrides
}
func (m *ModuleBase) UseGenericConfig() bool {
return proptools.Bool(m.commonProperties.Use_generic_config)
}
type ConfigContext interface {
Config() Config
}
type ConfigurableEvaluatorContext interface {
OtherModuleProviderContext
Config() Config
OtherModulePropertyErrorf(module Module, property string, fmt string, args ...interface{})
HasMutatorFinished(mutatorName string) bool
}
type configurationEvalutor struct {
ctx ConfigurableEvaluatorContext
m Module
}
func (m *ModuleBase) ConfigurableEvaluator(ctx ConfigurableEvaluatorContext) proptools.ConfigurableEvaluator {
return configurationEvalutor{
ctx: ctx,
m: m.module,
}
}
func (e configurationEvalutor) PropertyErrorf(property string, fmt string, args ...interface{}) {
e.ctx.OtherModulePropertyErrorf(e.m, property, fmt, args...)
}
func (e configurationEvalutor) EvaluateConfiguration(condition proptools.ConfigurableCondition, property string) proptools.ConfigurableValue {
ctx := e.ctx
m := e.m
if !ctx.HasMutatorFinished("defaults") {
ctx.OtherModulePropertyErrorf(m, property, "Cannot evaluate configurable property before the defaults mutator has run")
return proptools.ConfigurableValueUndefined()
}
switch condition.FunctionName() {
case "release_flag":
if condition.NumArgs() != 1 {
ctx.OtherModulePropertyErrorf(m, property, "release_flag requires 1 argument, found %d", condition.NumArgs())
return proptools.ConfigurableValueUndefined()
}
if ty, ok := ctx.Config().productVariables.BuildFlagTypes[condition.Arg(0)]; ok {
v := ctx.Config().productVariables.BuildFlags[condition.Arg(0)]
switch ty {
case "unspecified", "obsolete":
return proptools.ConfigurableValueUndefined()
case "string":
return proptools.ConfigurableValueString(v)
case "bool":
return proptools.ConfigurableValueBool(v == "true")
default:
panic("unhandled release flag type: " + ty)
}
}
return proptools.ConfigurableValueUndefined()
case "product_variable":
if condition.NumArgs() != 1 {
ctx.OtherModulePropertyErrorf(m, property, "product_variable requires 1 argument, found %d", condition.NumArgs())
return proptools.ConfigurableValueUndefined()
}
variable := condition.Arg(0)
switch variable {
case "build_from_text_stub":
return proptools.ConfigurableValueBool(ctx.Config().BuildFromTextStub())
case "debuggable":
return proptools.ConfigurableValueBool(ctx.Config().Debuggable())
case "eng":
return proptools.ConfigurableValueBool(ctx.Config().Eng())
case "use_debug_art":
// TODO(b/234351700): Remove once ART does not have separated debug APEX
return proptools.ConfigurableValueBool(ctx.Config().UseDebugArt())
case "selinux_ignore_neverallows":
return proptools.ConfigurableValueBool(ctx.Config().SelinuxIgnoreNeverallows())
case "always_use_prebuilt_sdks":
return proptools.ConfigurableValueBool(ctx.Config().AlwaysUsePrebuiltSdks())
default:
// TODO(b/323382414): Might add these on a case-by-case basis
ctx.OtherModulePropertyErrorf(m, property, fmt.Sprintf("TODO(b/323382414): Product variable %q is not yet supported in selects", variable))
return proptools.ConfigurableValueUndefined()
}
case "soong_config_variable":
if condition.NumArgs() != 2 {
ctx.OtherModulePropertyErrorf(m, property, "soong_config_variable requires 2 arguments, found %d", condition.NumArgs())
return proptools.ConfigurableValueUndefined()
}
namespace := condition.Arg(0)
variable := condition.Arg(1)
if n, ok := ctx.Config().productVariables.VendorVars[namespace]; ok {
if v, ok := n[variable]; ok {
ty := ""
if namespaces, ok := ctx.Config().productVariables.VendorVarTypes[namespace]; ok {
ty = namespaces[variable]
}
switch ty {
case "":
// strings are the default, we don't bother writing them to the soong variables json file
return proptools.ConfigurableValueString(v)
case "bool":
return proptools.ConfigurableValueBool(v == "true")
case "int":
i, err := strconv.ParseInt(v, 10, 64)
if err != nil {
ctx.OtherModulePropertyErrorf(m, property, "integer soong_config_variable was not an int: %q", v)
return proptools.ConfigurableValueUndefined()
}
return proptools.ConfigurableValueInt(i)
case "string_list":
return proptools.ConfigurableValueStringList(strings.Split(v, " "))
default:
panic("unhandled soong config variable type: " + ty)
}
}
}
return proptools.ConfigurableValueUndefined()
case "arch":
if condition.NumArgs() != 0 {
ctx.OtherModulePropertyErrorf(m, property, "arch requires no arguments, found %d", condition.NumArgs())
return proptools.ConfigurableValueUndefined()
}
if !m.base().ArchReady() {
ctx.OtherModulePropertyErrorf(m, property, "A select on arch was attempted before the arch mutator ran")
return proptools.ConfigurableValueUndefined()
}
return proptools.ConfigurableValueString(m.base().Arch().ArchType.Name)
case "os":
if condition.NumArgs() != 0 {
ctx.OtherModulePropertyErrorf(m, property, "os requires no arguments, found %d", condition.NumArgs())
return proptools.ConfigurableValueUndefined()
}
// the arch mutator runs after the os mutator, we can just use this to enforce that os is ready.
if !m.base().ArchReady() {
ctx.OtherModulePropertyErrorf(m, property, "A select on os was attempted before the arch mutator ran (arch runs after os, we use it to lazily detect that os is ready)")
return proptools.ConfigurableValueUndefined()
}
return proptools.ConfigurableValueString(m.base().Os().Name)
case "boolean_var_for_testing":
// We currently don't have any other boolean variables (we should add support for typing
// the soong config variables), so add this fake one for testing the boolean select
// functionality.
if condition.NumArgs() != 0 {
ctx.OtherModulePropertyErrorf(m, property, "boolean_var_for_testing requires 0 arguments, found %d", condition.NumArgs())
return proptools.ConfigurableValueUndefined()
}
if n, ok := ctx.Config().productVariables.VendorVars["boolean_var"]; ok {
if v, ok := n["for_testing"]; ok {
switch v {
case "true":
return proptools.ConfigurableValueBool(true)
case "false":
return proptools.ConfigurableValueBool(false)
default:
ctx.OtherModulePropertyErrorf(m, property, "testing:my_boolean_var can only be true or false, found %q", v)
}
}
}
return proptools.ConfigurableValueUndefined()
default:
ctx.OtherModulePropertyErrorf(m, property, "Unknown select condition %s", condition.FunctionName)
return proptools.ConfigurableValueUndefined()
}
}
// ModuleNameWithPossibleOverride returns the name of the OverrideModule that overrides the current
// variant of this OverridableModule, or ctx.ModuleName() if this module is not an OverridableModule
// or if this variant is not overridden.
func ModuleNameWithPossibleOverride(ctx BaseModuleContext) string {
if overridable, ok := ctx.Module().(OverridableModule); ok {
if o := overridable.GetOverriddenBy(); o != "" {
return o
}
}
return ctx.ModuleName()
}
// SrcIsModule decodes module references in the format ":unqualified-name" or "//namespace:name"
// into the module name, or empty string if the input was not a module reference.
func SrcIsModule(s string) (module string) {
if len(s) > 1 {
if s[0] == ':' {
module = s[1:]
if !isUnqualifiedModuleName(module) {
// The module name should be unqualified but is not so do not treat it as a module.
module = ""
}
} else if s[0] == '/' && s[1] == '/' {
module = s
}
}
return module
}
// SrcIsModuleWithTag decodes module references in the format ":unqualified-name{.tag}" or
// "//namespace:name{.tag}" into the module name and tag, ":unqualified-name" or "//namespace:name"
// into the module name and an empty string for the tag, or empty strings if the input was not a
// module reference.
func SrcIsModuleWithTag(s string) (module, tag string) {
if len(s) > 1 {
if s[0] == ':' {
module = s[1:]
} else if s[0] == '/' && s[1] == '/' {
module = s
}
if module != "" {
if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
if module[len(module)-1] == '}' {
tag = module[tagStart+1 : len(module)-1]
module = module[:tagStart]
}
}
if s[0] == ':' && !isUnqualifiedModuleName(module) {
// The module name should be unqualified but is not so do not treat it as a module.
module = ""
tag = ""
}
}
}
return module, tag
}
// isUnqualifiedModuleName makes sure that the supplied module is an unqualified module name, i.e.
// does not contain any /.
func isUnqualifiedModuleName(module string) bool {
return strings.IndexByte(module, '/') == -1
}
// sourceOrOutputDependencyTag is the dependency tag added automatically by pathDepsMutator for any
// module reference in a property annotated with `android:"path"` or passed to ExtractSourceDeps
// or ExtractSourcesDeps.
//
// If uniquely identifies the dependency that was added as it contains both the module name used to
// add the dependency as well as the tag. That makes it very simple to find the matching dependency
// in GetModuleFromPathDep as all it needs to do is find the dependency whose tag matches the tag
// used to add it. It does not need to check that the module name as returned by one of
// Module.Name(), BaseModuleContext.OtherModuleName() or ModuleBase.BaseModuleName() matches the
// name supplied in the tag. That means it does not need to handle differences in module names
// caused by prebuilt_ prefix, or fully qualified module names.
type sourceOrOutputDependencyTag struct {
blueprint.BaseDependencyTag
AlwaysPropagateAconfigValidationDependencyTag
// The name of the module.
moduleName string
// The tag that will be used to get the specific output file(s).
tag string
}
func sourceOrOutputDepTag(moduleName, tag string) blueprint.DependencyTag {
return sourceOrOutputDependencyTag{moduleName: moduleName, tag: tag}
}
// IsSourceDepTagWithOutputTag returns true if the supplied blueprint.DependencyTag is one that was
// used to add dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for
// properties tagged with `android:"path"` AND it was added using a module reference of
// :moduleName{outputTag}.
func IsSourceDepTagWithOutputTag(depTag blueprint.DependencyTag, outputTag string) bool {
t, ok := depTag.(sourceOrOutputDependencyTag)
return ok && t.tag == outputTag
}
// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
// using ":module" syntax, if any.
//
// Deprecated: tag the property with `android:"path"` instead.
func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
set := make(map[string]bool)
for _, s := range srcFiles {
if m, t := SrcIsModuleWithTag(s); m != "" {
if _, found := set[s]; found {
ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
} else {
set[s] = true
ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m)
}
}
}
}
// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
// using ":module" syntax, if any.
//
// Deprecated: tag the property with `android:"path"` instead.
func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
if s != nil {
if m, t := SrcIsModuleWithTag(*s); m != "" {
ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m)
}
}
}
// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
// using the ":module" syntax and provides a list of paths to be used as if they were listed in the property.
type SourceFileProducer interface {
Srcs() Paths
}
// OutputFilesForModule returns the output file paths with the given tag. On error, including if the
// module produced zero paths, it reports errors to the ctx and returns nil.
func OutputFilesForModule(ctx PathContext, module Module, tag string) Paths {
paths, err := outputFilesForModule(ctx, module, tag)
if err != nil {
reportPathError(ctx, err)
return nil
}
return paths
}
// OutputFileForModule returns the output file paths with the given tag. On error, including if the
// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
// TODO(b/397766191): Change the signature to take ModuleProxy
// Please only access the module's internal data through providers.
func OutputFileForModule(ctx PathContext, module Module, tag string) Path {
paths, err := outputFilesForModule(ctx, module, tag)
if err != nil {
reportPathError(ctx, err)
return nil
}
if len(paths) == 0 {
type addMissingDependenciesIntf interface {
AddMissingDependencies([]string)
OtherModuleName(blueprint.Module) string
}
if mctx, ok := ctx.(addMissingDependenciesIntf); ok && ctx.Config().AllowMissingDependencies() {
mctx.AddMissingDependencies([]string{mctx.OtherModuleName(module)})
} else {
ReportPathErrorf(ctx, "failed to get output files from module %q", pathContextName(ctx, module))
}
// Return a fake output file to avoid nil dereferences of Path objects later.
// This should never get used for an actual build as the error or missing
// dependency has already been reported.
p, err := pathForSource(ctx, filepath.Join("missing_output_file", pathContextName(ctx, module)))
if err != nil {
reportPathError(ctx, err)
return nil
}
return p
}
if len(paths) > 1 {
ReportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
pathContextName(ctx, module))
}
return paths[0]
}
type OutputFilesProviderModuleContext interface {
OtherModuleProviderContext
Module() Module
GetOutputFiles() OutputFilesInfo
}
// TODO(b/397766191): Change the signature to take ModuleProxy
// Please only access the module's internal data through providers.
func outputFilesForModule(ctx PathContext, module Module, tag string) (Paths, error) {
outputFilesFromProvider, err := outputFilesForModuleFromProvider(ctx, module, tag)
if outputFilesFromProvider != nil || err != OutputFilesProviderNotSet {
return outputFilesFromProvider, err
}
if octx, ok := ctx.(OutputFilesProviderModuleContext); ok {
if EqualModules(octx.Module(), module) {
// It is the current module, we can access the srcs through interface
if sourceFileProducer, ok := module.(SourceFileProducer); ok {
return sourceFileProducer.Srcs(), nil
}
} else if sourceFiles, ok := OtherModuleProvider(octx, module, SourceFilesInfoProvider); ok {
if tag != "" {
return nil, fmt.Errorf("module %q is a SourceFileProducer, which does not support tag %q", pathContextName(ctx, module), tag)
}
paths := sourceFiles.Srcs
return paths, nil
}
}
return nil, fmt.Errorf("module %q is not a SourceFileProducer or having valid output file for tag %q", pathContextName(ctx, module), tag)
}
// This method uses OutputFilesProvider for output files
// *inter-module-communication*.
// If mctx module is the same as the param module the output files are obtained
// from outputFiles property of module base, to avoid both setting and
// reading OutputFilesProvider before GenerateBuildActions is finished.
// If a module doesn't have the OutputFilesProvider, nil is returned.
func outputFilesForModuleFromProvider(ctx PathContext, module Module, tag string) (Paths, error) {
var outputFiles OutputFilesInfo
if mctx, isMctx := ctx.(OutputFilesProviderModuleContext); isMctx {
if !EqualModules(mctx.Module(), module) {
outputFiles, _ = OtherModuleProvider(mctx, module, OutputFilesProvider)
} else {
outputFiles = mctx.GetOutputFiles()
}
} else if cta, isCta := ctx.(*singletonContextAdaptor); isCta {
outputFiles, _ = OtherModuleProvider(cta, module, OutputFilesProvider)
} else {
return nil, fmt.Errorf("unsupported context %q in method outputFilesForModuleFromProvider", reflect.TypeOf(ctx))
}
if outputFiles.isEmpty() {
return nil, OutputFilesProviderNotSet
}
if tag == "" {
return outputFiles.DefaultOutputFiles, nil
} else if taggedOutputFiles, hasTag := outputFiles.TaggedOutputFiles[tag]; hasTag {
return taggedOutputFiles, nil
} else {
return nil, UnsupportedOutputTagError{
tag: tag,
}
}
}
func (o OutputFilesInfo) isEmpty() bool {
return o.DefaultOutputFiles == nil && o.TaggedOutputFiles == nil
}
type OutputFilesInfo struct {
// default output files when tag is an empty string ""
DefaultOutputFiles Paths
// the corresponding output files for given tags
TaggedOutputFiles map[string]Paths
}
var OutputFilesProvider = blueprint.NewProvider[OutputFilesInfo]()
type UnsupportedOutputTagError struct {
tag string
}
func (u UnsupportedOutputTagError) Error() string {
return fmt.Sprintf("unsupported output tag %q", u.tag)
}
func (u UnsupportedOutputTagError) Is(e error) bool {
_, ok := e.(UnsupportedOutputTagError)
return ok
}
var _ error = UnsupportedOutputTagError{}
// This is used to mark the case where OutputFilesProvider is not set on some modules.
var OutputFilesProviderNotSet = fmt.Errorf("No output files from provider")
var ErrUnsupportedOutputTag = UnsupportedOutputTagError{}
// Modules can implement HostToolProvider and return a valid OptionalPath from HostToolPath() to
// specify that they can be used as a tool by a genrule module.
type HostToolProvider interface {
Module
// HostToolPath returns the path to the host tool for the module if it is one, or an invalid
// OptionalPath.
HostToolPath() OptionalPath
}
func init() {
RegisterParallelSingletonType("buildtarget", BuildTargetSingleton)
}
func BuildTargetSingleton() Singleton {
return &buildTargetSingleton{}
}
func parentDir(dir string) string {
dir, _ = filepath.Split(dir)
return filepath.Clean(dir)
}
type buildTargetSingleton struct{}
func AddAncestors(ctx SingletonContext, dirMap map[string]Paths, mmName func(string) string) ([]string, []string) {
// Ensure ancestor directories are in dirMap
// Make directories build their direct subdirectories
// Returns a slice of all directories and a slice of top-level directories.
dirs := SortedKeys(dirMap)
for _, dir := range dirs {
dir := parentDir(dir)
for dir != "." && dir != "/" {
if _, exists := dirMap[dir]; exists {
break
}
dirMap[dir] = nil
dir = parentDir(dir)
}
}
dirs = SortedKeys(dirMap)
var topDirs []string
for _, dir := range dirs {
p := parentDir(dir)
if p != "." && p != "/" {
dirMap[p] = append(dirMap[p], PathForPhony(ctx, mmName(dir)))
} else if dir != "." && dir != "/" && dir != "" {
topDirs = append(topDirs, dir)
}
}
return SortedKeys(dirMap), topDirs
}
func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
var checkbuildDeps Paths
// Create a top level partialcompileclean target for modules to add dependencies to.
ctx.Phony("partialcompileclean")
mmTarget := func(dir string) string {
return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
}
modulesInDir := make(map[string]Paths)
ctx.VisitAllModuleProxies(func(module ModuleProxy) {
info := OtherModuleProviderOrDefault(ctx, module, ModuleBuildTargetsProvider)
if info.CheckbuildTarget != nil {
checkbuildDeps = append(checkbuildDeps, info.CheckbuildTarget)
modulesInDir[info.BlueprintDir] = append(modulesInDir[info.BlueprintDir], info.CheckbuildTarget)
}
if info.InstallTarget != nil {
modulesInDir[info.BlueprintDir] = append(modulesInDir[info.BlueprintDir], info.InstallTarget)
}
})
suffix := ""
if ctx.Config().KatiEnabled() {
suffix = "-soong"
}
// Create a top-level checkbuild target that depends on all modules
ctx.Phony("checkbuild"+suffix, checkbuildDeps...)
// Make will generate the MODULES-IN-* targets
if ctx.Config().KatiEnabled() {
return
}
dirs, _ := AddAncestors(ctx, modulesInDir, mmTarget)
// Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
// depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
// files.
for _, dir := range dirs {
ctx.Phony(mmTarget(dir), modulesInDir[dir]...)
}
// Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
type osAndCross struct {
os OsType
hostCross bool
}
osDeps := map[osAndCross]Paths{}
ctx.VisitAllModules(func(module Module) {
if module.Enabled(ctx) {
key := osAndCross{os: module.Target().Os, hostCross: module.Target().HostCross}
osDeps[key] = append(osDeps[key], OtherModuleProviderOrDefault(ctx, module, InstallFilesProvider).CheckbuildFiles...)
}
})
osClass := make(map[string]Paths)
for key, deps := range osDeps {
var className string
switch key.os.Class {
case Host:
if key.hostCross {
className = "host-cross"
} else {
className = "host"
}
case Device:
className = "target"
default:
continue
}
name := className + "-" + key.os.Name
osClass[className] = append(osClass[className], PathForPhony(ctx, name))
ctx.Phony(name, deps...)
}
// Wrap those into host|host-cross|target phony rules
for _, class := range SortedKeys(osClass) {
ctx.Phony(class, osClass[class]...)
}
}
// Collect information for opening IDE project files in java/jdeps.go.
type IDEInfo interface {
IDEInfo(ctx BaseModuleContext, ideInfo *IdeInfo)
BaseModuleName() string
}
// Collect information for opening IDE project files in java/jdeps.go.
type IdeInfo struct {
BaseModuleName string `json:"-"`
Deps []string `json:"dependencies,omitempty"`
Srcs []string `json:"srcs,omitempty"`
Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
Jarjar_rules []string `json:"jarjar_rules,omitempty"`
Jars []string `json:"jars,omitempty"`
Classes []string `json:"class,omitempty"`
Installed_paths []string `json:"installed,omitempty"`
SrcJars []string `json:"srcjars,omitempty"`
Paths []string `json:"path,omitempty"`
Static_libs []string `json:"static_libs,omitempty"`
Libs []string `json:"libs,omitempty"`
}
// Merge merges two IdeInfos and produces a new one, leaving the origional unchanged
func (i IdeInfo) Merge(other IdeInfo) IdeInfo {
return IdeInfo{
Deps: mergeStringLists(i.Deps, other.Deps),
Srcs: mergeStringLists(i.Srcs, other.Srcs),
Aidl_include_dirs: mergeStringLists(i.Aidl_include_dirs, other.Aidl_include_dirs),
Jarjar_rules: mergeStringLists(i.Jarjar_rules, other.Jarjar_rules),
Jars: mergeStringLists(i.Jars, other.Jars),
Classes: mergeStringLists(i.Classes, other.Classes),
Installed_paths: mergeStringLists(i.Installed_paths, other.Installed_paths),
SrcJars: mergeStringLists(i.SrcJars, other.SrcJars),
Paths: mergeStringLists(i.Paths, other.Paths),
Static_libs: mergeStringLists(i.Static_libs, other.Static_libs),
Libs: mergeStringLists(i.Libs, other.Libs),
}
}
// mergeStringLists appends the two string lists together and returns a new string list,
// leaving the originals unchanged. Duplicate strings will be deduplicated.
func mergeStringLists(a, b []string) []string {
return FirstUniqueStrings(Concat(a, b))
}
var IdeInfoProviderKey = blueprint.NewProvider[IdeInfo]()
func CheckBlueprintSyntax(ctx BaseModuleContext, filename string, contents string) []error {
bpctx := ctx.blueprintBaseModuleContext()
return blueprint.CheckBlueprintSyntax(bpctx.ModuleFactories(), filename, contents)
}
|