Initial prebuilt support
Support prebuilt shared libraries as an initial proof-of-concept of prebuilts. Future changes will support binaries and static libraries, and the ability to select which to use based on something besides blueprint properties. Test: TestPrebuilts run during m -j Change-Id: I6e84da667e9005ae11844bad01d25cbe4ced1ce3
This commit is contained in:
@@ -81,7 +81,7 @@ func (binary *binaryDecorator) linkerProps() []interface{} {
|
||||
}
|
||||
|
||||
func (binary *binaryDecorator) getStem(ctx BaseModuleContext) string {
|
||||
stem := ctx.ModuleName()
|
||||
stem := ctx.baseModuleName()
|
||||
if binary.Properties.Stem != "" {
|
||||
stem = binary.Properties.Stem
|
||||
}
|
||||
@@ -171,7 +171,7 @@ func (binary *binaryDecorator) linkerInit(ctx BaseModuleContext) {
|
||||
}
|
||||
if ctx.TargetPrimary() {
|
||||
binary.baseInstaller.Properties.Symlinks = append(binary.baseInstaller.Properties.Symlinks,
|
||||
ctx.ModuleName())
|
||||
ctx.baseModuleName())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
42
cc/cc.go
42
cc/cc.go
@@ -19,7 +19,6 @@ package cc
|
||||
// is handled in builder.go
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -146,6 +145,7 @@ type ModuleContextIntf interface {
|
||||
sdk() bool
|
||||
sdkVersion() string
|
||||
selectedStl() string
|
||||
baseModuleName() string
|
||||
}
|
||||
|
||||
type ModuleContext interface {
|
||||
@@ -354,6 +354,10 @@ func (ctx *moduleContextImpl) selectedStl() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (ctx *moduleContextImpl) baseModuleName() string {
|
||||
return ctx.mod.ModuleBase.BaseModuleName()
|
||||
}
|
||||
|
||||
func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
|
||||
return &Module{
|
||||
hod: hod,
|
||||
@@ -368,6 +372,21 @@ func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Mo
|
||||
return module
|
||||
}
|
||||
|
||||
func (c *Module) Prebuilt() *android.Prebuilt {
|
||||
if p, ok := c.linker.(prebuiltLinkerInterface); ok {
|
||||
return p.prebuilt()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Module) Name() string {
|
||||
name := c.ModuleBase.Name()
|
||||
if p, ok := c.linker.(prebuiltLinkerInterface); ok {
|
||||
name = p.Name(name)
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
||||
ctx := &moduleContext{
|
||||
ModuleContext: actx,
|
||||
@@ -434,12 +453,12 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
||||
return
|
||||
}
|
||||
c.outputFile = android.OptionalPathForPath(outputFile)
|
||||
}
|
||||
|
||||
if c.installer != nil && !c.Properties.PreventInstall {
|
||||
c.installer.install(ctx, outputFile)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
|
||||
c.installer.install(ctx, c.outputFile.Path())
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -792,11 +811,6 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||
return
|
||||
}
|
||||
|
||||
if !cc.outputFile.Valid() {
|
||||
ctx.ModuleErrorf("module %q missing output file", name)
|
||||
return
|
||||
}
|
||||
|
||||
if tag == reuseObjTag {
|
||||
depPaths.ObjFiles = append(depPaths.ObjFiles,
|
||||
cc.compiler.(libraryInterface).reuseObjs()...)
|
||||
@@ -861,11 +875,13 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||
depPaths.CrtBegin = linkFile
|
||||
case crtEndDepTag:
|
||||
depPaths.CrtEnd = linkFile
|
||||
default:
|
||||
panic(fmt.Errorf("unknown dependency tag: %s", tag))
|
||||
}
|
||||
|
||||
if ptr != nil {
|
||||
if !linkFile.Valid() {
|
||||
ctx.ModuleErrorf("module %q missing output file", name)
|
||||
return
|
||||
}
|
||||
*ptr = append(*ptr, linkFile.Path())
|
||||
}
|
||||
|
||||
|
@@ -284,7 +284,7 @@ type libraryInterface interface {
|
||||
func (library *libraryDecorator) getLibName(ctx ModuleContext) string {
|
||||
name := library.libName
|
||||
if name == "" {
|
||||
name = ctx.ModuleName()
|
||||
name = ctx.baseModuleName()
|
||||
}
|
||||
|
||||
if ctx.Host() && Bool(library.Properties.Unique_host_soname) {
|
||||
|
72
cc/prebuilt.go
Normal file
72
cc/prebuilt.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// 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 (
|
||||
"android/soong/android"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
func init() {
|
||||
android.RegisterModuleType("cc_prebuilt_shared_library", prebuiltSharedLibraryFactory)
|
||||
}
|
||||
|
||||
type prebuiltLinkerInterface interface {
|
||||
Name(string) string
|
||||
prebuilt() *android.Prebuilt
|
||||
}
|
||||
|
||||
type prebuiltLibraryLinker struct {
|
||||
*libraryDecorator
|
||||
android.Prebuilt
|
||||
}
|
||||
|
||||
var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
|
||||
|
||||
func (p *prebuiltLibraryLinker) prebuilt() *android.Prebuilt {
|
||||
return &p.Prebuilt
|
||||
}
|
||||
|
||||
func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
|
||||
props := p.libraryDecorator.linkerProps()
|
||||
return append(props, &p.Prebuilt.Properties)
|
||||
}
|
||||
|
||||
func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
|
||||
flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
|
||||
// TODO(ccross): verify shared library dependencies
|
||||
if len(p.Prebuilt.Properties.Srcs) > 0 {
|
||||
p.libraryDecorator.exportIncludes(ctx, "-I")
|
||||
p.libraryDecorator.reexportFlags(deps.ReexportedFlags)
|
||||
p.libraryDecorator.reexportDeps(deps.ReexportedFlagsDeps)
|
||||
// TODO(ccross): .toc optimization, stripping, packing
|
||||
return p.Prebuilt.Path(ctx)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func prebuiltSharedLibraryFactory() (blueprint.Module, []interface{}) {
|
||||
module, library := NewLibrary(android.HostAndDeviceSupported, true, false)
|
||||
module.compiler = nil
|
||||
|
||||
prebuilt := &prebuiltLibraryLinker{
|
||||
libraryDecorator: library,
|
||||
}
|
||||
module.linker = prebuilt
|
||||
|
||||
return module.Init()
|
||||
}
|
Reference in New Issue
Block a user