blob: 2720a0f40243b07373546fe66f9d4400f6ac7617 [file] [log] [blame] [view]
Dan Willemsen77338622017-11-08 16:39:18 -08001# Build System Changes for Android.mk Writers
2
Dan Willemsen66d21d42020-01-27 19:26:02 -08003## COPY_HEADERS usage now produces warnings {#copy_headers}
4
5We've considered `BUILD_COPY_HEADERS`/`LOCAL_COPY_HEADERS` to be deprecated for
6a long time, and the places where it's been able to be used have shrinked over
7the last several releases. Equivalent functionality is not available in Soong.
8
9See the [build/soong/docs/best_practices.md#headers] for more information about
10how best to handle headers in Android.
11
Dan Willemsen2bfffb92020-01-14 10:56:53 -080012## `m4` is not available on `$PATH`
13
14There is a prebuilt of it available in prebuilts/build-tools, and a make
15variable `M4` that contains the path.
16
17Beyond the direct usage, whenever you use bison or flex directly, they call m4
18behind the scene, so you must set the M4 environment variable (and depend upon
19it for incremental build correctness):
20
21```
22$(intermediates)/foo.c: .KATI_IMPLICIT_OUTPUTS := $(intermediates)/foo.h
23$(intermediates)/foo.c: $(LOCAL_PATH)/foo.y $(M4) $(BISON) $(BISON_DATA)
24 M4=$(M4) $(BISON) ...
25```
26
Dan Willemsen26076252020-01-02 20:08:10 -080027## Rules executed within limited environment
28
29With `ALLOW_NINJA_ENV=false` (soon to be the default), ninja, and all the
30rules/actions executed within it will only have access to a limited number of
31environment variables. Ninja does not track when environment variables change
32in order to trigger rebuilds, so changing behavior based on arbitrary variables
33is not safe with incremental builds.
34
35Kati and Soong can safely use environment variables, so the expectation is that
36you'd embed any environment variables that you need to use within the command
37line generated by those tools. See the [export section](#export_keyword) below
38for examples.
39
40For a temporary workaround, you can set `ALLOW_NINJA_ENV=true` in your
41environment to restore the previous behavior, or set
42`BUILD_BROKEN_NINJA_USES_ENV_VAR := <var> <var2> ...` in your `BoardConfig.mk`
43to allow specific variables to be passed through until you've fixed the rules.
44
Dan Willemsen0cb422f2019-11-25 17:51:18 -080045## LOCAL_C_INCLUDES outside the source/output trees are an error {#BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS}
46
47Include directories are expected to be within the source tree (or in the output
48directory, generated during the build). This has been checked in some form
49since Oreo, but now has better checks.
50
51There's now a `BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS` variable, that when set, will
52turn these errors into warnings temporarily. I don't expect this to last more
53than a release, since they're fairly easy to clean up.
54
55Neither of these cases are supported by Soong, and will produce errors when
56converting your module.
57
58### Absolute paths
59
60This has been checked since Oreo. The common reason to hit this is because a
61makefile is calculating a path, and ran abspath/realpath/etc. This is a problem
62because it makes your build non-reproducible. It's very unlikely that your
63source path is the same on every machine.
64
65### Using `../` to leave the source/output directories
66
67This is the new check that has been added. In every case I've found, this has
68been a mistake in the Android.mk -- assuming that `LOCAL_C_INCLUDES` (which is
69relative to the top of the source tree) acts like `LOCAL_SRC_FILES` (which is
70relative to `LOCAL_PATH`).
71
72Since this usually isn't a valid path, you can almost always just remove the
73offending line.
74
75
Dan Willemsen26076252020-01-02 20:08:10 -080076## `BOARD_HAL_STATIC_LIBRARIES` and `LOCAL_HAL_STATIC_LIBRARIES` are obsolete {#BOARD_HAL_STATIC_LIBRARIES}
Yifan Hong88adfc62019-10-11 15:52:44 -070077
78Define proper HIDL / Stable AIDL HAL instead.
79
80* For libhealthd, use health HAL. See instructions for implementing
81 health HAL:
82
83 * [hardware/interfaces/health/2.1/README.md] for health 2.1 HAL (recommended)
84 * [hardware/interfaces/health/1.0/README.md] for health 1.0 HAL
85
86* For libdumpstate, use at least Dumpstate HAL 1.0.
87
Tao Bao84f88a42019-05-28 16:30:18 -070088## PRODUCT_STATIC_BOOT_CONTROL_HAL is obsolete {#PRODUCT_STATIC_BOOT_CONTROL_HAL}
89
90`PRODUCT_STATIC_BOOT_CONTROL_HAL` was the workaround to allow sideloading with
91statically linked boot control HAL, before shared library HALs were supported
92under recovery. Android Q has added such support (HALs will be loaded in
93passthrough mode), and the workarounds are being removed. Targets should build
94and install the recovery variant of boot control HAL modules into recovery
95image, similar to the ones installed for normal boot. See the change to
96crosshatch for example of this:
97
98* [device/google/crosshatch/bootctrl/Android.bp] for `bootctrl.sdm845` building
99 rules
100* [device/google/crosshatch/device.mk] for installing `bootctrl.sdm845.recovery`
101 and `android.hardware.boot@1.0-impl.recovery` into recovery image
102
103[device/google/crosshatch/bootctrl/Android.bp]: https://android.googlesource.com/device/google/crosshatch/+/master/bootctrl/Android.bp
104[device/google/crosshatch/device.mk]: https://android.googlesource.com/device/google/crosshatch/+/master/device.mk
105
Dan Willemsen695849e2019-04-17 12:25:09 -0700106## Deprecation of `BUILD_*` module types
107
108See [build/make/Deprecation.md](Deprecation.md) for the current status.
109
Dan Willemsen3d05a082019-02-22 23:06:03 +0000110## `PRODUCT_HOST_PACKAGES` split from `PRODUCT_PACKAGES` {#PRODUCT_HOST_PACKAGES}
111
112Previously, adding a module to `PRODUCT_PACKAGES` that supported both the host
113and the target (`host_supported` in Android.bp; two modules with the same name
114in Android.mk) would cause both to be built and installed. In many cases you
115only want either the host or target versions to be built/installed by default,
116and would be over-building with both. So `PRODUCT_PACKAGES` will be changing to
117just affect target modules, while `PRODUCT_HOST_PACKAGES` is being added for
118host modules.
119
120Functional differences between `PRODUCT_PACKAGES` and `PRODUCT_HOST_PACKAGES`:
121
122* `PRODUCT_HOST_PACKAGES` does not have `_ENG`/`_DEBUG` variants, as that's a
123 property of the target, not the host.
124* `PRODUCT_HOST_PACKAGES` does not support `LOCAL_MODULE_OVERRIDES`.
125* `PRODUCT_HOST_PACKAGES` requires listed modules to exist, and be host
126 modules. (Unless `ALLOW_MISSING_DEPENDENCIES` is set)
127
128This is still an active migration, so currently it still uses
129`PRODUCT_PACKAGES` to make installation decisions, but verifies that if we used
130`PRODUCT_HOST_PACKAGES`, it would trigger installation for all of the same host
131packages. This check ignores shared libraries, as those are not normally
132necessary in `PRODUCT_*PACKAGES`, and tended to be over-built (especially the
13332-bit variants).
134
135Future changes will switch installation decisions to `PRODUCT_HOST_PACKAGES`
136for host modules, error when there's a host-only module in `PRODUCT_PACKAGES`,
137and do some further cleanup where `LOCAL_REQUIRED_MODULES` are still merged
138between host and target modules with the same name.
139
Dan Willemsen46267cb2019-01-25 14:35:58 -0800140## `*.c.arm` / `*.cpp.arm` deprecation {#file_arm}
141
142In Android.mk files, you used to be able to change LOCAL_ARM_MODE for each
143source file by appending `.arm` to the end of the filename in
144`LOCAL_SRC_FILES`.
145
146Soong does not support this uncommonly used behavior, instead expecting those
147files to be split out into a separate static library that chooses `arm` over
148`thumb` for the entire library. This must now also be done in Android.mk files.
149
Dan Willemsenf2646902019-01-25 16:54:37 -0800150## Windows cross-compiles no longer supported in Android.mk
151
152Modules that build for Windows (our only `HOST_CROSS` OS currently) must now be
153defined in `Android.bp` files.
154
Dan Willemsene048f7e2019-02-09 18:58:36 -0800155## `LOCAL_MODULE_TAGS := eng debug` are obsolete {#LOCAL_MODULE_TAGS}
Dan Willemsen9569ddd2019-01-22 19:38:56 -0800156
Dan Willemsene048f7e2019-02-09 18:58:36 -0800157`LOCAL_MODULE_TAGS` value `eng` and `debug` are now obsolete. They allowed
Dan Willemsen9569ddd2019-01-22 19:38:56 -0800158modules to specify that they should always be installed on `-eng`, or `-eng`
159and `-userdebug` builds. This conflicted with the ability for products to
160specify which modules should be installed, effectively making it impossible to
161build a stripped down product configuration that did not include those modules.
162
163For the equivalent functionality, specify the modules in `PRODUCT_PACKAGES_ENG`
164or `PRODUCT_PACKAGES_DEBUG` in the appropriate product makefiles.
165
166Core android packages like `su` got added to the list in
167`build/make/target/product/base_system.mk`, but for device-specific modules
168there are often better base product makefiles to use instead.
169
Dan Willemsen06364282019-01-02 14:32:54 -0800170## `USER` deprecation {#USER}
171
172`USER` will soon be `nobody` in many cases due to the addition of a sandbox
173around the Android build. Most of the time you shouldn't need to know the
174identity of the user running the build, but if you do, it's available in the
175make variable `BUILD_USERNAME` for now.
176
177Similarly, the `hostname` tool will also be returning a more consistent value
178of `android-build`. The real value is available as `BUILD_HOSTNAME`.
179
Dan Willemsen6dbb33d2018-10-21 19:41:49 -0700180## `BUILD_NUMBER` removal from Android.mk {#BUILD_NUMBER}
181
182`BUILD_NUMBER` should not be used directly in Android.mk files, as it would
183trigger them to be re-read every time the `BUILD_NUMBER` changes (which it does
184on every build server build). If possible, just remove the use so that your
185builds are more reproducible. If you do need it, use `BUILD_NUMBER_FROM_FILE`:
186
187``` make
188$(LOCAL_BUILT_MODULE):
189 mytool --build_number $(BUILD_NUMBER_FROM_FILE) -o $@
190```
191
192That will expand out to a subshell that will read the current `BUILD_NUMBER`
193whenever it's run. It will not re-run your command if the build number has
194changed, so incremental builds will have the build number from the last time
195the particular output was rebuilt.
196
Dan Willemsen78c40be2018-10-17 16:50:49 -0700197## `DIST_DIR`, `dist_goal`, and `dist-for-goals` {#dist}
198
199`DIST_DIR` and `dist_goal` are no longer available when reading Android.mk
200files (or other build tasks). Always use `dist-for-goals` instead, which takes
201a PHONY goal, and a list of files to copy to `$DIST_DIR`. Whenever `dist` is
202specified, and the goal would be built (either explicitly on the command line,
203or as a dependency of something on the command line), that file will be copied
204into `$DIST_DIR`. For example,
205
206``` make
207$(call dist-for-goals,foo,bar/baz)
208```
209
210will copy `bar/baz` into `$DIST_DIR/baz` when `m foo dist` is run.
211
212#### Renames during copy
213
214Instead of specifying just a file, a destination name can be specified,
215including subdirectories:
216
217``` make
218$(call dist-for-goals,foo,bar/baz:logs/foo.log)
219```
220
221will copy `bar/baz` into `$DIST_DIR/logs/foo.log` when `m foo dist` is run.
222
Dan Willemsen5fb16a62018-09-04 16:23:14 -0700223## `.PHONY` rule enforcement {#phony_targets}
224
225There are several new warnings/errors meant to ensure the proper use of
226`.PHONY` targets in order to improve the speed and reliability of incremental
227builds.
228
229`.PHONY`-marked targets are often used as shortcuts to provide "friendly" names
230for real files to be built, but any target marked with `.PHONY` is also always
231considered dirty, needing to be rebuilt every build. This isn't a problem for
232aliases or one-off user-requested operations, but if real builds steps depend
233on a `.PHONY` target, it can get quite expensive for what should be a tiny
234build.
235
236``` make
237...mk:42: warning: PHONY target "out/.../foo" looks like a real file (contains a "/")
238```
239
240Between this warning and the next, we're requiring that `.PHONY` targets do not
241have "/" in them, and real file targets do have a "/". This makes it more
242obvious when reading makefiles what is happening, and will help the build
243system differentiate these in the future too.
244
245``` make
246...mk:42: warning: writing to readonly directory: "kernel-modules"
247```
248
249This warning will show up for one of two reasons:
250
2511. The target isn't intended to be a real file, and should be marked with
252 `.PHONY`. This would be the case for this example.
2532. The target is a real file, but it's outside the output directories. All
254 outputs from the build system should be within the output directory,
255 otherwise `m clean` is unable to clean the build, and future builds may not
256 work properly.
257
258``` make
259...mk:42: warning: real file "out/.../foo" depends on PHONY target "buildbins"
260```
261
262If the first target isn't intended to be a real file, then it should be marked
263with `.PHONY`, which will satisfy this warning. This isn't the case for this
264example, as we require `.PHONY` targets not to have '/' in them.
265
266If the second (PHONY) target is a real file, it may unnecessarily be marked
267with `.PHONY`.
268
269### `.PHONY` and calling other build systems
270
271One common pattern (mostly outside AOSP) that we've seen hit these warning is
272when building with external build systems (firmware, bootloader, kernel, etc).
273Those are often marked as `.PHONY` because the Android build system doesn't
274have enough dependencies to know when to run the other build system again
275during an incremental build.
276
277We recommend to build these outside of Android, and deliver prebuilts into the
278Android tree instead of decreasing the speed and reliability of the incremental
279Android build.
280
281In cases where that's not desired, to preserve the speed of Android
282incrementals, over-specifying dependencies is likely a better option than
283marking it with `.PHONY`:
284
285``` make
286out/target/.../zImage: $(sort $(shell find -L $(KERNEL_SRCDIR)))
287 ...
288```
289
290For reliability, many of these other build systems do not guarantee the same
291level of incremental build assurances as the Android Build is attempting to do
292-- without custom checks, Make doesn't rebuild objects when CFLAGS change, etc.
293In order to fix this, our recommendation is to do clean builds for each of
294these external build systems every time anything they rely on changes. For
295relatively smaller builds (like the kernel), this may be reasonable as long as
296you're not trying to actively debug the kernel.
297
298## `export` and `unexport` deprecation {#export_keyword}
Dan Willemsen8b9c3cc2018-02-27 02:15:32 -0800299
Dan Willemsen3a1072a2019-05-14 22:03:58 -0700300The `export` and `unexport` keywords are obsolete, and will throw errors when
301used.
Dan Willemsen8b9c3cc2018-02-27 02:15:32 -0800302
Dan Willemsen8b9c3cc2018-02-27 02:15:32 -0800303Device specific configuration should not be able to affect common core build
304steps -- we're looking at triggering build steps to be invalidated if the set
305of environment variables they can access changes. If device specific
306configuration is allowed to change those, switching devices with the same
307output directory could become significantly more expensive than it already can
308be.
309
Dan Willemsen3a1072a2019-05-14 22:03:58 -0700310If used during Android.mk files, and later tasks, it is increasingly likely
311that they are being used incorrectly. Attempting to change the environment for
312a single build step, and instead setting it for hundreds of thousands.
Dan Willemsen8b9c3cc2018-02-27 02:15:32 -0800313
314It is not recommended to just move the environment variable setting outside of
315the build (in vendorsetup.sh, or some other configuration script or wrapper).
316We expect to limit the environment variables that the build respects in the
317future, others will be cleared. (There will be methods to get custom variables
318into the build, just not to every build step)
319
320Instead, write the export commands into the rule command lines themselves:
321
322``` make
323$(intermediates)/generated_output.img:
324 rm -rf $@
325 export MY_ENV_A="$(MY_A)"; make ...
326```
327
328If you want to set many environment variables, and/or use them many times,
329write them out to a script and source the script:
330
331``` make
332envsh := $(intermediates)/env.sh
333$(envsh):
334 rm -rf $@
335 echo 'export MY_ENV_A="$(MY_A)"' >$@
336 echo 'export MY_ENV_B="$(MY_B)"' >>$@
337
338$(intermediates)/generated_output.img: PRIVATE_ENV := $(envsh)
339$(intermediates)/generated_output.img: $(envsh) a/b/c/package.sh
340 rm -rf $@
341 source $(PRIVATE_ENV); make ...
342 source $(PRIVATE_ENV); a/b/c/package.sh ...
343```
344
Dan Willemsen5f76fc02018-06-21 21:42:29 -0700345## Implicit make rules are obsolete {#implicit_rules}
Dan Willemsen62db0f02018-06-16 09:37:13 -0700346
347Implicit rules look something like the following:
348
349``` make
350$(TARGET_OUT_SHARED_LIBRARIES)/%_vendor.so: $(TARGET_OUT_SHARED_LIBRARIES)/%.so
351 ...
352
353%.o : %.foo
354 ...
355```
356
Dan Willemsen5f76fc02018-06-21 21:42:29 -0700357These can have wide ranging effects across unrelated modules, so they're now obsolete. Instead, use static pattern rules, which are similar, but explicitly match the specified outputs:
Dan Willemsen62db0f02018-06-16 09:37:13 -0700358
359``` make
360libs := $(foreach lib,libfoo libbar,$(TARGET_OUT_SHARED_LIBRARIES)/$(lib)_vendor.so)
361$(libs): %_vendor.so: %.so
362 ...
363
364files := $(wildcard $(LOCAL_PATH)/*.foo)
365gen := $(patsubst $(LOCAL_PATH)/%.foo,$(intermediates)/%.o,$(files))
366$(gen): %.o : %.foo
367 ...
368```
369
Dan Willemsenac926592018-06-11 22:28:00 -0700370## Removing '/' from Valid Module Names {#name_slash}
371
372The build system uses module names in path names in many places. Having an
373extra '/' or '../' being inserted can cause problems -- and not just build
374breaks, but stranger invalid behavior.
375
376In every case we've seen, the fix is relatively simple: move the directory into
377`LOCAL_MODULE_RELATIVE_PATH` (or `LOCAL_MODULE_PATH` if you're still using it).
378If this causes multiple modules to be named the same, use unique module names
379and `LOCAL_MODULE_STEM` to change the installed file name:
380
381``` make
382include $(CLEAR_VARS)
383LOCAL_MODULE := ver1/code.bin
384LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/firmware
385...
386include $(BUILD_PREBUILT)
387
388include $(CLEAR_VARS)
389LOCAL_MODULE := ver2/code.bin
390LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/firmware
391...
392include $(BUILD_PREBUILT)
393```
394
395Can be rewritten as:
396
397```
398include $(CLEAR_VARS)
399LOCAL_MODULE := ver1_code.bin
400LOCAL_MODULE_STEM := code.bin
401LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/firmware/ver1
402...
403include $(BUILD_PREBUILT)
404
405include $(CLEAR_VARS)
406LOCAL_MODULE := ver2_code.bin
407LOCAL_MODULE_STEM := code.bin
408LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/firmware/ver2
409...
410include $(BUILD_PREBUILT)
411```
412
413You just need to make sure that any other references (`PRODUCT_PACKAGES`,
414`LOCAL_REQUIRED_MODULES`, etc) are converted to the new names.
415
Dan Willemsenbbe6a022018-06-10 14:49:01 -0700416## Valid Module Names {#name}
417
418We've adopted lexical requirements very similar to [Bazel's
419requirements](https://docs.bazel.build/versions/master/build-ref.html#name) for
420target names. Valid characters are `a-z`, `A-Z`, `0-9`, and the special
Dan Willemsenac926592018-06-11 22:28:00 -0700421characters `_.+-=,@~`. This currently applies to `LOCAL_PACKAGE_NAME`,
Dan Willemsenbbe6a022018-06-10 14:49:01 -0700422`LOCAL_MODULE`, and `LOCAL_MODULE_SUFFIX`, and `LOCAL_MODULE_STEM*`.
423
424Many other characters already caused problems if you used them, so we don't
425expect this to have a large effect.
426
Dan Willemsen5039ef42018-05-18 11:00:17 -0700427## PATH Tools {#PATH_Tools}
428
429The build has started restricting the external host tools usable inside the
430build. This will help ensure that build results are reproducible across
431different machines, and catch mistakes before they become larger issues.
432
433To start with, this includes replacing the $PATH with our own directory of
434tools, mirroring that of the host PATH. The only difference so far is the
435removal of the host GCC tools. Anything that is not explicitly in the
436configuration as allowed will continue functioning, but will generate a log
437message. This is expected to become more restrictive over time.
438
439The configuration is located in build/soong/ui/build/paths/config.go, and
440contains all the common tools in use in many builds. Anything not in that list
441will currently print a warning in the `$OUT_DIR/soong.log` file, including the
442command and arguments used, and the process tree in order to help locate the
443usage.
444
445In order to fix any issues brought up by these checks, the best way to fix them
446is to use tools checked into the tree -- either as prebuilts, or building them
447as host tools during the build.
448
449As a temporary measure, you can set `TEMPORARY_DISABLE_PATH_RESTRICTIONS=true`
450in your environment to temporarily turn off the error checks and allow any tool
451to be used (with logging). Beware that GCC didn't work well with the interposer
452used for logging, so this may not help in all cases.
453
Dan Willemsen79fd6962017-11-28 22:32:05 -0800454## Deprecating / obsoleting envsetup.sh variables in Makefiles
Dan Willemsen77338622017-11-08 16:39:18 -0800455
456It is not required to source envsetup.sh before running a build. Many scripts,
457including a majority of our automated build systems, do not do so. Make will
458transparently make every environment variable available as a make variable.
459This means that relying on environment variables only set up in envsetup.sh will
460produce different output for local users and scripted users.
461
462Many of these variables also include absolute path names, which we'd like to
463keep out of the generated files, so that you don't need to do a full rebuild if
464you move the source tree.
465
466To fix this, we're marking the variables that are set in envsetup.sh as
467deprecated in the makefiles. This will trigger a warning every time one is read
Dan Willemsen79fd6962017-11-28 22:32:05 -0800468(or written) inside Kati. Once all the warnings have been removed for a
469particular variable, we'll switch it to obsolete, and any references will become
470errors.
Dan Willemsen77338622017-11-08 16:39:18 -0800471
472### envsetup.sh variables with make equivalents
473
474| instead of | use |
475|--------------------------------------------------------------|----------------------|
Yasuhiro Kubotacd301f62018-10-09 15:51:23 +0900476| OUT {#OUT} | PRODUCT_OUT |
Dan Willemsen77338622017-11-08 16:39:18 -0800477| ANDROID_HOST_OUT {#ANDROID_HOST_OUT} | HOST_OUT |
478| ANDROID_PRODUCT_OUT {#ANDROID_PRODUCT_OUT} | PRODUCT_OUT |
479| ANDROID_HOST_OUT_TESTCASES {#ANDROID_HOST_OUT_TESTCASES} | HOST_OUT_TESTCASES |
480| ANDROID_TARGET_OUT_TESTCASES {#ANDROID_TARGET_OUT_TESTCASES} | TARGET_OUT_TESTCASES |
481
482All of the make variables may be relative paths from the current directory, or
483absolute paths if the output directory was specified as an absolute path. If you
484need an absolute variable, convert it to absolute during a rule, so that it's
485not expanded into the generated ninja file:
486
487``` make
488$(PRODUCT_OUT)/gen.img: my/src/path/gen.sh
489 export PRODUCT_OUT=$$(cd $(PRODUCT_OUT); pwd); cd my/src/path; ./gen.sh -o $${PRODUCT_OUT}/gen.img
490```
491
492### ANDROID_BUILD_TOP {#ANDROID_BUILD_TOP}
493
494In Android.mk files, you can always assume that the current directory is the
495root of the source tree, so this can just be replaced with '.' (which is what
496$TOP is hardcoded to), or removed entirely. If you need an absolute path, see
497the instructions above.
498
499### Stop using PATH directly {#PATH}
500
501This isn't only set by envsetup.sh, but it is modified by it. Due to that it's
502rather easy for this to change between different shells, and it's not ideal to
503reread the makefiles every time this changes.
504
505In most cases, you shouldn't need to touch PATH at all. When you need to have a
506rule reference a particular binary that's part of the source tree or outputs,
507it's preferrable to just use the path to the file itself (since you should
508already be adding that as a dependency).
509
510Depending on the rule, passing the file path itself may not be feasible due to
511layers of unchangable scripts/binaries. In that case, be sure to add the
512dependency, but modify the PATH within the rule itself:
513
514``` make
515$(TARGET): myscript my/path/binary
516 PATH=my/path:$$PATH myscript -o $@
517```
518
519### Stop using PYTHONPATH directly {#PYTHONPATH}
520
521Like PATH, this isn't only set by envsetup.sh, but it is modified by it. Due to
522that it's rather easy for this to change between different shells, and it's not
523ideal to reread the makefiles every time.
524
525The best solution here is to start switching to Soong's python building support,
526which packages the python interpreter, libraries, and script all into one file
527that no longer needs PYTHONPATH. See fontchain_lint for examples of this:
528
529* [external/fonttools/Lib/fontTools/Android.bp] for python_library_host
530* [frameworks/base/Android.bp] for python_binary_host
531* [frameworks/base/data/fonts/Android.mk] to execute the python binary
532
533If you still need to use PYTHONPATH, do so within the rule itself, just like
534path:
535
536``` make
537$(TARGET): myscript.py $(sort $(shell find my/python/lib -name '*.py'))
538 PYTHONPATH=my/python/lib:$$PYTHONPATH myscript.py -o $@
539```
Yifan Hong97de88c2017-12-12 18:01:09 -0800540### Stop using PRODUCT_COMPATIBILITY_MATRIX_LEVEL_OVERRIDE directly {#PRODUCT_COMPATIBILITY_MATRIX_LEVEL_OVERRIDE}
541
542Specify Framework Compatibility Matrix Version in device manifest by adding a `target-level`
543attribute to the root element `<manifest>`. If `PRODUCT_COMPATIBILITY_MATRIX_LEVEL_OVERRIDE`
544is 26 or 27, you can add `"target-level"="1"` to your device manifest instead.
Dan Willemsen77338622017-11-08 16:39:18 -0800545
Stephen Hines178cf8e2018-01-11 11:54:48 -0800546### Stop using USE_CLANG_PLATFORM_BUILD {#USE_CLANG_PLATFORM_BUILD}
547
548Clang is the default and only supported Android compiler, so there is no reason
549for this option to exist.
550
Dan Willemsen77338622017-11-08 16:39:18 -0800551### Other envsetup.sh variables {#other_envsetup_variables}
552
553* ANDROID_TOOLCHAIN
554* ANDROID_TOOLCHAIN_2ND_ARCH
555* ANDROID_DEV_SCRIPTS
556* ANDROID_EMULATOR_PREBUILTS
557* ANDROID_PRE_BUILD_PATHS
558
559These are all exported from envsetup.sh, but don't have clear equivalents within
560the makefile system. If you need one of them, you'll have to set up your own
561version.
562
563
564[build/soong/Changes.md]: https://android.googlesource.com/platform/build/soong/+/master/Changes.md
Dan Willemsen66d21d42020-01-27 19:26:02 -0800565[build/soong/docs/best_practices.md#headers]: https://android.googlesource.com/platform/build/soong/+/master/docs/best_practices.md#headers
Dan Willemsen77338622017-11-08 16:39:18 -0800566[external/fonttools/Lib/fontTools/Android.bp]: https://android.googlesource.com/platform/external/fonttools/+/master/Lib/fontTools/Android.bp
567[frameworks/base/Android.bp]: https://android.googlesource.com/platform/frameworks/base/+/master/Android.bp
568[frameworks/base/data/fonts/Android.mk]: https://android.googlesource.com/platform/frameworks/base/+/master/data/fonts/Android.mk
Yifan Hong88adfc62019-10-11 15:52:44 -0700569[hardware/interfaces/health/1.0/README.md]: https://android.googlesource.com/platform/hardware/interfaces/+/master/health/1.0/README.md
570[hardware/interfaces/health/2.1/README.md]: https://android.googlesource.com/platform/hardware/interfaces/+/master/health/2.1/README.md