2016-07-29 21:48:20 +02:00
|
|
|
// Copyright 2016 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 cc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2019-10-08 11:27:17 +02:00
|
|
|
"regexp"
|
2019-07-23 01:36:06 +02:00
|
|
|
"strconv"
|
2016-07-29 21:48:20 +02:00
|
|
|
"strings"
|
|
|
|
|
2016-09-29 23:06:02 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
"android/soong/android"
|
2016-07-29 22:44:28 +02:00
|
|
|
"android/soong/cc/config"
|
2016-07-29 21:48:20 +02:00
|
|
|
)
|
|
|
|
|
2019-11-26 19:32:50 +01:00
|
|
|
var (
|
|
|
|
allowedManualInterfacePaths = []string{"vendor/", "hardware/"}
|
|
|
|
)
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
// This file contains the basic C/C++/assembly to .o compliation steps
|
|
|
|
|
|
|
|
type BaseCompilerProperties struct {
|
|
|
|
// list of source files used to compile the C/C++ module. May be .c, .cpp, or .S files.
|
2016-12-14 00:23:47 +01:00
|
|
|
// srcs may reference the outputs of other modules that produce source files like genrule
|
|
|
|
// or filegroup using the syntax ":module".
|
2019-03-05 07:35:41 +01:00
|
|
|
Srcs []string `android:"path,arch_variant"`
|
2016-07-29 21:48:20 +02:00
|
|
|
|
|
|
|
// list of source files that should not be used to build the C/C++ module.
|
|
|
|
// This is most useful in the arch/multilib variants to remove non-common files
|
2019-03-05 07:35:41 +01:00
|
|
|
Exclude_srcs []string `android:"path,arch_variant"`
|
2016-07-29 21:48:20 +02:00
|
|
|
|
|
|
|
// list of module-specific flags that will be used for C and C++ compiles.
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of module-specific flags that will be used for C++ compiles
|
|
|
|
Cppflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of module-specific flags that will be used for C compiles
|
|
|
|
Conlyflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of module-specific flags that will be used for .S compiles
|
|
|
|
Asflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of module-specific flags that will be used for C and C++ compiles when
|
|
|
|
// compiling with clang
|
|
|
|
Clang_cflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of module-specific flags that will be used for .S compiles when
|
|
|
|
// compiling with clang
|
|
|
|
Clang_asflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// the instruction set architecture to use to compile the C/C++
|
|
|
|
// module.
|
2017-10-26 00:20:50 +02:00
|
|
|
Instruction_set *string `android:"arch_variant"`
|
2016-07-29 21:48:20 +02:00
|
|
|
|
|
|
|
// list of directories relative to the root of the source tree that will
|
|
|
|
// be added to the include path using -I.
|
|
|
|
// If possible, don't use this. If adding paths from the current directory use
|
|
|
|
// local_include_dirs, if adding paths from other modules use export_include_dirs in
|
|
|
|
// that module.
|
2017-04-27 02:01:07 +02:00
|
|
|
Include_dirs []string `android:"arch_variant,variant_prepend"`
|
2016-07-29 21:48:20 +02:00
|
|
|
|
|
|
|
// list of directories relative to the Blueprints file that will
|
|
|
|
// be added to the include path using -I
|
2018-07-23 06:18:45 +02:00
|
|
|
Local_include_dirs []string `android:"arch_variant,variant_prepend"`
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2018-12-06 20:04:03 +01:00
|
|
|
// Add the directory containing the Android.bp file to the list of include
|
|
|
|
// directories. Defaults to true.
|
|
|
|
Include_build_directory *bool
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
// list of generated sources to compile. These are the names of gensrcs or
|
|
|
|
// genrule modules.
|
|
|
|
Generated_sources []string `android:"arch_variant"`
|
|
|
|
|
2020-07-04 20:54:35 +02:00
|
|
|
// list of generated sources that should not be used to build the C/C++ module.
|
|
|
|
// This is most useful in the arch/multilib variants to remove non-common files
|
|
|
|
Exclude_generated_sources []string `android:"arch_variant"`
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
// list of generated headers to add to the include path. These are the names
|
|
|
|
// of genrule modules.
|
|
|
|
Generated_headers []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// pass -frtti instead of -fno-rtti
|
|
|
|
Rtti *bool
|
|
|
|
|
2017-02-04 01:13:38 +01:00
|
|
|
// C standard version to use. Can be a specific version (such as "gnu11"),
|
|
|
|
// "experimental" (which will use draft versions like C1x when available),
|
|
|
|
// or the empty string (which will use the default).
|
2017-11-07 19:57:05 +01:00
|
|
|
C_std *string
|
2017-02-04 01:13:38 +01:00
|
|
|
|
|
|
|
// C++ standard version to use. Can be a specific version (such as
|
|
|
|
// "gnu++11"), "experimental" (which will use draft versions like C++1z when
|
|
|
|
// available), or the empty string (which will use the default).
|
2017-11-07 19:57:05 +01:00
|
|
|
Cpp_std *string
|
2017-02-04 01:13:38 +01:00
|
|
|
|
2016-10-17 23:24:56 +02:00
|
|
|
// if set to false, use -std=c++* instead of -std=gnu++*
|
|
|
|
Gnu_extensions *bool
|
|
|
|
|
2019-04-11 07:59:54 +02:00
|
|
|
Yacc *YaccProperties
|
2020-07-15 10:58:56 +02:00
|
|
|
Lex *LexProperties
|
2019-04-11 07:59:54 +02:00
|
|
|
|
2016-11-03 22:28:51 +01:00
|
|
|
Aidl struct {
|
|
|
|
// list of directories that will be added to the aidl include paths.
|
|
|
|
Include_dirs []string
|
|
|
|
|
|
|
|
// list of directories relative to the Blueprints file that will
|
|
|
|
// be added to the aidl include paths.
|
|
|
|
Local_include_dirs []string
|
2018-03-09 09:29:59 +01:00
|
|
|
|
|
|
|
// whether to generate traces (for systrace) for this interface
|
|
|
|
Generate_traces *bool
|
2016-11-03 22:28:51 +01:00
|
|
|
}
|
|
|
|
|
2017-05-02 02:37:24 +02:00
|
|
|
Renderscript struct {
|
|
|
|
// list of directories that will be added to the llvm-rs-cc include paths
|
|
|
|
Include_dirs []string
|
|
|
|
|
|
|
|
// list of flags that will be passed to llvm-rs-cc
|
|
|
|
Flags []string
|
|
|
|
|
|
|
|
// Renderscript API level to target
|
|
|
|
Target_api *string
|
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
Debug, Release struct {
|
|
|
|
// list of module-specific flags that will be used for C and C++ compiles in debug or
|
|
|
|
// release builds
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
Split /system and /vendor modules, allow multi-installation
Nothing changes if BOARD_VNDK_VERSION isn't set.
When the VNDK is enabled (BOARD_VNDK_VERSION in Make), this will split
/system and /vendor modules into two different variant spaces that can't
link to each other. There are a few interfaces between the two variant
spaces:
The `llndk_library` stubs will be available in the /vendor variant, but
won't be installed, so at runtime the /system variant will be used.
Setting `vendor_available: true` will split a module into both variants.
The /system (or "core") variant will compile just like today. The
/vendor ("vendor") variant will compile against everything else in the
vendor space (so LL-NDK instead of libc/liblog/etc). There will be two
copies of these libraries installed onto the final device.
Since the available runtime interfaces for vendor modules may be
reduced, and your dependencies may not expose their private interfaces,
we allow the vendor variants to reduce their compilation set, and export
a different set of headers:
cc_library {
name: "libfoo",
srcs: ["common.cpp", "private_impl.cpp"],
export_include_dirs: ["include"],
target: {
vendor: {
export_include_dirs: ["include_vndk"],
exclude_srcs: ["private_impl.cpp"],
srcs: ["vendor_only.cpp"],
},
},
}
So the "core" variant would compile with both "common.cpp" and
"private_impl.cpp", and export "include".
The "vendor" variant would compile "common.cpp" and "vendor_only.cpp",
and export "include_vndk".
Bug: 36426473
Bug: 36079834
Test: out/soong/build.ninja, out/soong/Android- only changes due to _core addition and
.llndk -> .vendor
Test: attempt to compile with BOARD_VNDK_VERSION:=current
Change-Id: Idef28764043bf6c33dc0d2e7e2026c38867ff769
2017-04-06 21:43:22 +02:00
|
|
|
|
|
|
|
Target struct {
|
2020-10-29 08:49:43 +01:00
|
|
|
Vendor, Product struct {
|
|
|
|
// list of source files that should only be used in vendor or
|
|
|
|
// product variant of the C/C++ module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Srcs []string `android:"path"`
|
Split /system and /vendor modules, allow multi-installation
Nothing changes if BOARD_VNDK_VERSION isn't set.
When the VNDK is enabled (BOARD_VNDK_VERSION in Make), this will split
/system and /vendor modules into two different variant spaces that can't
link to each other. There are a few interfaces between the two variant
spaces:
The `llndk_library` stubs will be available in the /vendor variant, but
won't be installed, so at runtime the /system variant will be used.
Setting `vendor_available: true` will split a module into both variants.
The /system (or "core") variant will compile just like today. The
/vendor ("vendor") variant will compile against everything else in the
vendor space (so LL-NDK instead of libc/liblog/etc). There will be two
copies of these libraries installed onto the final device.
Since the available runtime interfaces for vendor modules may be
reduced, and your dependencies may not expose their private interfaces,
we allow the vendor variants to reduce their compilation set, and export
a different set of headers:
cc_library {
name: "libfoo",
srcs: ["common.cpp", "private_impl.cpp"],
export_include_dirs: ["include"],
target: {
vendor: {
export_include_dirs: ["include_vndk"],
exclude_srcs: ["private_impl.cpp"],
srcs: ["vendor_only.cpp"],
},
},
}
So the "core" variant would compile with both "common.cpp" and
"private_impl.cpp", and export "include".
The "vendor" variant would compile "common.cpp" and "vendor_only.cpp",
and export "include_vndk".
Bug: 36426473
Bug: 36079834
Test: out/soong/build.ninja, out/soong/Android- only changes due to _core addition and
.llndk -> .vendor
Test: attempt to compile with BOARD_VNDK_VERSION:=current
Change-Id: Idef28764043bf6c33dc0d2e7e2026c38867ff769
2017-04-06 21:43:22 +02:00
|
|
|
|
2020-10-29 08:49:43 +01:00
|
|
|
// list of source files that should not be used to build vendor
|
|
|
|
// or product variant of the C/C++ module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Exclude_srcs []string `android:"path"`
|
2017-08-10 06:33:27 +02:00
|
|
|
|
2020-10-29 08:49:43 +01:00
|
|
|
// List of additional cflags that should be used to build vendor
|
|
|
|
// or product variant of the C/C++ module.
|
2017-08-10 06:33:27 +02:00
|
|
|
Cflags []string
|
2020-07-04 20:54:35 +02:00
|
|
|
|
2020-10-29 08:49:43 +01:00
|
|
|
// list of generated sources that should not be used to build
|
|
|
|
// vendor or product variant of the C/C++ module.
|
2020-07-04 20:54:35 +02:00
|
|
|
Exclude_generated_sources []string
|
Split /system and /vendor modules, allow multi-installation
Nothing changes if BOARD_VNDK_VERSION isn't set.
When the VNDK is enabled (BOARD_VNDK_VERSION in Make), this will split
/system and /vendor modules into two different variant spaces that can't
link to each other. There are a few interfaces between the two variant
spaces:
The `llndk_library` stubs will be available in the /vendor variant, but
won't be installed, so at runtime the /system variant will be used.
Setting `vendor_available: true` will split a module into both variants.
The /system (or "core") variant will compile just like today. The
/vendor ("vendor") variant will compile against everything else in the
vendor space (so LL-NDK instead of libc/liblog/etc). There will be two
copies of these libraries installed onto the final device.
Since the available runtime interfaces for vendor modules may be
reduced, and your dependencies may not expose their private interfaces,
we allow the vendor variants to reduce their compilation set, and export
a different set of headers:
cc_library {
name: "libfoo",
srcs: ["common.cpp", "private_impl.cpp"],
export_include_dirs: ["include"],
target: {
vendor: {
export_include_dirs: ["include_vndk"],
exclude_srcs: ["private_impl.cpp"],
srcs: ["vendor_only.cpp"],
},
},
}
So the "core" variant would compile with both "common.cpp" and
"private_impl.cpp", and export "include".
The "vendor" variant would compile "common.cpp" and "vendor_only.cpp",
and export "include_vndk".
Bug: 36426473
Bug: 36079834
Test: out/soong/build.ninja, out/soong/Android- only changes due to _core addition and
.llndk -> .vendor
Test: attempt to compile with BOARD_VNDK_VERSION:=current
Change-Id: Idef28764043bf6c33dc0d2e7e2026c38867ff769
2017-04-06 21:43:22 +02:00
|
|
|
}
|
2018-01-31 16:54:12 +01:00
|
|
|
Recovery struct {
|
|
|
|
// list of source files that should only be used in the
|
|
|
|
// recovery variant of the C/C++ module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Srcs []string `android:"path"`
|
2018-01-31 16:54:12 +01:00
|
|
|
|
|
|
|
// list of source files that should not be used to
|
|
|
|
// build the recovery variant of the C/C++ module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Exclude_srcs []string `android:"path"`
|
2018-01-31 16:54:12 +01:00
|
|
|
|
|
|
|
// List of additional cflags that should be used to build the recovery
|
|
|
|
// variant of the C/C++ module.
|
|
|
|
Cflags []string
|
2020-07-04 20:54:35 +02:00
|
|
|
|
|
|
|
// list of generated sources that should not be used to
|
|
|
|
// build the recovery variant of the C/C++ module.
|
|
|
|
Exclude_generated_sources []string
|
2018-01-31 16:54:12 +01:00
|
|
|
}
|
2020-10-27 23:01:21 +01:00
|
|
|
Vendor_ramdisk struct {
|
|
|
|
// list of source files that should not be used to
|
|
|
|
// build the vendor ramdisk variant of the C/C++ module.
|
|
|
|
Exclude_srcs []string `android:"path"`
|
|
|
|
|
|
|
|
// List of additional cflags that should be used to build the vendor ramdisk
|
|
|
|
// variant of the C/C++ module.
|
|
|
|
Cflags []string
|
|
|
|
}
|
Split /system and /vendor modules, allow multi-installation
Nothing changes if BOARD_VNDK_VERSION isn't set.
When the VNDK is enabled (BOARD_VNDK_VERSION in Make), this will split
/system and /vendor modules into two different variant spaces that can't
link to each other. There are a few interfaces between the two variant
spaces:
The `llndk_library` stubs will be available in the /vendor variant, but
won't be installed, so at runtime the /system variant will be used.
Setting `vendor_available: true` will split a module into both variants.
The /system (or "core") variant will compile just like today. The
/vendor ("vendor") variant will compile against everything else in the
vendor space (so LL-NDK instead of libc/liblog/etc). There will be two
copies of these libraries installed onto the final device.
Since the available runtime interfaces for vendor modules may be
reduced, and your dependencies may not expose their private interfaces,
we allow the vendor variants to reduce their compilation set, and export
a different set of headers:
cc_library {
name: "libfoo",
srcs: ["common.cpp", "private_impl.cpp"],
export_include_dirs: ["include"],
target: {
vendor: {
export_include_dirs: ["include_vndk"],
exclude_srcs: ["private_impl.cpp"],
srcs: ["vendor_only.cpp"],
},
},
}
So the "core" variant would compile with both "common.cpp" and
"private_impl.cpp", and export "include".
The "vendor" variant would compile "common.cpp" and "vendor_only.cpp",
and export "include_vndk".
Bug: 36426473
Bug: 36079834
Test: out/soong/build.ninja, out/soong/Android- only changes due to _core addition and
.llndk -> .vendor
Test: attempt to compile with BOARD_VNDK_VERSION:=current
Change-Id: Idef28764043bf6c33dc0d2e7e2026c38867ff769
2017-04-06 21:43:22 +02:00
|
|
|
}
|
2017-05-03 20:01:58 +02:00
|
|
|
|
2017-09-07 19:53:07 +02:00
|
|
|
Proto struct {
|
|
|
|
// Link statically against the protobuf runtime
|
2017-11-07 19:57:05 +01:00
|
|
|
Static *bool `android:"arch_variant"`
|
2017-09-07 19:53:07 +02:00
|
|
|
} `android:"arch_variant"`
|
|
|
|
|
2017-05-03 20:01:58 +02:00
|
|
|
// Stores the original list of source files before being cleared by library reuse
|
|
|
|
OriginalSrcs []string `blueprint:"mutated"`
|
2017-12-20 08:08:09 +01:00
|
|
|
|
|
|
|
// Build and link with OpenMP
|
|
|
|
Openmp *bool `android:"arch_variant"`
|
2020-03-02 09:44:33 +01:00
|
|
|
|
2020-08-18 08:37:17 +02:00
|
|
|
// Deprecated.
|
2020-03-02 09:44:33 +01:00
|
|
|
// Adds __ANDROID_APEX_<APEX_MODULE_NAME>__ macro defined for apex variants in addition to __ANDROID_APEX__
|
|
|
|
Use_apex_name_macro *bool
|
2020-08-18 08:37:17 +02:00
|
|
|
|
|
|
|
// Adds two macros for apex variants in addition to __ANDROID_APEX__
|
|
|
|
// * __ANDROID_APEX_COM_ANDROID_FOO__
|
|
|
|
// * __ANDROID_APEX_NAME__="com.android.foo"
|
|
|
|
UseApexNameMacro bool `blueprint:"mutated"`
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func NewBaseCompiler() *baseCompiler {
|
|
|
|
return &baseCompiler{}
|
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
type baseCompiler struct {
|
|
|
|
Properties BaseCompilerProperties
|
2017-09-07 19:53:07 +02:00
|
|
|
Proto android.ProtoProperties
|
2018-01-23 19:49:04 +01:00
|
|
|
cFlagsDeps android.Paths
|
2017-12-20 00:11:01 +01:00
|
|
|
pathDeps android.Paths
|
2017-01-11 01:21:22 +01:00
|
|
|
flags builderFlags
|
2017-11-16 23:33:08 +01:00
|
|
|
|
|
|
|
// Sources that were passed to the C/C++ compiler
|
|
|
|
srcs android.Paths
|
|
|
|
|
|
|
|
// Sources that were passed in the Android.bp file, including generated sources generated by
|
|
|
|
// other modules and filegroups. May include source files that have not yet been translated to
|
|
|
|
// C/C++ (.aidl, .proto, etc.)
|
|
|
|
srcsBeforeGen android.Paths
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ compiler = (*baseCompiler)(nil)
|
|
|
|
|
2017-01-11 01:21:22 +01:00
|
|
|
type CompiledInterface interface {
|
|
|
|
Srcs() android.Paths
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) Srcs() android.Paths {
|
2018-03-28 01:19:42 +02:00
|
|
|
return append(android.Paths{}, compiler.srcs...)
|
2017-01-11 01:21:22 +01:00
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func (compiler *baseCompiler) appendCflags(flags []string) {
|
|
|
|
compiler.Properties.Cflags = append(compiler.Properties.Cflags, flags...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) appendAsflags(flags []string) {
|
|
|
|
compiler.Properties.Asflags = append(compiler.Properties.Asflags, flags...)
|
|
|
|
}
|
|
|
|
|
2016-08-01 22:20:05 +02:00
|
|
|
func (compiler *baseCompiler) compilerProps() []interface{} {
|
2016-11-03 22:38:52 +01:00
|
|
|
return []interface{}{&compiler.Properties, &compiler.Proto}
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 22:20:05 +02:00
|
|
|
func (compiler *baseCompiler) compilerInit(ctx BaseModuleContext) {}
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2016-12-14 02:06:13 +01:00
|
|
|
func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-07-29 21:48:20 +02:00
|
|
|
deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...)
|
2020-07-04 20:54:35 +02:00
|
|
|
deps.GeneratedSources = removeListFromList(deps.GeneratedSources, compiler.Properties.Exclude_generated_sources)
|
2016-07-29 21:48:20 +02:00
|
|
|
deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...)
|
|
|
|
|
2019-03-29 03:30:56 +01:00
|
|
|
android.ProtoDeps(ctx, &compiler.Proto)
|
2016-11-03 04:44:08 +01:00
|
|
|
if compiler.hasSrcExt(".proto") {
|
2017-11-07 19:57:05 +01:00
|
|
|
deps = protoDeps(ctx, deps, &compiler.Proto, Bool(compiler.Properties.Proto.Static))
|
2016-10-21 01:11:43 +02:00
|
|
|
}
|
|
|
|
|
2017-12-20 08:08:09 +01:00
|
|
|
if Bool(compiler.Properties.Openmp) {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libomp")
|
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2020-08-18 08:37:17 +02:00
|
|
|
func (compiler *baseCompiler) useApexNameMacro() bool {
|
|
|
|
return Bool(compiler.Properties.Use_apex_name_macro) || compiler.Properties.UseApexNameMacro
|
|
|
|
}
|
|
|
|
|
2017-11-14 23:09:14 +01:00
|
|
|
// Return true if the module is in the WarningAllowedProjects.
|
|
|
|
func warningsAreAllowed(subdir string) bool {
|
|
|
|
subdir += "/"
|
2020-02-11 16:54:35 +01:00
|
|
|
return android.HasAnyPrefix(subdir, config.WarningAllowedProjects)
|
2017-11-14 23:09:14 +01:00
|
|
|
}
|
|
|
|
|
2019-02-04 20:22:08 +01:00
|
|
|
func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) {
|
|
|
|
getNamedMapForConfig(ctx.Config(), key).Store(module, true)
|
2017-11-14 23:09:14 +01:00
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
// Create a Flags struct that collects the compile flags from global values,
|
|
|
|
// per-target values, module type values, and per-module Blueprints properties
|
2017-11-16 23:33:08 +01:00
|
|
|
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
|
2016-07-29 22:44:28 +02:00
|
|
|
tc := ctx.toolchain()
|
2019-10-08 11:27:17 +02:00
|
|
|
modulePath := android.PathForModuleSrc(ctx).String()
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2019-03-06 07:25:09 +01:00
|
|
|
compiler.srcsBeforeGen = android.PathsForModuleSrcExcludes(ctx, compiler.Properties.Srcs, compiler.Properties.Exclude_srcs)
|
2017-11-16 23:33:08 +01:00
|
|
|
compiler.srcsBeforeGen = append(compiler.srcsBeforeGen, deps.GeneratedSources...)
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags)
|
|
|
|
CheckBadCompilerFlags(ctx, "cppflags", compiler.Properties.Cppflags)
|
|
|
|
CheckBadCompilerFlags(ctx, "conlyflags", compiler.Properties.Conlyflags)
|
|
|
|
CheckBadCompilerFlags(ctx, "asflags", compiler.Properties.Asflags)
|
2018-05-24 09:44:14 +02:00
|
|
|
CheckBadCompilerFlags(ctx, "vendor.cflags", compiler.Properties.Target.Vendor.Cflags)
|
2020-10-29 08:49:43 +01:00
|
|
|
CheckBadCompilerFlags(ctx, "product.cflags", compiler.Properties.Target.Product.Cflags)
|
2018-05-24 09:44:14 +02:00
|
|
|
CheckBadCompilerFlags(ctx, "recovery.cflags", compiler.Properties.Target.Recovery.Cflags)
|
2020-10-27 23:01:21 +01:00
|
|
|
CheckBadCompilerFlags(ctx, "vendor_ramdisk.cflags", compiler.Properties.Target.Vendor_ramdisk.Cflags)
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2019-02-28 20:00:01 +01:00
|
|
|
esc := proptools.NinjaAndShellEscapeList
|
2016-09-29 23:06:02 +02:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Cflags)...)
|
|
|
|
flags.Local.CppFlags = append(flags.Local.CppFlags, esc(compiler.Properties.Cppflags)...)
|
|
|
|
flags.Local.ConlyFlags = append(flags.Local.ConlyFlags, esc(compiler.Properties.Conlyflags)...)
|
|
|
|
flags.Local.AsFlags = append(flags.Local.AsFlags, esc(compiler.Properties.Asflags)...)
|
|
|
|
flags.Local.YasmFlags = append(flags.Local.YasmFlags, esc(compiler.Properties.Asflags)...)
|
2019-04-11 07:59:54 +02:00
|
|
|
|
|
|
|
flags.Yacc = compiler.Properties.Yacc
|
2020-07-15 10:58:56 +02:00
|
|
|
flags.Lex = compiler.Properties.Lex
|
2016-07-29 21:48:20 +02:00
|
|
|
|
|
|
|
// Include dir cflags
|
|
|
|
localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs)
|
2016-11-03 23:53:42 +01:00
|
|
|
if len(localIncludeDirs) > 0 {
|
2017-04-26 23:55:27 +02:00
|
|
|
f := includeDirsToFlags(localIncludeDirs)
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CommonFlags = append(flags.Local.CommonFlags, f)
|
|
|
|
flags.Local.YasmFlags = append(flags.Local.YasmFlags, f)
|
2016-11-03 23:53:42 +01:00
|
|
|
}
|
|
|
|
rootIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Include_dirs)
|
|
|
|
if len(rootIncludeDirs) > 0 {
|
2017-04-26 23:55:27 +02:00
|
|
|
f := includeDirsToFlags(rootIncludeDirs)
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CommonFlags = append(flags.Local.CommonFlags, f)
|
|
|
|
flags.Local.YasmFlags = append(flags.Local.YasmFlags, f)
|
2016-11-03 23:53:42 +01:00
|
|
|
}
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2018-12-06 20:04:03 +01:00
|
|
|
if compiler.Properties.Include_build_directory == nil ||
|
|
|
|
*compiler.Properties.Include_build_directory {
|
2019-10-08 11:27:17 +02:00
|
|
|
flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+modulePath)
|
|
|
|
flags.Local.YasmFlags = append(flags.Local.YasmFlags, "-I"+modulePath)
|
2018-12-06 20:04:03 +01:00
|
|
|
}
|
2017-11-03 21:31:05 +01:00
|
|
|
|
|
|
|
if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() {
|
|
|
|
flags.SystemIncludeFlags = append(flags.SystemIncludeFlags,
|
|
|
|
"${config.CommonGlobalIncludes}",
|
2020-05-27 14:47:32 +02:00
|
|
|
tc.IncludeFlags())
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2017-09-28 02:01:44 +02:00
|
|
|
if ctx.useSdk() {
|
2018-11-15 06:22:00 +01:00
|
|
|
// TODO: Switch to --sysroot.
|
2016-07-29 21:48:20 +02:00
|
|
|
// The NDK headers are installed to a common sysroot. While a more
|
|
|
|
// typical Soong approach would be to only make the headers for the
|
|
|
|
// library you're using available, we're trying to emulate the NDK
|
|
|
|
// behavior here, and the NDK always has all the NDK headers available.
|
2017-03-31 00:03:04 +02:00
|
|
|
flags.SystemIncludeFlags = append(flags.SystemIncludeFlags,
|
2016-07-29 21:48:20 +02:00
|
|
|
"-isystem "+getCurrentIncludePath(ctx).String(),
|
2018-03-16 02:44:57 +01:00
|
|
|
"-isystem "+getCurrentIncludePath(ctx).Join(ctx, config.NDKTriple(tc)).String())
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2017-09-28 02:01:44 +02:00
|
|
|
if ctx.useVndk() {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VNDK__")
|
2017-03-19 21:44:32 +01:00
|
|
|
}
|
|
|
|
|
2018-06-08 18:32:54 +02:00
|
|
|
if ctx.inRecovery() {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_RECOVERY__")
|
2018-06-08 18:32:54 +02:00
|
|
|
}
|
|
|
|
|
2020-08-13 20:24:56 +02:00
|
|
|
if ctx.apexVariationName() != "" {
|
2020-03-02 09:44:33 +01:00
|
|
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_APEX__")
|
2020-08-18 08:37:17 +02:00
|
|
|
if compiler.useApexNameMacro() {
|
2020-08-13 20:24:56 +02:00
|
|
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_APEX_"+makeDefineString(ctx.apexVariationName())+"__")
|
2020-08-18 08:37:17 +02:00
|
|
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_APEX_NAME__='\""+ctx.apexVariationName()+"\"'")
|
2020-03-02 09:44:33 +01:00
|
|
|
}
|
2020-03-21 15:20:55 +01:00
|
|
|
if ctx.Device() {
|
2020-07-23 07:32:17 +02:00
|
|
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags,
|
2020-11-18 00:29:36 +01:00
|
|
|
fmt.Sprintf("-D__ANDROID_APEX_MIN_SDK_VERSION__=%d",
|
2020-07-23 07:32:17 +02:00
|
|
|
ctx.apexSdkVersion().FinalOrFutureInt()))
|
2020-03-21 15:20:55 +01:00
|
|
|
}
|
2019-01-19 11:24:06 +01:00
|
|
|
}
|
|
|
|
|
2020-09-17 03:07:31 +02:00
|
|
|
if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
|
|
|
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_NATIVE_BRIDGE__")
|
|
|
|
}
|
|
|
|
|
2017-11-07 19:57:05 +01:00
|
|
|
instructionSet := String(compiler.Properties.Instruction_set)
|
2016-07-29 21:48:20 +02:00
|
|
|
if flags.RequiredInstructionSet != "" {
|
|
|
|
instructionSet = flags.RequiredInstructionSet
|
|
|
|
}
|
2018-10-08 05:54:34 +02:00
|
|
|
instructionSetFlags, err := tc.ClangInstructionSetFlags(instructionSet)
|
2016-07-29 21:48:20 +02:00
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("%s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags)
|
|
|
|
|
|
|
|
// TODO: debug
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Release.Cflags)...)
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2018-10-08 05:54:34 +02:00
|
|
|
CheckBadCompilerFlags(ctx, "clang_cflags", compiler.Properties.Clang_cflags)
|
|
|
|
CheckBadCompilerFlags(ctx, "clang_asflags", compiler.Properties.Clang_asflags)
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = config.ClangFilterUnknownCflags(flags.Local.CFlags)
|
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Clang_cflags)...)
|
|
|
|
flags.Local.AsFlags = append(flags.Local.AsFlags, esc(compiler.Properties.Clang_asflags)...)
|
|
|
|
flags.Local.CppFlags = config.ClangFilterUnknownCflags(flags.Local.CppFlags)
|
|
|
|
flags.Local.ConlyFlags = config.ClangFilterUnknownCflags(flags.Local.ConlyFlags)
|
|
|
|
flags.Local.LdFlags = config.ClangFilterUnknownCflags(flags.Local.LdFlags)
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2018-10-08 05:54:34 +02:00
|
|
|
target := "-target " + tc.ClangTriple()
|
2019-07-23 01:36:06 +02:00
|
|
|
if ctx.Os().Class == android.Device {
|
|
|
|
version := ctx.sdkVersion()
|
|
|
|
if version == "" || version == "current" {
|
2020-07-24 01:43:25 +02:00
|
|
|
target += strconv.Itoa(android.FutureApiLevelInt)
|
2019-07-23 01:36:06 +02:00
|
|
|
} else {
|
|
|
|
target += version
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-08 05:54:34 +02:00
|
|
|
gccPrefix := "-B" + config.ToolPath(tc)
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Global.CFlags = append(flags.Global.CFlags, target, gccPrefix)
|
|
|
|
flags.Global.AsFlags = append(flags.Global.AsFlags, target, gccPrefix)
|
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, target, gccPrefix)
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
hod := "Host"
|
2016-07-29 21:48:20 +02:00
|
|
|
if ctx.Os().Class == android.Device {
|
2016-07-29 22:44:28 +02:00
|
|
|
hod = "Device"
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags, instructionSetFlags)
|
|
|
|
flags.Global.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.Global.ConlyFlags...)
|
|
|
|
flags.Global.CppFlags = append([]string{fmt.Sprintf("${config.%sGlobalCppflags}", hod)}, flags.Global.CppFlags...)
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Global.AsFlags = append(flags.Global.AsFlags, tc.ClangAsflags())
|
|
|
|
flags.Global.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.Global.CppFlags...)
|
|
|
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags,
|
2018-10-08 05:54:34 +02:00
|
|
|
tc.ClangCflags(),
|
|
|
|
"${config.CommonClangGlobalCflags}",
|
|
|
|
fmt.Sprintf("${config.%sClangGlobalCflags}", hod))
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2019-10-08 11:27:17 +02:00
|
|
|
if isThirdParty(modulePath) {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Global.CommonFlags = append([]string{"${config.ClangExternalCflags}"}, flags.Global.CommonFlags...)
|
2018-06-06 23:42:44 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 03:42:46 +02:00
|
|
|
if tc.Bionic() {
|
2017-11-03 21:31:05 +01:00
|
|
|
if Bool(compiler.Properties.Rtti) {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CppFlags = append(flags.Local.CppFlags, "-frtti")
|
2016-07-29 21:48:20 +02:00
|
|
|
} else {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CppFlags = append(flags.Local.CppFlags, "-fno-rtti")
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
2017-11-03 21:31:05 +01:00
|
|
|
}
|
2016-12-03 02:13:24 +01:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Global.AsFlags = append(flags.Global.AsFlags, "-D__ASSEMBLY__")
|
2017-11-03 21:31:05 +01:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Global.CppFlags = append(flags.Global.CppFlags, tc.ClangCppflags())
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Global.YasmFlags = append(flags.Global.YasmFlags, tc.YasmFlags())
|
2017-11-03 21:31:05 +01:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags, tc.ToolchainClangCflags())
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2018-02-17 02:15:19 +01:00
|
|
|
cStd := config.CStdVersion
|
|
|
|
if String(compiler.Properties.C_std) == "experimental" {
|
|
|
|
cStd = config.ExperimentalCStdVersion
|
|
|
|
} else if String(compiler.Properties.C_std) != "" {
|
|
|
|
cStd = String(compiler.Properties.C_std)
|
|
|
|
}
|
2016-10-17 23:19:06 +02:00
|
|
|
|
2018-02-17 02:15:19 +01:00
|
|
|
cppStd := String(compiler.Properties.Cpp_std)
|
|
|
|
switch String(compiler.Properties.Cpp_std) {
|
|
|
|
case "":
|
|
|
|
cppStd = config.CppStdVersion
|
|
|
|
case "experimental":
|
|
|
|
cppStd = config.ExperimentalCppStdVersion
|
|
|
|
}
|
2016-10-17 23:19:06 +02:00
|
|
|
|
2018-02-17 02:15:19 +01:00
|
|
|
if compiler.Properties.Gnu_extensions != nil && *compiler.Properties.Gnu_extensions == false {
|
|
|
|
cStd = gnuToCReplacer.Replace(cStd)
|
|
|
|
cppStd = gnuToCReplacer.Replace(cppStd)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.ConlyFlags = append([]string{"-std=" + cStd}, flags.Local.ConlyFlags...)
|
|
|
|
flags.Local.CppFlags = append([]string{"-std=" + cppStd}, flags.Local.CppFlags...)
|
2018-02-17 02:15:19 +01:00
|
|
|
|
2020-10-29 08:49:43 +01:00
|
|
|
if ctx.inVendor() {
|
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Vendor.Cflags)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.inProduct() {
|
|
|
|
// TODO(b/150902910): must use 'compiler.Properties.Target.Product.Cflags'
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Vendor.Cflags)...)
|
2017-08-10 06:33:27 +02:00
|
|
|
}
|
|
|
|
|
2018-05-24 09:44:14 +02:00
|
|
|
if ctx.inRecovery() {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Recovery.Cflags)...)
|
2018-05-24 09:44:14 +02:00
|
|
|
}
|
|
|
|
|
2020-10-27 23:01:21 +01:00
|
|
|
if ctx.inVendorRamdisk() {
|
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Vendor_ramdisk.Cflags)...)
|
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
// We can enforce some rules more strictly in the code we own. strict
|
|
|
|
// indicates if this is code that we can be stricter with. If we have
|
|
|
|
// rules that we want to apply to *our* code (but maybe can't for
|
|
|
|
// vendor/device specific things), we could extend this to be a ternary
|
|
|
|
// value.
|
|
|
|
strict := true
|
2019-10-08 11:27:17 +02:00
|
|
|
if strings.HasPrefix(modulePath, "external/") {
|
2016-07-29 21:48:20 +02:00
|
|
|
strict = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can be used to make some annotations stricter for code we can fix
|
|
|
|
// (such as when we mark functions as deprecated).
|
|
|
|
if strict {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Global.CFlags = append(flags.Global.CFlags, "-DANDROID_STRICT")
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-11-03 04:44:08 +01:00
|
|
|
if compiler.hasSrcExt(".proto") {
|
2016-10-21 01:11:43 +02:00
|
|
|
flags = protoFlags(ctx, flags, &compiler.Proto)
|
|
|
|
}
|
|
|
|
|
2016-11-03 04:44:08 +01:00
|
|
|
if compiler.hasSrcExt(".y") || compiler.hasSrcExt(".yy") {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CommonFlags = append(flags.Local.CommonFlags,
|
2016-11-03 04:44:08 +01:00
|
|
|
"-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String())
|
|
|
|
}
|
|
|
|
|
2017-09-09 10:15:26 +02:00
|
|
|
if compiler.hasSrcExt(".mc") {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CommonFlags = append(flags.Local.CommonFlags,
|
2017-09-09 10:15:26 +02:00
|
|
|
"-I"+android.PathForModuleGen(ctx, "windmc", ctx.ModuleDir()).String())
|
|
|
|
}
|
|
|
|
|
2016-11-03 22:28:51 +01:00
|
|
|
if compiler.hasSrcExt(".aidl") {
|
|
|
|
if len(compiler.Properties.Aidl.Local_include_dirs) > 0 {
|
|
|
|
localAidlIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Aidl.Local_include_dirs)
|
|
|
|
flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(localAidlIncludeDirs))
|
|
|
|
}
|
|
|
|
if len(compiler.Properties.Aidl.Include_dirs) > 0 {
|
|
|
|
rootAidlIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Aidl.Include_dirs)
|
|
|
|
flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(rootAidlIncludeDirs))
|
|
|
|
}
|
|
|
|
|
2018-03-09 09:29:59 +01:00
|
|
|
if Bool(compiler.Properties.Aidl.Generate_traces) {
|
|
|
|
flags.aidlFlags = append(flags.aidlFlags, "-t")
|
|
|
|
}
|
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CommonFlags = append(flags.Local.CommonFlags,
|
2016-11-03 22:28:51 +01:00
|
|
|
"-I"+android.PathForModuleGen(ctx, "aidl").String())
|
|
|
|
}
|
|
|
|
|
2019-07-16 04:08:37 +02:00
|
|
|
if compiler.hasSrcExt(".rscript") || compiler.hasSrcExt(".fs") {
|
2017-05-02 02:37:24 +02:00
|
|
|
flags = rsFlags(ctx, flags, &compiler.Properties)
|
|
|
|
}
|
|
|
|
|
2018-09-05 17:55:20 +02:00
|
|
|
if compiler.hasSrcExt(".sysprop") {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CommonFlags = append(flags.Local.CommonFlags,
|
2018-09-05 17:55:20 +02:00
|
|
|
"-I"+android.PathForModuleGen(ctx, "sysprop", "include").String())
|
|
|
|
}
|
|
|
|
|
2017-11-14 23:09:14 +01:00
|
|
|
if len(compiler.Properties.Srcs) > 0 {
|
|
|
|
module := ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName()
|
2019-11-04 18:37:55 +01:00
|
|
|
if inList("-Wno-error", flags.Local.CFlags) || inList("-Wno-error", flags.Local.CppFlags) {
|
2019-02-04 20:22:08 +01:00
|
|
|
addToModuleList(ctx, modulesUsingWnoErrorKey, module)
|
2019-11-04 18:37:55 +01:00
|
|
|
} else if !inList("-Werror", flags.Local.CFlags) && !inList("-Werror", flags.Local.CppFlags) {
|
2017-11-14 23:09:14 +01:00
|
|
|
if warningsAreAllowed(ctx.ModuleDir()) {
|
2019-02-04 20:22:08 +01:00
|
|
|
addToModuleList(ctx, modulesAddedWallKey, module)
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append([]string{"-Wall"}, flags.Local.CFlags...)
|
2017-11-14 23:09:14 +01:00
|
|
|
} else {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append([]string{"-Wall", "-Werror"}, flags.Local.CFlags...)
|
2017-11-14 23:09:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 08:08:09 +01:00
|
|
|
if Bool(compiler.Properties.Openmp) {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-fopenmp")
|
2017-12-20 08:08:09 +01:00
|
|
|
}
|
|
|
|
|
2020-06-11 20:32:11 +02:00
|
|
|
// Exclude directories from manual binder interface allowed list.
|
2019-11-26 19:32:50 +01:00
|
|
|
//TODO(b/145621474): Move this check into IInterface.h when clang-tidy no longer uses absolute paths.
|
2020-02-11 16:54:35 +01:00
|
|
|
if android.HasAnyPrefix(ctx.ModuleDir(), allowedManualInterfacePaths) {
|
2019-11-26 19:32:50 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DDO_NOT_CHECK_MANUAL_BINDER_INTERFACES")
|
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2016-11-03 04:44:08 +01:00
|
|
|
func (compiler *baseCompiler) hasSrcExt(ext string) bool {
|
2017-11-16 23:33:08 +01:00
|
|
|
for _, src := range compiler.srcsBeforeGen {
|
|
|
|
if src.Ext() == ext {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2016-10-21 01:11:43 +02:00
|
|
|
for _, src := range compiler.Properties.Srcs {
|
2016-11-03 04:44:08 +01:00
|
|
|
if filepath.Ext(src) == ext {
|
2016-10-21 01:11:43 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2017-05-03 20:01:58 +02:00
|
|
|
for _, src := range compiler.Properties.OriginalSrcs {
|
|
|
|
if filepath.Ext(src) == ext {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2016-10-21 01:11:43 +02:00
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
Reland: Deduplicate APEX variants that would build identically
APEX variants that share the same SDK version and updatability
almost always use identical command line arguments to build but
with different intermediates directories. This causes unnecessary
build time and disk space for duplicated work.
Deduplicate APEX variants that would build identically. Create
aliases from the per-APEX variations to the new shared variations
so that the APEX modules can continue to depend on them via the
APEX name as the variation.
This has one significant change in behavior. Before this change,
if an APEX had two libraries in its direct dependencies and one
of those libraries depended on the other, and the second library
had stubs, then the first library would depend on the implementation
of the second library and not the stubs. After this change, if
the first library is also present in a second APEX but the second
library is not, then the common variant shared between the two
APEXes would use the stubs, not the implementation.
In a correctly configured set of build rules this change will
be irrelevant, because if the compilation worked for the second
APEX using stubs then it will work for the common variant using
stubs. However, if an incorrect change to the build rules is
made this could lead to confusing errors, as a previously-working
common variant could suddenly stop building when a module is added
to a new APEX without its dependencies that require implementation
APIs to compile.
This change reduces the number of modules in an AOSP arm64-userdebug
build by 3% (52242 to 50586), reduces the number of variants of the
libcutils module from 74 to 53, and reduces the number of variants
of the massive libart[d] modules from 44 to 32.
This relands I0529837476a253c32b3dfb98dcccf107427c742c with a fix
to always mark permissions XML files of java_sdk_library modules as
unique per apex since they contain the APEX filename, and a fix
to UpdateUniqueApexVariationsForDeps to check ApexInfo.InApexes
instead of DepIsInSameApex to check if two modules are in the same
apex to account for a module that depends on another in a way that
doesn't normally include the dependency in the APEX (e.g. a libs
property), but the dependency is directly included in the APEX.
Bug: 164216768
Test: go test ./build/soong/apex/...
Change-Id: I2ae170601f764e5b88d0be2e0e6adc84e3a4d9cc
2020-08-11 21:17:01 +02:00
|
|
|
func (compiler *baseCompiler) uniqueApexVariations() bool {
|
2020-08-18 08:37:17 +02:00
|
|
|
return compiler.useApexNameMacro()
|
Reland: Deduplicate APEX variants that would build identically
APEX variants that share the same SDK version and updatability
almost always use identical command line arguments to build but
with different intermediates directories. This causes unnecessary
build time and disk space for duplicated work.
Deduplicate APEX variants that would build identically. Create
aliases from the per-APEX variations to the new shared variations
so that the APEX modules can continue to depend on them via the
APEX name as the variation.
This has one significant change in behavior. Before this change,
if an APEX had two libraries in its direct dependencies and one
of those libraries depended on the other, and the second library
had stubs, then the first library would depend on the implementation
of the second library and not the stubs. After this change, if
the first library is also present in a second APEX but the second
library is not, then the common variant shared between the two
APEXes would use the stubs, not the implementation.
In a correctly configured set of build rules this change will
be irrelevant, because if the compilation worked for the second
APEX using stubs then it will work for the common variant using
stubs. However, if an incorrect change to the build rules is
made this could lead to confusing errors, as a previously-working
common variant could suddenly stop building when a module is added
to a new APEX without its dependencies that require implementation
APIs to compile.
This change reduces the number of modules in an AOSP arm64-userdebug
build by 3% (52242 to 50586), reduces the number of variants of the
libcutils module from 74 to 53, and reduces the number of variants
of the massive libart[d] modules from 44 to 32.
This relands I0529837476a253c32b3dfb98dcccf107427c742c with a fix
to always mark permissions XML files of java_sdk_library modules as
unique per apex since they contain the APEX filename, and a fix
to UpdateUniqueApexVariationsForDeps to check ApexInfo.InApexes
instead of DepIsInSameApex to check if two modules are in the same
apex to account for a module that depends on another in a way that
doesn't normally include the dependency in the APEX (e.g. a libs
property), but the dependency is directly included in the APEX.
Bug: 164216768
Test: go test ./build/soong/apex/...
Change-Id: I2ae170601f764e5b88d0be2e0e6adc84e3a4d9cc
2020-08-11 21:17:01 +02:00
|
|
|
}
|
|
|
|
|
2020-09-10 03:48:40 +02:00
|
|
|
var invalidDefineCharRegex = regexp.MustCompile("[^a-zA-Z0-9_]")
|
|
|
|
|
2019-10-18 09:26:16 +02:00
|
|
|
// makeDefineString transforms a name of an APEX module into a value to be used as value for C define
|
|
|
|
// For example, com.android.foo => COM_ANDROID_FOO
|
|
|
|
func makeDefineString(name string) string {
|
2020-09-10 03:48:40 +02:00
|
|
|
return invalidDefineCharRegex.ReplaceAllString(strings.ToUpper(name), "_")
|
2019-10-18 09:26:16 +02:00
|
|
|
}
|
|
|
|
|
2016-10-17 23:24:56 +02:00
|
|
|
var gnuToCReplacer = strings.NewReplacer("gnu", "c")
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func ndkPathDeps(ctx ModuleContext) android.Paths {
|
2020-07-15 22:33:30 +02:00
|
|
|
if ctx.Module().(*Module).IsSdkVariant() {
|
2016-07-29 21:48:20 +02:00
|
|
|
// The NDK sysroot timestamp file depends on all the NDK sysroot files
|
|
|
|
// (headers and libraries).
|
2017-12-14 00:05:04 +01:00
|
|
|
return android.Paths{getNdkBaseTimestampFile(ctx)}
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-09-27 02:33:01 +02:00
|
|
|
func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
|
2019-12-06 05:15:38 +01:00
|
|
|
pathDeps := deps.GeneratedDeps
|
2016-07-29 21:48:20 +02:00
|
|
|
pathDeps = append(pathDeps, ndkPathDeps(ctx)...)
|
2016-10-26 19:03:47 +02:00
|
|
|
|
|
|
|
buildFlags := flagsToBuilderFlags(flags)
|
|
|
|
|
2017-11-16 23:33:08 +01:00
|
|
|
srcs := append(android.Paths(nil), compiler.srcsBeforeGen...)
|
|
|
|
|
2020-07-24 19:19:23 +02:00
|
|
|
srcs, genDeps := genSources(ctx, srcs, buildFlags)
|
2018-01-23 19:49:04 +01:00
|
|
|
pathDeps = append(pathDeps, genDeps...)
|
2016-10-26 19:03:47 +02:00
|
|
|
|
2017-12-20 00:11:01 +01:00
|
|
|
compiler.pathDeps = pathDeps
|
2018-01-23 19:49:04 +01:00
|
|
|
compiler.cFlagsDeps = flags.CFlagsDeps
|
2016-10-26 19:03:47 +02:00
|
|
|
|
2017-01-11 01:21:22 +01:00
|
|
|
// Save src, buildFlags and context
|
|
|
|
compiler.srcs = srcs
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
// Compile files listed in c.Properties.Srcs into objects
|
2018-01-23 19:49:04 +01:00
|
|
|
objs := compileObjs(ctx, buildFlags, "", srcs, pathDeps, compiler.cFlagsDeps)
|
2016-07-29 21:48:20 +02:00
|
|
|
|
|
|
|
if ctx.Failed() {
|
2016-09-27 02:33:01 +02:00
|
|
|
return Objects{}
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-09-27 02:33:01 +02:00
|
|
|
return objs
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compile a list of source files into objects a specified subdirectory
|
2016-10-26 19:03:47 +02:00
|
|
|
func compileObjs(ctx android.ModuleContext, flags builderFlags,
|
2018-01-23 19:49:04 +01:00
|
|
|
subdir string, srcFiles, pathDeps android.Paths, cFlagsDeps android.Paths) Objects {
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
return transformSourceToObj(ctx, subdir, srcFiles, flags, pathDeps, cFlagsDeps)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
2019-10-08 11:27:17 +02:00
|
|
|
|
|
|
|
var thirdPartyDirPrefixExceptions = []*regexp.Regexp{
|
|
|
|
regexp.MustCompile("^vendor/[^/]*google[^/]*/"),
|
|
|
|
regexp.MustCompile("^hardware/google/"),
|
|
|
|
regexp.MustCompile("^hardware/interfaces/"),
|
|
|
|
regexp.MustCompile("^hardware/libhardware[^/]*/"),
|
|
|
|
regexp.MustCompile("^hardware/ril/"),
|
|
|
|
}
|
|
|
|
|
|
|
|
func isThirdParty(path string) bool {
|
|
|
|
thirdPartyDirPrefixes := []string{"external/", "vendor/", "hardware/"}
|
|
|
|
|
2020-02-11 16:54:35 +01:00
|
|
|
if android.HasAnyPrefix(path, thirdPartyDirPrefixes) {
|
|
|
|
for _, prefix := range thirdPartyDirPrefixExceptions {
|
|
|
|
if prefix.MatchString(path) {
|
|
|
|
return false
|
2019-10-08 11:27:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2020-09-25 22:08:34 +02:00
|
|
|
|
|
|
|
// Properties for rust_bindgen related to generating rust bindings.
|
|
|
|
// This exists here so these properties can be included in a cc_default
|
|
|
|
// which can be used in both cc and rust modules.
|
|
|
|
type RustBindgenClangProperties struct {
|
|
|
|
// list of directories relative to the Blueprints file that will
|
|
|
|
// be added to the include path using -I
|
|
|
|
Local_include_dirs []string `android:"arch_variant,variant_prepend"`
|
|
|
|
|
|
|
|
// list of static libraries that provide headers for this binding.
|
|
|
|
Static_libs []string `android:"arch_variant,variant_prepend"`
|
|
|
|
|
|
|
|
// list of shared libraries that provide headers for this binding.
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
|
2020-11-17 19:39:30 +01:00
|
|
|
// List of libraries which export include paths required for this module
|
|
|
|
Header_libs []string `android:"arch_variant,variant_prepend"`
|
|
|
|
|
2020-09-25 22:08:34 +02:00
|
|
|
// list of clang flags required to correctly interpret the headers.
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of c++ specific clang flags required to correctly interpret the headers.
|
|
|
|
// This is provided primarily to make sure cppflags defined in cc_defaults are pulled in.
|
|
|
|
Cppflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// C standard version to use. Can be a specific version (such as "gnu11"),
|
|
|
|
// "experimental" (which will use draft versions like C1x when available),
|
|
|
|
// or the empty string (which will use the default).
|
|
|
|
//
|
|
|
|
// If this is set, the file extension will be ignored and this will be used as the std version value. Setting this
|
|
|
|
// to "default" will use the build system default version. This cannot be set at the same time as cpp_std.
|
|
|
|
C_std *string
|
|
|
|
|
|
|
|
// C++ standard version to use. Can be a specific version (such as
|
|
|
|
// "gnu++11"), "experimental" (which will use draft versions like C++1z when
|
|
|
|
// available), or the empty string (which will use the default).
|
|
|
|
//
|
|
|
|
// If this is set, the file extension will be ignored and this will be used as the std version value. Setting this
|
|
|
|
// to "default" will use the build system default version. This cannot be set at the same time as c_std.
|
|
|
|
Cpp_std *string
|
|
|
|
|
|
|
|
//TODO(b/161141999) Add support for headers from cc_library_header modules.
|
|
|
|
}
|