1// Copyright 2016 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package config
16
17import (
18	"runtime"
19	"slices"
20	"strings"
21
22	"android/soong/android"
23	"android/soong/remoteexec"
24)
25
26var (
27	pctx = android.NewPackageContext("android/soong/cc/config")
28
29	// Flags used by lots of devices.  Putting them in package static variables
30	// will save bytes in build.ninja so they aren't repeated for every file
31	commonGlobalCflags = []string{
32		// Enable some optimization by default.
33		"-O2",
34
35		// Warnings enabled by default. Reference:
36		// https://clang.llvm.org/docs/DiagnosticsReference.html
37		"-Wall",
38		"-Wextra",
39		"-Winit-self",
40		"-Wpointer-arith",
41		"-Wunguarded-availability",
42
43		// Warnings treated as errors by default.
44		// See also noOverrideGlobalCflags for errors that cannot be disabled
45		// from Android.bp files.
46
47		// Using __DATE__/__TIME__ causes build nondeterminism.
48		"-Werror=date-time",
49		// Detects forgotten */& that usually cause a crash
50		"-Werror=int-conversion",
51		// Detects unterminated alignment modification pragmas, which often lead
52		// to ABI mismatch between modules and hard-to-debug crashes.
53		"-Werror=pragma-pack",
54		// Same as above, but detects alignment pragmas around a header
55		// inclusion.
56		"-Werror=pragma-pack-suspicious-include",
57		// Detects dividing an array size by itself, which is a common typo that
58		// leads to bugs.
59		"-Werror=sizeof-array-div",
60		// Detects a typo that cuts off a prefix from a string literal.
61		"-Werror=string-plus-int",
62		// Detects for loops that will never execute more than once (for example
63		// due to unconditional break), but have a non-empty loop increment
64		// clause. Often a mistake/bug.
65		"-Werror=unreachable-code-loop-increment",
66
67		// Warnings that should not be errors even for modules with -Werror.
68
69		// Making deprecated usages an error causes extreme pain when trying to
70		// deprecate anything.
71		"-Wno-error=deprecated-declarations",
72
73		// Warnings disabled by default.
74
75		// Designated initializer syntax is recommended by the Google C++ style
76		// and is OK to use even if not formally supported by the chosen C++
77		// version.
78		"-Wno-c99-designator",
79		// Detects uses of a GNU C extension equivalent to a limited form of
80		// constexpr. Enabling this would require replacing many constants with
81		// macros, which is not a good trade-off.
82		"-Wno-gnu-folding-constant",
83		// AIDL generated code redeclares pure virtual methods in each
84		// subsequent version of an interface, so this warning is currently
85		// infeasible to enable.
86		"-Wno-inconsistent-missing-override",
87		// Detects designated initializers that are in a different order than
88		// the fields in the initialized type, which causes the side effects
89		// of initializers to occur out of order with the source code.
90		// In practice, this warning has extremely poor signal to noise ratio,
91		// because it is triggered even for initializers with no side effects.
92		// Individual modules can still opt into it via cflags.
93		"-Wno-error=reorder-init-list",
94		"-Wno-reorder-init-list",
95		// Incompatible with the Google C++ style guidance to use 'int' for loop
96		// indices; poor signal to noise ratio.
97		"-Wno-sign-compare",
98		// Poor signal to noise ratio.
99		"-Wno-unused",
100
101		// Global preprocessor constants.
102
103		"-DANDROID",
104		"-DNDEBUG",
105		"-UDEBUG",
106		"-D__compiler_offsetof=__builtin_offsetof",
107		// Allows the bionic versioning.h to indirectly determine whether the
108		// option -Wunguarded-availability is on or not.
109		"-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__",
110
111		// -f and -g options.
112
113		// Emit address-significance table which allows linker to perform safe ICF. Clang does
114		// not emit the table by default on Android since NDK still uses GNU binutils.
115		"-faddrsig",
116
117		// Emit debugging data in a modern format (DWARF v5).
118		"-fdebug-default-version=5",
119
120		// Force clang to always output color diagnostics. Ninja will strip the ANSI
121		// color codes if it is not running in a terminal.
122		"-fcolor-diagnostics",
123
124		// Turn off FMA which got enabled by default in clang-r445002 (http://b/218805949)
125		"-ffp-contract=off",
126
127		// Google C++ style does not allow exceptions, turn them off by default.
128		"-fno-exceptions",
129
130		// Disable optimizations based on strict aliasing by default.
131		// The performance benefit of enabling them currently does not outweigh
132		// the risk of hard-to-reproduce bugs.
133		"-fno-strict-aliasing",
134
135		// Disable line wrapping for error messages - it interferes with
136		// displaying logs in web browsers.
137		"-fmessage-length=0",
138
139		// Disable C++17 "relaxed template template argument matching" as a workaround for
140		// our out-dated libcxx.
141		// http://b/341084395
142		"-fno-relaxed-template-template-args",
143
144		// Using simple template names reduces the size of debug builds.
145		"-gsimple-template-names",
146
147		// Use zstd to compress debug data.
148		"-gz=zstd",
149
150		// Make paths in deps files relative.
151		"-no-canonical-prefixes",
152
153		// http://b/315250603 temporarily disabled
154		"-Wno-error=format",
155	}
156
157	commonGlobalConlyflags = []string{}
158
159	commonGlobalAsflags = []string{
160		"-D__ASSEMBLY__",
161		// TODO(b/235105792): override global -fdebug-default-version=5, it is causing $TMPDIR to
162		// end up in the dwarf data for crtend_so.S.
163		"-fdebug-default-version=4",
164	}
165
166	// Compilation flags for device code; not applied to host code.
167	deviceGlobalCflags = []string{
168		"-ffunction-sections",
169		"-fdata-sections",
170		"-fno-short-enums",
171		"-funwind-tables",
172		"-fstack-protector-strong",
173		"-Wa,--noexecstack",
174		"-D_FORTIFY_SOURCE=2",
175
176		"-Wstrict-aliasing=2",
177
178		"-Werror=return-type",
179		"-Werror=non-virtual-dtor",
180		"-Werror=address",
181		"-Werror=sequence-point",
182		"-Werror=format-security",
183		"-nostdlibinc",
184
185		// Emit additional debug info for AutoFDO
186		"-fdebug-info-for-profiling",
187	}
188
189	commonGlobalLldflags = []string{
190		"-fuse-ld=lld",
191		"-Wl,--icf=safe",
192		"-Wl,--no-demangle",
193	}
194
195	deviceGlobalCppflags = []string{
196		"-fvisibility-inlines-hidden",
197	}
198
199	// Linking flags for device code; not applied to host binaries.
200	deviceGlobalLdflags = []string{
201		"-Wl,-z,noexecstack",
202		"-Wl,-z,relro",
203		"-Wl,-z,now",
204		"-Wl,--build-id=md5",
205		"-Wl,--fatal-warnings",
206		"-Wl,--no-undefined-version",
207		// TODO: Eventually we should link against a libunwind.a with hidden symbols, and then these
208		// --exclude-libs arguments can be removed.
209		"-Wl,--exclude-libs,libgcc.a",
210		"-Wl,--exclude-libs,libgcc_stripped.a",
211		"-Wl,--exclude-libs,libunwind_llvm.a",
212		"-Wl,--exclude-libs,libunwind.a",
213	}
214
215	deviceGlobalLldflags = append(append(deviceGlobalLdflags, commonGlobalLldflags...),
216		"-Wl,--compress-debug-sections=zstd",
217	)
218
219	hostGlobalCflags = []string{}
220
221	hostGlobalCppflags = []string{}
222
223	hostGlobalLdflags = []string{}
224
225	hostGlobalLldflags = commonGlobalLldflags
226
227	commonGlobalCppflags = []string{
228		// -Wimplicit-fallthrough is not enabled by -Wall.
229		"-Wimplicit-fallthrough",
230
231		// Enable clang's thread-safety annotations in libcxx.
232		"-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
233
234		// libc++'s math.h has an #include_next outside of system_headers.
235		"-Wno-gnu-include-next",
236	}
237
238	// These flags are appended after the module's cflags, so they cannot be
239	// overridden from Android.bp files.
240	//
241	// NOTE: if you need to disable a warning to unblock a compiler upgrade
242	// and it is only triggered by third party code, add it to
243	// extraExternalCflags (if possible) or noOverrideExternalGlobalCflags
244	// (if the former doesn't work). If the new warning also occurs in first
245	// party code, try adding it to commonGlobalCflags first. Adding it here
246	// should be the last resort, because it prevents all code in Android from
247	// opting into the warning.
248	noOverrideGlobalCflags = []string{
249		"-Werror=bool-operation",
250		"-Werror=format-insufficient-args",
251		"-Werror=implicit-int-float-conversion",
252		"-Werror=int-in-bool-context",
253		"-Werror=int-to-pointer-cast",
254		"-Werror=pointer-to-int-cast",
255		"-Werror=xor-used-as-pow",
256		// http://b/161386391 for -Wno-void-pointer-to-enum-cast
257		"-Wno-void-pointer-to-enum-cast",
258		// http://b/161386391 for -Wno-void-pointer-to-int-cast
259		"-Wno-void-pointer-to-int-cast",
260		// http://b/161386391 for -Wno-pointer-to-int-cast
261		"-Wno-pointer-to-int-cast",
262		"-Werror=fortify-source",
263		// http://b/315246135 temporarily disabled
264		"-Wno-unused-variable",
265		// Disabled because it produces many false positives. http://b/323050926
266		"-Wno-missing-field-initializers",
267		// http://b/323050889
268		"-Wno-packed-non-pod",
269
270		"-Werror=address-of-temporary",
271		"-Werror=incompatible-function-pointer-types",
272		"-Werror=null-dereference",
273		"-Werror=return-type",
274
275		// http://b/72331526 Disable -Wtautological-* until the instances detected by these
276		// new warnings are fixed.
277		"-Wno-tautological-constant-compare",
278		"-Wno-tautological-type-limit-compare",
279		// http://b/145211066
280		"-Wno-implicit-int-float-conversion",
281		// New warnings to be fixed after clang-r377782.
282		"-Wno-tautological-overlap-compare", // http://b/148815696
283		// New warnings to be fixed after clang-r383902.
284		"-Wno-deprecated-copy",                      // http://b/153746672
285		"-Wno-range-loop-construct",                 // http://b/153747076
286		"-Wno-zero-as-null-pointer-constant",        // http://b/68236239
287		"-Wno-deprecated-anon-enum-enum-conversion", // http://b/153746485
288		"-Wno-deprecated-enum-enum-conversion",
289		"-Wno-pessimizing-move", // http://b/154270751
290		// New warnings to be fixed after clang-r399163
291		"-Wno-non-c-typedef-for-linkage", // http://b/161304145
292		// New warnings to be fixed after clang-r428724
293		"-Wno-align-mismatch", // http://b/193679946
294		// New warnings to be fixed after clang-r433403
295		"-Wno-error=unused-but-set-variable",  // http://b/197240255
296		"-Wno-error=unused-but-set-parameter", // http://b/197240255
297		// New warnings to be fixed after clang-r468909
298		"-Wno-error=deprecated-builtins", // http://b/241601211
299		"-Wno-error=deprecated",          // in external/googletest/googletest
300		// New warnings to be fixed after clang-r475365
301		"-Wno-error=single-bit-bitfield-constant-conversion", // http://b/243965903
302		"-Wno-error=enum-constexpr-conversion",               // http://b/243964282
303		// New warnings to be fixed after clang-r522817
304		"-Wno-error=invalid-offsetof",
305		"-Wno-error=thread-safety-reference-return",
306
307		// Irrelevant on Android because _we_ don't use exceptions, but causes
308		// lots of build noise because libcxx/libcxxabi do. This can probably
309		// go away when we're on a new enough libc++, but has to be global
310		// until then because it causes warnings in the _callers_, not the
311		// project itself.
312		"-Wno-deprecated-dynamic-exception-spec",
313
314		// Allow using VLA CXX extension.
315		"-Wno-vla-cxx-extension",
316	}
317
318	noOverride64GlobalCflags = []string{}
319
320	// Extra cflags applied to third-party code (anything for which
321	// IsThirdPartyPath() in build/soong/android/paths.go returns true;
322	// includes external/, most of vendor/ and most of hardware/)
323	extraExternalCflags = []string{
324		"-Wno-enum-compare",
325		"-Wno-enum-compare-switch",
326
327		// http://b/72331524 Allow null pointer arithmetic until the instances detected by
328		// this new warning are fixed.
329		"-Wno-null-pointer-arithmetic",
330
331		// Bug: http://b/29823425 Disable -Wnull-dereference until the
332		// new instances detected by this warning are fixed.
333		"-Wno-null-dereference",
334
335		// http://b/145211477
336		"-Wno-pointer-compare",
337		"-Wno-final-dtor-non-final-class",
338
339		// http://b/165945989
340		"-Wno-psabi",
341
342		// http://b/199369603
343		"-Wno-null-pointer-subtraction",
344
345		// http://b/175068488
346		"-Wno-string-concatenation",
347
348		// http://b/239661264
349		"-Wno-deprecated-non-prototype",
350
351		"-Wno-unused",
352		"-Wno-deprecated",
353	}
354
355	// Similar to noOverrideGlobalCflags, but applies only to third-party code
356	// (see extraExternalCflags).
357	// This section can unblock compiler upgrades when a third party module that
358	// enables -Werror and some group of warnings explicitly triggers newly
359	// added warnings.
360	noOverrideExternalGlobalCflags = []string{
361		// http://b/151457797
362		"-fcommon",
363		// http://b/191699019
364		"-Wno-format-insufficient-args",
365		// http://b/296321508
366		// Introduced in response to a critical security vulnerability and
367		// should be a hard error - it requires only whitespace changes to fix.
368		"-Wno-misleading-indentation",
369		// Triggered by old LLVM code in external/llvm. Likely not worth
370		// enabling since it's a cosmetic issue.
371		"-Wno-bitwise-instead-of-logical",
372
373		"-Wno-unused",
374		"-Wno-unused-parameter",
375		"-Wno-unused-but-set-parameter",
376		"-Wno-unqualified-std-cast-call",
377		"-Wno-array-parameter",
378		"-Wno-gnu-offsetof-extensions",
379		// TODO: Enable this warning http://b/315245071
380		"-Wno-fortify-source",
381	}
382
383	llvmNextExtraCommonGlobalCflags = []string{
384		// Do not report warnings when testing with the top of trunk LLVM.
385		"-Wno-everything",
386	}
387
388	// Flags that must not appear in any command line.
389	IllegalFlags = []string{
390		"-w",
391	}
392
393	CStdVersion               = "gnu17"
394	CppStdVersion             = "gnu++20"
395	ExperimentalCStdVersion   = "gnu2x"
396	ExperimentalCppStdVersion = "gnu++2b"
397
398	// prebuilts/clang default settings.
399	ClangDefaultBase         = "prebuilts/clang/host"
400	ClangDefaultVersion      = "clang-r522817"
401	ClangDefaultShortVersion = "18"
402
403	// Directories with warnings from Android.bp files.
404	WarningAllowedProjects = []string{
405		"device/",
406		"vendor/",
407	}
408
409	VersionScriptFlagPrefix = "-Wl,--version-script,"
410
411	VisibilityHiddenFlag  = "-fvisibility=hidden"
412	VisibilityDefaultFlag = "-fvisibility=default"
413)
414
415func init() {
416	if runtime.GOOS == "linux" {
417		commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
418	}
419
420	pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
421	pctx.StaticVariable("CommonGlobalAsflags", strings.Join(commonGlobalAsflags, " "))
422	pctx.StaticVariable("DeviceGlobalCppflags", strings.Join(deviceGlobalCppflags, " "))
423	pctx.StaticVariable("DeviceGlobalLdflags", strings.Join(deviceGlobalLdflags, " "))
424	pctx.StaticVariable("DeviceGlobalLldflags", strings.Join(deviceGlobalLldflags, " "))
425	pctx.StaticVariable("HostGlobalCppflags", strings.Join(hostGlobalCppflags, " "))
426	pctx.StaticVariable("HostGlobalLdflags", strings.Join(hostGlobalLdflags, " "))
427	pctx.StaticVariable("HostGlobalLldflags", strings.Join(hostGlobalLldflags, " "))
428
429	pctx.VariableFunc("CommonGlobalCflags", func(ctx android.PackageVarContext) string {
430		flags := slices.Clone(commonGlobalCflags)
431
432		// http://b/131390872
433		// Automatically initialize any uninitialized stack variables.
434		// Prefer zero-init if multiple options are set.
435		if ctx.Config().IsEnvTrue("AUTO_ZERO_INITIALIZE") {
436			flags = append(flags, "-ftrivial-auto-var-init=zero")
437		} else if ctx.Config().IsEnvTrue("AUTO_PATTERN_INITIALIZE") {
438			flags = append(flags, "-ftrivial-auto-var-init=pattern")
439		} else if ctx.Config().IsEnvTrue("AUTO_UNINITIALIZE") {
440			flags = append(flags, "-ftrivial-auto-var-init=uninitialized")
441		} else {
442			// Default to zero initialization.
443			flags = append(flags, "-ftrivial-auto-var-init=zero")
444		}
445
446		// Workaround for ccache with clang.
447		// See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
448		if ctx.Config().IsEnvTrue("USE_CCACHE") {
449			flags = append(flags, "-Wno-unused-command-line-argument")
450		}
451
452		if ctx.Config().IsEnvTrue("ALLOW_UNKNOWN_WARNING_OPTION") {
453			flags = append(flags, "-Wno-error=unknown-warning-option")
454		}
455
456		switch ctx.Config().Getenv("CLANG_DEFAULT_DEBUG_LEVEL") {
457		case "debug_level_0":
458			flags = append(flags, "-g0")
459		case "debug_level_1":
460			flags = append(flags, "-g1")
461		case "debug_level_2":
462			flags = append(flags, "-g2")
463		case "debug_level_3":
464			flags = append(flags, "-g3")
465		case "debug_level_g":
466			flags = append(flags, "-g")
467		default:
468			flags = append(flags, "-g")
469		}
470
471		return strings.Join(flags, " ")
472	})
473
474	pctx.VariableFunc("DeviceGlobalCflags", func(ctx android.PackageVarContext) string {
475		return strings.Join(deviceGlobalCflags, " ")
476	})
477
478	pctx.VariableFunc("NoOverrideGlobalCflags", func(ctx android.PackageVarContext) string {
479		flags := noOverrideGlobalCflags
480		if ctx.Config().IsEnvTrue("LLVM_NEXT") {
481			flags = append(noOverrideGlobalCflags, llvmNextExtraCommonGlobalCflags...)
482			IllegalFlags = []string{} // Don't fail build while testing a new compiler.
483		}
484		return strings.Join(flags, " ")
485	})
486
487	pctx.StaticVariable("NoOverride64GlobalCflags", strings.Join(noOverride64GlobalCflags, " "))
488	pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
489	pctx.StaticVariable("NoOverrideExternalGlobalCflags", strings.Join(noOverrideExternalGlobalCflags, " "))
490	pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
491	pctx.StaticVariable("ExternalCflags", strings.Join(extraExternalCflags, " "))
492
493	// Everything in these lists is a crime against abstraction and dependency tracking.
494	// Do not add anything to this list.
495	commonGlobalIncludes := []string{
496		"system/core/include",
497		"system/logging/liblog/include",
498		"system/media/audio/include",
499		"hardware/libhardware/include",
500		"hardware/libhardware_legacy/include",
501		"hardware/ril/include",
502		"frameworks/native/include",
503		"frameworks/native/opengl/include",
504		"frameworks/av/include",
505	}
506	pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I", commonGlobalIncludes)
507
508	pctx.StaticVariable("CLANG_DEFAULT_VERSION", ClangDefaultVersion)
509	pctx.StaticVariable("CLANG_DEFAULT_SHORT_VERSION", ClangDefaultShortVersion)
510
511	pctx.StaticVariableWithEnvOverride("ClangBase", "LLVM_PREBUILTS_BASE", ClangDefaultBase)
512	pctx.StaticVariableWithEnvOverride("ClangVersion", "LLVM_PREBUILTS_VERSION", ClangDefaultVersion)
513	pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
514	pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
515
516	pctx.StaticVariableWithEnvOverride("ClangShortVersion", "LLVM_RELEASE_VERSION", ClangDefaultShortVersion)
517	pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib/clang/${ClangShortVersion}/lib/linux")
518
519	pctx.StaticVariable("WarningAllowedProjects", strings.Join(WarningAllowedProjects, " "))
520
521	// These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
522	// being used for the rest of the build process.
523	pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
524	pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
525	pctx.SourcePathVariable("RSReleaseVersion", "3.8")
526	pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
527	pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
528
529	rsGlobalIncludes := []string{
530		"external/clang/lib/Headers",
531		"frameworks/rs/script_api/include",
532	}
533	pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I", rsGlobalIncludes)
534
535	pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string {
536		if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" {
537			return override + " "
538		}
539		return ""
540	})
541
542	pctx.StaticVariableWithEnvOverride("RECXXPool", "RBE_CXX_POOL", remoteexec.DefaultPool)
543	pctx.StaticVariableWithEnvOverride("RECXXLinksPool", "RBE_CXX_LINKS_POOL", remoteexec.DefaultPool)
544	pctx.StaticVariableWithEnvOverride("REClangTidyPool", "RBE_CLANG_TIDY_POOL", remoteexec.DefaultPool)
545	pctx.StaticVariableWithEnvOverride("RECXXLinksExecStrategy", "RBE_CXX_LINKS_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
546	pctx.StaticVariableWithEnvOverride("REClangTidyExecStrategy", "RBE_CLANG_TIDY_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
547	pctx.StaticVariableWithEnvOverride("REAbiDumperExecStrategy", "RBE_ABI_DUMPER_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
548	pctx.StaticVariableWithEnvOverride("REAbiLinkerExecStrategy", "RBE_ABI_LINKER_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
549}
550
551var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
552
553func ClangPath(ctx android.PathContext, file string) android.SourcePath {
554	type clangToolKey string
555
556	key := android.NewCustomOnceKey(clangToolKey(file))
557
558	return ctx.Config().OnceSourcePath(key, func() android.SourcePath {
559		return clangPath(ctx).Join(ctx, file)
560	})
561}
562
563var clangPathKey = android.NewOnceKey("clangPath")
564
565func clangPath(ctx android.PathContext) android.SourcePath {
566	return ctx.Config().OnceSourcePath(clangPathKey, func() android.SourcePath {
567		clangBase := ClangDefaultBase
568		if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
569			clangBase = override
570		}
571		clangVersion := ClangDefaultVersion
572		if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
573			clangVersion = override
574		}
575		return android.PathForSource(ctx, clangBase, ctx.Config().PrebuiltOS(), clangVersion)
576	})
577}
578