2017-11-17 19:55:38 +01:00
|
|
|
// Copyright 2017 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.
|
|
|
|
|
2017-01-11 01:21:22 +01:00
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// This singleton generates CMakeLists.txt files. It does so for each blueprint Android.bp resulting in a cc.Module
|
|
|
|
// when either make, mm, mma, mmm or mmma is called. CMakeLists.txt files are generated in a separate folder
|
|
|
|
// structure (see variable CLionOutputProjectsDirectory for root).
|
|
|
|
|
|
|
|
func init() {
|
2023-05-16 02:58:37 +02:00
|
|
|
android.RegisterParallelSingletonType("cmakelists_generator", cMakeListsGeneratorSingleton)
|
2017-01-11 01:21:22 +01:00
|
|
|
}
|
|
|
|
|
2017-11-29 02:34:01 +01:00
|
|
|
func cMakeListsGeneratorSingleton() android.Singleton {
|
2017-01-11 01:21:22 +01:00
|
|
|
return &cmakelistsGeneratorSingleton{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type cmakelistsGeneratorSingleton struct{}
|
|
|
|
|
|
|
|
const (
|
|
|
|
cMakeListsFilename = "CMakeLists.txt"
|
|
|
|
cLionAggregateProjectsDirectory = "development" + string(os.PathSeparator) + "ide" + string(os.PathSeparator) + "clion"
|
|
|
|
cLionOutputProjectsDirectory = "out" + string(os.PathSeparator) + cLionAggregateProjectsDirectory
|
|
|
|
minimumCMakeVersionSupported = "3.5"
|
|
|
|
|
|
|
|
// Environment variables used to modify behavior of this singleton.
|
|
|
|
envVariableGenerateCMakeLists = "SOONG_GEN_CMAKEFILES"
|
|
|
|
envVariableGenerateDebugInfo = "SOONG_GEN_CMAKEFILES_DEBUG"
|
|
|
|
envVariableTrue = "1"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Instruct generator to trace how header include path and flags were generated.
|
|
|
|
// This is done to ease investigating bug reports.
|
|
|
|
var outputDebugInfo = false
|
|
|
|
|
2017-11-29 02:34:01 +01:00
|
|
|
func (c *cmakelistsGeneratorSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
2017-01-11 01:21:22 +01:00
|
|
|
if getEnvVariable(envVariableGenerateCMakeLists, ctx) != envVariableTrue {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
outputDebugInfo = (getEnvVariable(envVariableGenerateDebugInfo, ctx) == envVariableTrue)
|
|
|
|
|
2018-06-07 23:16:27 +02:00
|
|
|
// Track which projects have already had CMakeLists.txt generated to keep the first
|
|
|
|
// variant for each project.
|
|
|
|
seenProjects := map[string]bool{}
|
|
|
|
|
2017-11-29 02:34:01 +01:00
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
2017-01-11 01:21:22 +01:00
|
|
|
if ccModule, ok := module.(*Module); ok {
|
|
|
|
if compiledModule, ok := ccModule.compiler.(CompiledInterface); ok {
|
2018-06-07 23:16:27 +02:00
|
|
|
generateCLionProject(compiledModule, ctx, ccModule, seenProjects)
|
2017-01-11 01:21:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Link all handmade CMakeLists.txt aggregate from
|
|
|
|
// BASE/development/ide/clion to
|
|
|
|
// BASE/out/development/ide/clion.
|
2020-01-11 02:11:46 +01:00
|
|
|
dir := filepath.Join(android.AbsSrcDirForExistingUseCases(), cLionAggregateProjectsDirectory)
|
2017-01-11 01:21:22 +01:00
|
|
|
filepath.Walk(dir, linkAggregateCMakeListsFiles)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-29 02:34:01 +01:00
|
|
|
func getEnvVariable(name string, ctx android.SingletonContext) string {
|
2017-01-11 01:21:22 +01:00
|
|
|
// Using android.Config.Getenv instead of os.getEnv to guarantee soong will
|
|
|
|
// re-run in case this environment variable changes.
|
2017-11-29 09:27:14 +01:00
|
|
|
return ctx.Config().Getenv(name)
|
2017-01-11 01:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func exists(path string) bool {
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
if err == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func linkAggregateCMakeListsFiles(path string, info os.FileInfo, err error) error {
|
|
|
|
|
|
|
|
if info == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
dst := strings.Replace(path, cLionAggregateProjectsDirectory, cLionOutputProjectsDirectory, 1)
|
|
|
|
if info.IsDir() {
|
|
|
|
// This is a directory to create
|
|
|
|
os.MkdirAll(dst, os.ModePerm)
|
|
|
|
} else {
|
|
|
|
// This is a file to link
|
|
|
|
os.Remove(dst)
|
|
|
|
os.Symlink(path, dst)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-06-07 23:16:27 +02:00
|
|
|
func generateCLionProject(compiledModule CompiledInterface, ctx android.SingletonContext, ccModule *Module,
|
|
|
|
seenProjects map[string]bool) {
|
2017-01-11 01:21:22 +01:00
|
|
|
srcs := compiledModule.Srcs()
|
|
|
|
if len(srcs) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-07 23:16:27 +02:00
|
|
|
// Only write CMakeLists.txt for the first variant of each architecture of each module
|
2020-12-21 18:11:10 +01:00
|
|
|
clionprojectLocation := getCMakeListsForModule(ccModule, ctx)
|
|
|
|
if seenProjects[clionprojectLocation] {
|
2018-06-07 23:16:27 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-12-21 18:11:10 +01:00
|
|
|
seenProjects[clionprojectLocation] = true
|
2018-06-07 23:16:27 +02:00
|
|
|
|
|
|
|
// Ensure the directory hosting the cmakelists.txt exists
|
2020-12-21 18:11:10 +01:00
|
|
|
projectDir := path.Dir(clionprojectLocation)
|
2017-01-11 01:21:22 +01:00
|
|
|
os.MkdirAll(projectDir, os.ModePerm)
|
|
|
|
|
|
|
|
// Create cmakelists.txt
|
|
|
|
f, _ := os.Create(filepath.Join(projectDir, cMakeListsFilename))
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
// Header.
|
|
|
|
f.WriteString("# THIS FILE WAS AUTOMATICALY GENERATED!\n")
|
|
|
|
f.WriteString("# ANY MODIFICATION WILL BE OVERWRITTEN!\n\n")
|
|
|
|
f.WriteString("# To improve project view in Clion :\n")
|
|
|
|
f.WriteString("# Tools > CMake > Change Project Root \n\n")
|
|
|
|
f.WriteString(fmt.Sprintf("cmake_minimum_required(VERSION %s)\n", minimumCMakeVersionSupported))
|
|
|
|
f.WriteString(fmt.Sprintf("project(%s)\n", ccModule.ModuleBase.Name()))
|
2020-01-11 02:11:46 +01:00
|
|
|
f.WriteString(fmt.Sprintf("set(ANDROID_ROOT %s)\n\n", android.AbsSrcDirForExistingUseCases()))
|
2017-01-11 01:21:22 +01:00
|
|
|
|
2018-10-08 05:54:34 +02:00
|
|
|
pathToCC, _ := evalVariable(ctx, "${config.ClangBin}/")
|
|
|
|
f.WriteString(fmt.Sprintf("set(CMAKE_C_COMPILER \"%s%s\")\n", buildCMakePath(pathToCC), "clang"))
|
|
|
|
f.WriteString(fmt.Sprintf("set(CMAKE_CXX_COMPILER \"%s%s\")\n", buildCMakePath(pathToCC), "clang++"))
|
|
|
|
|
2017-01-11 01:21:22 +01:00
|
|
|
// Add all sources to the project.
|
|
|
|
f.WriteString("list(APPEND\n")
|
|
|
|
f.WriteString(" SOURCE_FILES\n")
|
|
|
|
for _, src := range srcs {
|
|
|
|
f.WriteString(fmt.Sprintf(" ${ANDROID_ROOT}/%s\n", src.String()))
|
|
|
|
}
|
|
|
|
f.WriteString(")\n")
|
|
|
|
|
|
|
|
// Add all header search path and compiler parameters (-D, -W, -f, -XXXX)
|
2019-11-04 18:37:55 +01:00
|
|
|
f.WriteString("\n# GLOBAL ALL FLAGS:\n")
|
|
|
|
globalAllParameters := parseCompilerParameters(ccModule.flags.Global.CommonFlags, ctx, f)
|
|
|
|
translateToCMake(globalAllParameters, f, true, true)
|
2017-01-11 01:21:22 +01:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
f.WriteString("\n# LOCAL ALL FLAGS:\n")
|
|
|
|
localAllParameters := parseCompilerParameters(ccModule.flags.Local.CommonFlags, ctx, f)
|
|
|
|
translateToCMake(localAllParameters, f, true, true)
|
2017-01-11 01:21:22 +01:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
f.WriteString("\n# GLOBAL CFLAGS:\n")
|
|
|
|
globalCParameters := parseCompilerParameters(ccModule.flags.Global.CFlags, ctx, f)
|
|
|
|
translateToCMake(globalCParameters, f, true, true)
|
2017-01-11 01:21:22 +01:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
f.WriteString("\n# LOCAL CFLAGS:\n")
|
|
|
|
localCParameters := parseCompilerParameters(ccModule.flags.Local.CFlags, ctx, f)
|
|
|
|
translateToCMake(localCParameters, f, true, true)
|
2017-01-11 01:21:22 +01:00
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
f.WriteString("\n# GLOBAL C ONLY FLAGS:\n")
|
|
|
|
globalConlyParameters := parseCompilerParameters(ccModule.flags.Global.ConlyFlags, ctx, f)
|
|
|
|
translateToCMake(globalConlyParameters, f, true, false)
|
|
|
|
|
|
|
|
f.WriteString("\n# LOCAL C ONLY FLAGS:\n")
|
|
|
|
localConlyParameters := parseCompilerParameters(ccModule.flags.Local.ConlyFlags, ctx, f)
|
|
|
|
translateToCMake(localConlyParameters, f, true, false)
|
|
|
|
|
|
|
|
f.WriteString("\n# GLOBAL CPP FLAGS:\n")
|
|
|
|
globalCppParameters := parseCompilerParameters(ccModule.flags.Global.CppFlags, ctx, f)
|
|
|
|
translateToCMake(globalCppParameters, f, false, true)
|
|
|
|
|
|
|
|
f.WriteString("\n# LOCAL CPP FLAGS:\n")
|
|
|
|
localCppParameters := parseCompilerParameters(ccModule.flags.Local.CppFlags, ctx, f)
|
|
|
|
translateToCMake(localCppParameters, f, false, true)
|
|
|
|
|
|
|
|
f.WriteString("\n# GLOBAL SYSTEM INCLUDE FLAGS:\n")
|
|
|
|
globalIncludeParameters := parseCompilerParameters(ccModule.flags.SystemIncludeFlags, ctx, f)
|
|
|
|
translateToCMake(globalIncludeParameters, f, true, true)
|
2017-03-31 00:03:04 +02:00
|
|
|
|
2017-01-11 01:21:22 +01:00
|
|
|
// Add project executable.
|
2017-03-24 01:49:09 +01:00
|
|
|
f.WriteString(fmt.Sprintf("\nadd_executable(%s ${SOURCE_FILES})\n",
|
|
|
|
cleanExecutableName(ccModule.ModuleBase.Name())))
|
2017-01-11 01:21:22 +01:00
|
|
|
}
|
|
|
|
|
2017-03-24 01:49:09 +01:00
|
|
|
func cleanExecutableName(s string) string {
|
|
|
|
return strings.Replace(s, "@", "-", -1)
|
|
|
|
}
|
|
|
|
|
2017-01-11 01:21:22 +01:00
|
|
|
func translateToCMake(c compilerParameters, f *os.File, cflags bool, cppflags bool) {
|
2017-03-24 20:02:50 +01:00
|
|
|
writeAllIncludeDirectories(c.systemHeaderSearchPath, f, true)
|
|
|
|
writeAllIncludeDirectories(c.headerSearchPath, f, false)
|
2017-01-11 01:21:22 +01:00
|
|
|
if cflags {
|
2018-08-15 02:27:15 +02:00
|
|
|
writeAllRelativeFilePathFlags(c.relativeFilePathFlags, f, "CMAKE_C_FLAGS")
|
2017-01-11 01:21:22 +01:00
|
|
|
writeAllFlags(c.flags, f, "CMAKE_C_FLAGS")
|
|
|
|
}
|
|
|
|
if cppflags {
|
2018-08-15 02:27:15 +02:00
|
|
|
writeAllRelativeFilePathFlags(c.relativeFilePathFlags, f, "CMAKE_CXX_FLAGS")
|
2017-01-11 01:21:22 +01:00
|
|
|
writeAllFlags(c.flags, f, "CMAKE_CXX_FLAGS")
|
|
|
|
}
|
|
|
|
if c.sysroot != "" {
|
|
|
|
f.WriteString(fmt.Sprintf("include_directories(SYSTEM \"%s\")\n", buildCMakePath(path.Join(c.sysroot, "usr", "include"))))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildCMakePath(p string) string {
|
|
|
|
if path.IsAbs(p) {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("${ANDROID_ROOT}/%s", p)
|
|
|
|
}
|
|
|
|
|
2017-03-24 20:02:50 +01:00
|
|
|
func writeAllIncludeDirectories(includes []string, f *os.File, isSystem bool) {
|
2017-03-21 18:19:19 +01:00
|
|
|
if len(includes) == 0 {
|
|
|
|
return
|
|
|
|
}
|
2017-03-24 20:02:50 +01:00
|
|
|
|
|
|
|
system := ""
|
2017-05-09 22:44:49 +02:00
|
|
|
if isSystem {
|
2017-03-24 20:02:50 +01:00
|
|
|
system = "SYSTEM"
|
2017-01-11 01:21:22 +01:00
|
|
|
}
|
|
|
|
|
2017-03-24 20:02:50 +01:00
|
|
|
f.WriteString(fmt.Sprintf("include_directories(%s \n", system))
|
|
|
|
|
|
|
|
for _, include := range includes {
|
|
|
|
f.WriteString(fmt.Sprintf(" \"%s\"\n", buildCMakePath(include)))
|
2017-03-21 18:19:19 +01:00
|
|
|
}
|
2017-03-24 20:02:50 +01:00
|
|
|
f.WriteString(")\n\n")
|
|
|
|
|
|
|
|
// Also add all headers to source files.
|
2017-05-09 22:44:49 +02:00
|
|
|
f.WriteString("file (GLOB_RECURSE TMP_HEADERS\n")
|
2017-03-21 18:19:19 +01:00
|
|
|
for _, include := range includes {
|
2017-03-24 20:02:50 +01:00
|
|
|
f.WriteString(fmt.Sprintf(" \"%s/**/*.h\"\n", buildCMakePath(include)))
|
2017-01-11 01:21:22 +01:00
|
|
|
}
|
2017-03-21 18:19:19 +01:00
|
|
|
f.WriteString(")\n")
|
2017-05-09 22:44:49 +02:00
|
|
|
f.WriteString("list (APPEND SOURCE_FILES ${TMP_HEADERS})\n\n")
|
2017-01-11 01:21:22 +01:00
|
|
|
}
|
|
|
|
|
2018-08-15 02:27:15 +02:00
|
|
|
type relativeFilePathFlagType struct {
|
|
|
|
flag string
|
|
|
|
relativeFilePath string
|
|
|
|
}
|
|
|
|
|
|
|
|
func writeAllRelativeFilePathFlags(relativeFilePathFlags []relativeFilePathFlagType, f *os.File, tag string) {
|
|
|
|
for _, flag := range relativeFilePathFlags {
|
|
|
|
f.WriteString(fmt.Sprintf("set(%s \"${%s} %s=%s\")\n", tag, tag, flag.flag, buildCMakePath(flag.relativeFilePath)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 01:21:22 +01:00
|
|
|
func writeAllFlags(flags []string, f *os.File, tag string) {
|
|
|
|
for _, flag := range flags {
|
|
|
|
f.WriteString(fmt.Sprintf("set(%s \"${%s} %s\")\n", tag, tag, flag))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type parameterType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
headerSearchPath parameterType = iota
|
|
|
|
variable
|
|
|
|
systemHeaderSearchPath
|
|
|
|
flag
|
|
|
|
systemRoot
|
2018-08-15 02:27:15 +02:00
|
|
|
relativeFilePathFlag
|
2017-01-11 01:21:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type compilerParameters struct {
|
2017-03-21 18:19:19 +01:00
|
|
|
headerSearchPath []string
|
|
|
|
systemHeaderSearchPath []string
|
2017-01-11 01:21:22 +01:00
|
|
|
flags []string
|
|
|
|
sysroot string
|
2018-08-15 02:27:15 +02:00
|
|
|
// Must be in a=b/c/d format and can be split into "a" and "b/c/d"
|
|
|
|
relativeFilePathFlags []relativeFilePathFlagType
|
2017-01-11 01:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func makeCompilerParameters() compilerParameters {
|
|
|
|
return compilerParameters{
|
|
|
|
sysroot: "",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func categorizeParameter(parameter string) parameterType {
|
|
|
|
if strings.HasPrefix(parameter, "-I") {
|
|
|
|
return headerSearchPath
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(parameter, "$") {
|
|
|
|
return variable
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(parameter, "-isystem") {
|
|
|
|
return systemHeaderSearchPath
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(parameter, "-isysroot") {
|
|
|
|
return systemRoot
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(parameter, "--sysroot") {
|
|
|
|
return systemRoot
|
|
|
|
}
|
2021-08-28 00:12:56 +02:00
|
|
|
if strings.HasPrefix(parameter, "-fsanitize-ignorelist") {
|
2018-08-15 02:27:15 +02:00
|
|
|
return relativeFilePathFlag
|
|
|
|
}
|
2021-03-08 02:25:50 +01:00
|
|
|
if strings.HasPrefix(parameter, "-fprofile-sample-use") {
|
|
|
|
return relativeFilePathFlag
|
|
|
|
}
|
2017-01-11 01:21:22 +01:00
|
|
|
return flag
|
|
|
|
}
|
|
|
|
|
2019-11-06 01:18:47 +01:00
|
|
|
// Flattens a list of strings potentially containing space characters into a list of string containing no
|
|
|
|
// spaces.
|
|
|
|
func normalizeParameters(params []string) []string {
|
|
|
|
var flatParams []string
|
|
|
|
for _, s := range params {
|
|
|
|
s = strings.Trim(s, " ")
|
|
|
|
if len(s) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
flatParams = append(flatParams, strings.Split(s, " ")...)
|
|
|
|
}
|
|
|
|
return flatParams
|
|
|
|
}
|
|
|
|
|
2017-11-29 02:34:01 +01:00
|
|
|
func parseCompilerParameters(params []string, ctx android.SingletonContext, f *os.File) compilerParameters {
|
2017-01-11 01:21:22 +01:00
|
|
|
var compilerParameters = makeCompilerParameters()
|
|
|
|
|
|
|
|
for i, str := range params {
|
|
|
|
f.WriteString(fmt.Sprintf("# Raw param [%d] = '%s'\n", i, str))
|
|
|
|
}
|
|
|
|
|
2019-11-06 01:18:47 +01:00
|
|
|
// Soong does not guarantee that each flag will be in an individual string. e.g: The
|
|
|
|
// input received could be:
|
|
|
|
// params = {"-isystem", "path/to/system"}
|
|
|
|
// or it could be
|
|
|
|
// params = {"-isystem path/to/system"}
|
|
|
|
// To normalize the input, we split all strings with the "space" character and consolidate
|
|
|
|
// all tokens into a flattened parameters list
|
|
|
|
params = normalizeParameters(params)
|
|
|
|
|
2017-01-11 01:21:22 +01:00
|
|
|
for i := 0; i < len(params); i++ {
|
|
|
|
param := params[i]
|
|
|
|
if param == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
switch categorizeParameter(param) {
|
|
|
|
case headerSearchPath:
|
2017-03-21 18:19:19 +01:00
|
|
|
compilerParameters.headerSearchPath =
|
|
|
|
append(compilerParameters.headerSearchPath, strings.TrimPrefix(param, "-I"))
|
2017-01-11 01:21:22 +01:00
|
|
|
case variable:
|
|
|
|
if evaluated, error := evalVariable(ctx, param); error == nil {
|
|
|
|
if outputDebugInfo {
|
|
|
|
f.WriteString(fmt.Sprintf("# variable %s = '%s'\n", param, evaluated))
|
|
|
|
}
|
|
|
|
|
|
|
|
paramsFromVar := parseCompilerParameters(strings.Split(evaluated, " "), ctx, f)
|
|
|
|
concatenateParams(&compilerParameters, paramsFromVar)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if outputDebugInfo {
|
|
|
|
f.WriteString(fmt.Sprintf("# variable %s could NOT BE RESOLVED\n", param))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case systemHeaderSearchPath:
|
|
|
|
if i < len(params)-1 {
|
2017-03-21 18:19:19 +01:00
|
|
|
compilerParameters.systemHeaderSearchPath =
|
|
|
|
append(compilerParameters.systemHeaderSearchPath, params[i+1])
|
2017-01-11 01:21:22 +01:00
|
|
|
} else if outputDebugInfo {
|
|
|
|
f.WriteString("# Found a header search path marker with no path")
|
|
|
|
}
|
|
|
|
i = i + 1
|
|
|
|
case flag:
|
2017-02-06 18:49:58 +01:00
|
|
|
c := cleanupParameter(param)
|
|
|
|
f.WriteString(fmt.Sprintf("# FLAG '%s' became %s\n", param, c))
|
|
|
|
compilerParameters.flags = append(compilerParameters.flags, c)
|
2017-01-11 01:21:22 +01:00
|
|
|
case systemRoot:
|
|
|
|
if i < len(params)-1 {
|
|
|
|
compilerParameters.sysroot = params[i+1]
|
|
|
|
} else if outputDebugInfo {
|
|
|
|
f.WriteString("# Found a system root path marker with no path")
|
|
|
|
}
|
|
|
|
i = i + 1
|
2018-08-15 02:27:15 +02:00
|
|
|
case relativeFilePathFlag:
|
|
|
|
flagComponents := strings.Split(param, "=")
|
|
|
|
if len(flagComponents) == 2 {
|
|
|
|
flagStruct := relativeFilePathFlagType{flag: flagComponents[0], relativeFilePath: flagComponents[1]}
|
|
|
|
compilerParameters.relativeFilePathFlags = append(compilerParameters.relativeFilePathFlags, flagStruct)
|
|
|
|
} else {
|
|
|
|
if outputDebugInfo {
|
|
|
|
f.WriteString(fmt.Sprintf("# Relative File Path Flag [%s] is not formatted as a=b/c/d \n", param))
|
|
|
|
}
|
|
|
|
}
|
2017-01-11 01:21:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return compilerParameters
|
|
|
|
}
|
|
|
|
|
2017-02-06 18:49:58 +01:00
|
|
|
func cleanupParameter(p string) string {
|
|
|
|
// In the blueprint, c flags can be passed as:
|
|
|
|
// cflags: [ "-DLOG_TAG=\"libEGL\"", ]
|
|
|
|
// which becomes:
|
|
|
|
// '-DLOG_TAG="libEGL"' in soong.
|
|
|
|
// In order to be injected in CMakelists.txt we need to:
|
|
|
|
// - Remove the wrapping ' character
|
|
|
|
// - Double escape all special \ and " characters.
|
|
|
|
// For a end result like:
|
|
|
|
// -DLOG_TAG=\\\"libEGL\\\"
|
|
|
|
if !strings.HasPrefix(p, "'") || !strings.HasSuffix(p, "'") || len(p) < 3 {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reverse wrapper quotes and escaping that may have happened in NinjaAndShellEscape
|
|
|
|
// TODO: It is ok to reverse here for now but if NinjaAndShellEscape becomes more complex,
|
|
|
|
// we should create a method NinjaAndShellUnescape in escape.go and use that instead.
|
|
|
|
p = p[1 : len(p)-1]
|
|
|
|
p = strings.Replace(p, `'\''`, `'`, -1)
|
|
|
|
p = strings.Replace(p, `$$`, `$`, -1)
|
|
|
|
|
|
|
|
p = doubleEscape(p)
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
func escape(s string) string {
|
|
|
|
s = strings.Replace(s, `\`, `\\`, -1)
|
|
|
|
s = strings.Replace(s, `"`, `\"`, -1)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func doubleEscape(s string) string {
|
|
|
|
s = escape(s)
|
|
|
|
s = escape(s)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2017-01-11 01:21:22 +01:00
|
|
|
func concatenateParams(c1 *compilerParameters, c2 compilerParameters) {
|
2017-03-21 18:19:19 +01:00
|
|
|
c1.headerSearchPath = append(c1.headerSearchPath, c2.headerSearchPath...)
|
|
|
|
c1.systemHeaderSearchPath = append(c1.systemHeaderSearchPath, c2.systemHeaderSearchPath...)
|
2017-01-11 01:21:22 +01:00
|
|
|
if c2.sysroot != "" {
|
|
|
|
c1.sysroot = c2.sysroot
|
|
|
|
}
|
|
|
|
c1.flags = append(c1.flags, c2.flags...)
|
|
|
|
}
|
|
|
|
|
2017-11-29 02:34:01 +01:00
|
|
|
func evalVariable(ctx android.SingletonContext, str string) (string, error) {
|
2017-01-11 01:21:22 +01:00
|
|
|
evaluated, err := ctx.Eval(pctx, str)
|
|
|
|
if err == nil {
|
|
|
|
return evaluated, nil
|
|
|
|
}
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2017-11-29 02:34:01 +01:00
|
|
|
func getCMakeListsForModule(module *Module, ctx android.SingletonContext) string {
|
2020-01-11 02:11:46 +01:00
|
|
|
return filepath.Join(android.AbsSrcDirForExistingUseCases(),
|
2017-01-11 01:21:22 +01:00
|
|
|
cLionOutputProjectsDirectory,
|
|
|
|
path.Dir(ctx.BlueprintFile(module)),
|
|
|
|
module.ModuleBase.Name()+"-"+
|
|
|
|
module.ModuleBase.Arch().ArchType.Name+"-"+
|
|
|
|
module.ModuleBase.Os().Name,
|
|
|
|
cMakeListsFilename)
|
|
|
|
}
|