2015-04-08 07:50:10 +08:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
2018-09-05 23:55:20 +08:00
|
|
|
"path/filepath"
|
2019-06-05 08:10:41 +08:00
|
|
|
"strings"
|
2018-09-05 23:55:20 +08:00
|
|
|
|
2015-04-08 07:50:10 +08:00
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
"android/soong/android"
|
2015-04-08 07:50:10 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-07-25 01:19:23 +08:00
|
|
|
pctx.SourcePathVariable("lexCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/flex")
|
2020-07-24 05:37:35 +08:00
|
|
|
pctx.SourcePathVariable("m4Cmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/m4")
|
|
|
|
|
2016-11-04 05:28:51 +08:00
|
|
|
pctx.HostBinToolVariable("aidlCmd", "aidl-cpp")
|
2018-09-05 23:55:20 +08:00
|
|
|
pctx.HostBinToolVariable("syspropCmd", "sysprop_cpp")
|
2015-04-08 07:50:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2020-07-25 01:19:23 +08:00
|
|
|
lex = pctx.AndroidStaticRule("lex",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "M4=$m4Cmd $lexCmd -o$out $in",
|
|
|
|
CommandDeps: []string{"$lexCmd", "$m4Cmd"},
|
|
|
|
})
|
|
|
|
|
2018-09-05 23:55:20 +08:00
|
|
|
sysprop = pctx.AndroidStaticRule("sysprop",
|
|
|
|
blueprint.RuleParams{
|
2019-06-08 19:36:59 +08:00
|
|
|
Command: "$syspropCmd --header-dir=$headerOutDir --public-header-dir=$publicOutDir " +
|
2019-02-08 20:00:45 +08:00
|
|
|
"--source-dir=$srcOutDir --include-name=$includeName $in",
|
2018-09-05 23:55:20 +08:00
|
|
|
CommandDeps: []string{"$syspropCmd"},
|
|
|
|
},
|
2019-06-08 19:36:59 +08:00
|
|
|
"headerOutDir", "publicOutDir", "srcOutDir", "includeName")
|
2018-09-05 23:55:20 +08:00
|
|
|
|
2017-09-09 16:15:26 +08:00
|
|
|
windmc = pctx.AndroidStaticRule("windmc",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$windmcCmd -r$$(dirname $out) -h$$(dirname $out) $in",
|
|
|
|
CommandDeps: []string{"$windmcCmd"},
|
|
|
|
},
|
|
|
|
"windmcCmd")
|
2015-04-08 07:50:10 +08:00
|
|
|
)
|
|
|
|
|
2019-04-11 13:59:54 +08:00
|
|
|
type YaccProperties struct {
|
|
|
|
// list of module-specific flags that will be used for .y and .yy compiles
|
|
|
|
Flags []string
|
2015-04-08 07:50:10 +08:00
|
|
|
|
2019-04-11 13:59:54 +08:00
|
|
|
// whether the yacc files will produce a location.hh file
|
|
|
|
Gen_location_hh *bool
|
|
|
|
|
|
|
|
// whether the yacc files will product a position.hh file
|
|
|
|
Gen_position_hh *bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func genYacc(ctx android.ModuleContext, rule *android.RuleBuilder, yaccFile android.Path,
|
2020-07-25 01:19:23 +08:00
|
|
|
outFile android.ModuleGenPath, props *YaccProperties) (headerFiles android.Paths) {
|
2019-04-11 13:59:54 +08:00
|
|
|
|
|
|
|
outDir := android.PathForModuleGen(ctx, "yacc")
|
|
|
|
headerFile := android.GenPathWithExt(ctx, "yacc", yaccFile, "h")
|
|
|
|
ret := android.Paths{headerFile}
|
|
|
|
|
|
|
|
cmd := rule.Command()
|
2015-04-08 07:50:10 +08:00
|
|
|
|
2019-04-11 13:59:54 +08:00
|
|
|
// Fix up #line markers to not use the sbox temporary directory
|
|
|
|
sedCmd := "sed -i.bak 's#__SBOX_OUT_DIR__#" + outDir.String() + "#'"
|
|
|
|
rule.Command().Text(sedCmd).Input(outFile)
|
|
|
|
rule.Command().Text(sedCmd).Input(headerFile)
|
|
|
|
|
|
|
|
var flags []string
|
|
|
|
if props != nil {
|
|
|
|
flags = props.Flags
|
|
|
|
|
|
|
|
if Bool(props.Gen_location_hh) {
|
|
|
|
locationHeader := outFile.InSameDir(ctx, "location.hh")
|
|
|
|
ret = append(ret, locationHeader)
|
|
|
|
cmd.ImplicitOutput(locationHeader)
|
|
|
|
rule.Command().Text(sedCmd).Input(locationHeader)
|
|
|
|
}
|
|
|
|
if Bool(props.Gen_position_hh) {
|
|
|
|
positionHeader := outFile.InSameDir(ctx, "position.hh")
|
|
|
|
ret = append(ret, positionHeader)
|
|
|
|
cmd.ImplicitOutput(positionHeader)
|
|
|
|
rule.Command().Text(sedCmd).Input(positionHeader)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 01:19:23 +08:00
|
|
|
cmd.Text("BISON_PKGDATADIR=prebuilts/build-tools/common/bison").
|
|
|
|
FlagWithInput("M4=", ctx.Config().PrebuiltBuildTool(ctx, "m4")).
|
|
|
|
PrebuiltBuildTool(ctx, "bison").
|
2019-04-11 13:59:54 +08:00
|
|
|
Flag("-d").
|
|
|
|
Flags(flags).
|
|
|
|
FlagWithOutput("--defines=", headerFile).
|
|
|
|
Flag("-o").Output(outFile).Input(yaccFile)
|
|
|
|
|
|
|
|
return ret
|
2015-04-08 07:50:10 +08:00
|
|
|
}
|
|
|
|
|
2019-06-05 08:10:41 +08:00
|
|
|
func genAidl(ctx android.ModuleContext, rule *android.RuleBuilder, aidlFile android.Path,
|
|
|
|
outFile, depFile android.ModuleGenPath, aidlFlags string) android.Paths {
|
|
|
|
|
|
|
|
aidlPackage := strings.TrimSuffix(aidlFile.Rel(), aidlFile.Base())
|
|
|
|
baseName := strings.TrimSuffix(aidlFile.Base(), aidlFile.Ext())
|
2019-09-25 08:39:58 +08:00
|
|
|
shortName := baseName
|
|
|
|
// TODO(b/111362593): aidl_to_cpp_common.cpp uses heuristics to figure out if
|
|
|
|
// an interface name has a leading I. Those same heuristics have been
|
|
|
|
// moved here.
|
|
|
|
if len(baseName) >= 2 && baseName[0] == 'I' &&
|
|
|
|
strings.ToUpper(baseName)[1] == baseName[1] {
|
|
|
|
shortName = strings.TrimPrefix(baseName, "I")
|
|
|
|
}
|
2016-11-04 05:28:51 +08:00
|
|
|
|
2019-06-05 08:10:41 +08:00
|
|
|
outDir := android.PathForModuleGen(ctx, "aidl")
|
|
|
|
headerI := outDir.Join(ctx, aidlPackage, baseName+".h")
|
|
|
|
headerBn := outDir.Join(ctx, aidlPackage, "Bn"+shortName+".h")
|
|
|
|
headerBp := outDir.Join(ctx, aidlPackage, "Bp"+shortName+".h")
|
|
|
|
|
2019-07-07 15:27:47 +08:00
|
|
|
baseDir := strings.TrimSuffix(aidlFile.String(), aidlFile.Rel())
|
|
|
|
if baseDir != "" {
|
|
|
|
aidlFlags += " -I" + baseDir
|
|
|
|
}
|
|
|
|
|
2019-06-05 08:10:41 +08:00
|
|
|
cmd := rule.Command()
|
2019-07-09 08:08:34 +08:00
|
|
|
cmd.BuiltTool(ctx, "aidl-cpp").
|
2019-06-05 08:10:41 +08:00
|
|
|
FlagWithDepFile("-d", depFile).
|
|
|
|
Flag("--ninja").
|
|
|
|
Flag(aidlFlags).
|
|
|
|
Input(aidlFile).
|
|
|
|
OutputDir().
|
|
|
|
Output(outFile).
|
|
|
|
ImplicitOutputs(android.WritablePaths{
|
|
|
|
headerI,
|
|
|
|
headerBn,
|
|
|
|
headerBp,
|
|
|
|
})
|
|
|
|
|
|
|
|
return android.Paths{
|
|
|
|
headerI,
|
|
|
|
headerBn,
|
|
|
|
headerBp,
|
|
|
|
}
|
2016-11-04 05:28:51 +08:00
|
|
|
}
|
|
|
|
|
2020-07-25 01:19:23 +08:00
|
|
|
func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.ModuleGenPath) {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: lex,
|
|
|
|
Description: "lex " + lexFile.Rel(),
|
|
|
|
Output: outFile,
|
|
|
|
Input: lexFile,
|
|
|
|
})
|
2015-04-08 07:50:10 +08:00
|
|
|
}
|
|
|
|
|
2020-02-19 09:42:41 +08:00
|
|
|
func genSysprop(ctx android.ModuleContext, syspropFile android.Path) (android.Path, android.Paths) {
|
2018-09-05 23:55:20 +08:00
|
|
|
headerFile := android.PathForModuleGen(ctx, "sysprop", "include", syspropFile.Rel()+".h")
|
2019-06-08 19:36:59 +08:00
|
|
|
publicHeaderFile := android.PathForModuleGen(ctx, "sysprop/public", "include", syspropFile.Rel()+".h")
|
2018-09-05 23:55:20 +08:00
|
|
|
cppFile := android.PathForModuleGen(ctx, "sysprop", syspropFile.Rel()+".cpp")
|
|
|
|
|
2020-02-19 09:42:41 +08:00
|
|
|
headers := android.WritablePaths{headerFile, publicHeaderFile}
|
|
|
|
|
2018-09-05 23:55:20 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2020-02-19 09:42:41 +08:00
|
|
|
Rule: sysprop,
|
|
|
|
Description: "sysprop " + syspropFile.Rel(),
|
|
|
|
Output: cppFile,
|
|
|
|
ImplicitOutputs: headers,
|
|
|
|
Input: syspropFile,
|
2018-09-05 23:55:20 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"headerOutDir": filepath.Dir(headerFile.String()),
|
2019-06-08 19:36:59 +08:00
|
|
|
"publicOutDir": filepath.Dir(publicHeaderFile.String()),
|
2018-09-05 23:55:20 +08:00
|
|
|
"srcOutDir": filepath.Dir(cppFile.String()),
|
|
|
|
"includeName": syspropFile.Rel() + ".h",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-02-19 09:42:41 +08:00
|
|
|
return cppFile, headers.Paths()
|
2018-09-05 23:55:20 +08:00
|
|
|
}
|
|
|
|
|
2017-09-09 16:15:26 +08:00
|
|
|
func genWinMsg(ctx android.ModuleContext, srcFile android.Path, flags builderFlags) (android.Path, android.Path) {
|
|
|
|
headerFile := android.GenPathWithExt(ctx, "windmc", srcFile, "h")
|
|
|
|
rcFile := android.GenPathWithExt(ctx, "windmc", srcFile, "rc")
|
|
|
|
|
|
|
|
windmcCmd := gccCmd(flags.toolchain, "windmc")
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-09-09 16:15:26 +08:00
|
|
|
Rule: windmc,
|
|
|
|
Description: "windmc " + srcFile.Rel(),
|
|
|
|
Output: rcFile,
|
|
|
|
ImplicitOutput: headerFile,
|
|
|
|
Input: srcFile,
|
|
|
|
Args: map[string]string{
|
|
|
|
"windmcCmd": windmcCmd,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return rcFile, headerFile
|
|
|
|
}
|
|
|
|
|
2020-07-25 01:19:23 +08:00
|
|
|
func genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
|
|
|
buildFlags builderFlags) (android.Paths, android.Paths) {
|
2015-04-08 07:50:10 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
var deps android.Paths
|
2017-05-02 08:37:24 +08:00
|
|
|
var rsFiles android.Paths
|
|
|
|
|
2019-06-05 08:10:41 +08:00
|
|
|
var aidlRule *android.RuleBuilder
|
|
|
|
|
2019-04-11 13:59:54 +08:00
|
|
|
var yaccRule_ *android.RuleBuilder
|
|
|
|
yaccRule := func() *android.RuleBuilder {
|
|
|
|
if yaccRule_ == nil {
|
|
|
|
yaccRule_ = android.NewRuleBuilder().Sbox(android.PathForModuleGen(ctx, "yacc"))
|
|
|
|
}
|
|
|
|
return yaccRule_
|
|
|
|
}
|
|
|
|
|
2015-04-08 07:50:10 +08:00
|
|
|
for i, srcFile := range srcFiles {
|
2015-09-24 06:26:20 +08:00
|
|
|
switch srcFile.Ext() {
|
2016-03-02 07:15:26 +08:00
|
|
|
case ".y":
|
2016-11-03 11:43:13 +08:00
|
|
|
cFile := android.GenPathWithExt(ctx, "yacc", srcFile, "c")
|
2016-03-02 07:15:26 +08:00
|
|
|
srcFiles[i] = cFile
|
2020-07-25 01:19:23 +08:00
|
|
|
deps = append(deps, genYacc(ctx, yaccRule(), srcFile, cFile, buildFlags.yacc)...)
|
2016-03-02 07:15:26 +08:00
|
|
|
case ".yy":
|
2016-11-03 11:43:13 +08:00
|
|
|
cppFile := android.GenPathWithExt(ctx, "yacc", srcFile, "cpp")
|
2015-04-08 07:50:10 +08:00
|
|
|
srcFiles[i] = cppFile
|
2020-07-25 01:19:23 +08:00
|
|
|
deps = append(deps, genYacc(ctx, yaccRule(), srcFile, cppFile, buildFlags.yacc)...)
|
2016-03-02 07:15:26 +08:00
|
|
|
case ".l":
|
2016-11-03 11:43:13 +08:00
|
|
|
cFile := android.GenPathWithExt(ctx, "lex", srcFile, "c")
|
2016-03-02 07:15:26 +08:00
|
|
|
srcFiles[i] = cFile
|
2020-07-25 01:19:23 +08:00
|
|
|
genLex(ctx, srcFile, cFile)
|
2016-03-02 07:15:26 +08:00
|
|
|
case ".ll":
|
2016-11-03 11:43:13 +08:00
|
|
|
cppFile := android.GenPathWithExt(ctx, "lex", srcFile, "cpp")
|
2015-04-08 07:50:10 +08:00
|
|
|
srcFiles[i] = cppFile
|
2020-07-25 01:19:23 +08:00
|
|
|
genLex(ctx, srcFile, cppFile)
|
2016-10-21 07:11:43 +08:00
|
|
|
case ".proto":
|
2018-11-17 13:05:32 +08:00
|
|
|
ccFile, headerFile := genProto(ctx, srcFile, buildFlags)
|
2017-09-21 03:59:05 +08:00
|
|
|
srcFiles[i] = ccFile
|
|
|
|
deps = append(deps, headerFile)
|
2016-11-04 05:28:51 +08:00
|
|
|
case ".aidl":
|
2019-06-05 08:10:41 +08:00
|
|
|
if aidlRule == nil {
|
|
|
|
aidlRule = android.NewRuleBuilder().Sbox(android.PathForModuleGen(ctx, "aidl"))
|
|
|
|
}
|
2016-11-04 05:28:51 +08:00
|
|
|
cppFile := android.GenPathWithExt(ctx, "aidl", srcFile, "cpp")
|
2019-06-05 08:10:41 +08:00
|
|
|
depFile := android.GenPathWithExt(ctx, "aidl", srcFile, "cpp.d")
|
2016-11-04 05:28:51 +08:00
|
|
|
srcFiles[i] = cppFile
|
2019-06-05 08:10:41 +08:00
|
|
|
deps = append(deps, genAidl(ctx, aidlRule, srcFile, cppFile, depFile, buildFlags.aidlFlags)...)
|
2019-07-16 10:08:37 +08:00
|
|
|
case ".rscript", ".fs":
|
2017-05-02 08:37:24 +08:00
|
|
|
cppFile := rsGeneratedCppFile(ctx, srcFile)
|
|
|
|
rsFiles = append(rsFiles, srcFiles[i])
|
|
|
|
srcFiles[i] = cppFile
|
2017-09-09 16:15:26 +08:00
|
|
|
case ".mc":
|
|
|
|
rcFile, headerFile := genWinMsg(ctx, srcFile, buildFlags)
|
|
|
|
srcFiles[i] = rcFile
|
|
|
|
deps = append(deps, headerFile)
|
2018-09-05 23:55:20 +08:00
|
|
|
case ".sysprop":
|
2020-02-19 09:42:41 +08:00
|
|
|
cppFile, headerFiles := genSysprop(ctx, srcFile)
|
2018-09-05 23:55:20 +08:00
|
|
|
srcFiles[i] = cppFile
|
2020-02-19 09:42:41 +08:00
|
|
|
deps = append(deps, headerFiles...)
|
2015-04-08 07:50:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-05 08:10:41 +08:00
|
|
|
if aidlRule != nil {
|
|
|
|
aidlRule.Build(pctx, ctx, "aidl", "gen aidl")
|
|
|
|
}
|
|
|
|
|
2019-04-11 13:59:54 +08:00
|
|
|
if yaccRule_ != nil {
|
|
|
|
yaccRule_.Build(pctx, ctx, "yacc", "gen yacc")
|
|
|
|
}
|
|
|
|
|
2017-05-02 08:37:24 +08:00
|
|
|
if len(rsFiles) > 0 {
|
|
|
|
deps = append(deps, rsGenerateCpp(ctx, rsFiles, buildFlags.rsFlags)...)
|
|
|
|
}
|
|
|
|
|
2015-04-08 07:50:10 +08:00
|
|
|
return srcFiles, deps
|
|
|
|
}
|