Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13f02714 authored by Paul Duffin's avatar Paul Duffin
Browse files

Copy shared_libs and system_shared_libs to module snapshot

This change ensures that the runtime dependencies between a
binary/shared library are correctly specified in the snapshot so that
the build can ensure that shared libraries are built before the targets
that use them.

It adds support for differentiating between references that are
required to refer to another sdk member (required) and those that may
refer to either an sdk member or a non-sdk member (optional). The
latter is used for shared library references as the libraries used by
an sdk member may be provided from outside the sdk. e.g. liblog is not
part of the ART module but is used by some members of the ART sdk.

Bug: 142935992
Test: m nothing
Change-Id: Ia8509ffe79b208c23beba1880fe9c8a92b732685
parent b07fa511
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -186,9 +186,33 @@ type SnapshotBuilder interface {
	// is correctly output for both versioned and unversioned prebuilts in the
	// snapshot.
	//
	// "required: true" means that the property must only contain references
	// to other members of the sdk. Passing a reference to a module that is not a
	// member of the sdk will result in a build error.
	//
	// "required: false" means that the property can contain references to modules
	// that are either members or not members of the sdk. If a reference is to a
	// module that is a non member then the reference is left unchanged, i.e. it
	// is not transformed as references to members are.
	//
	// The handling of the member names is dependent on whether it is an internal or
	// exported member. An exported member is one whose name is specified in one of
	// the member type specific properties. An internal member is one that is added
	// due to being a part of an exported (or other internal) member and is not itself
	// an exported member.
	//
	// Member names are handled as follows:
	// * When creating the unversioned form of the module the name is left unchecked
	//   unless the member is internal in which case it is transformed into an sdk
	//   specific name, i.e. by prefixing with the sdk name.
	//
	// * When creating the versioned form of the module the name is transformed into
	//   a versioned sdk specific name, i.e. by prefixing with the sdk name and
	//   suffixing with the version.
	//
	// e.g.
	// bpPropertySet.AddPropertyWithTag("libs", []string{"member1", "member2"}, builder.SdkMemberReferencePropertyTag())
	SdkMemberReferencePropertyTag() BpPropertyTag
	// bpPropertySet.AddPropertyWithTag("libs", []string{"member1", "member2"}, builder.SdkMemberReferencePropertyTag(true))
	SdkMemberReferencePropertyTag(required bool) BpPropertyTag
}

type BpPropertyTag interface{}
+26 −0
Original line number Diff line number Diff line
@@ -95,6 +95,16 @@ type nativeBinaryInfoProperties struct {

	// outputFile is not exported as it is always arch specific.
	outputFile android.Path

	// The set of shared libraries
	//
	// This field is exported as its contents may not be arch specific.
	SharedLibs []string

	// The set of system shared libraries
	//
	// This field is exported as its contents may not be arch specific.
	SystemSharedLibs []string
}

func (p *nativeBinaryInfoProperties) PopulateFromVariant(variant android.SdkAware) {
@@ -102,6 +112,14 @@ func (p *nativeBinaryInfoProperties) PopulateFromVariant(variant android.SdkAwar

	p.archType = ccModule.Target().Arch.ArchType.String()
	p.outputFile = ccModule.OutputFile().Path()

	if ccModule.linker != nil {
		specifiedDeps := specifiedDeps{}
		specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps)

		p.SharedLibs = specifiedDeps.sharedLibs
		p.SystemSharedLibs = specifiedDeps.systemSharedLibs
	}
}

func (p *nativeBinaryInfoProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) {
@@ -114,4 +132,12 @@ func (p *nativeBinaryInfoProperties) AddToPropertySet(sdkModuleContext android.M

		builder.CopyToSnapshot(p.outputFile, nativeBinaryPathFor(*p))
	}

	if len(p.SharedLibs) > 0 {
		propertySet.AddPropertyWithTag("shared_libs", p.SharedLibs, builder.SdkMemberReferencePropertyTag(false))
	}

	if len(p.SystemSharedLibs) > 0 {
		propertySet.AddPropertyWithTag("system_shared_libs", p.SystemSharedLibs, builder.SdkMemberReferencePropertyTag(false))
	}
}
+9 −0
Original line number Diff line number Diff line
@@ -368,6 +368,15 @@ type linker interface {

	nativeCoverage() bool
	coverageOutputFilePath() android.OptionalPath

	// Get the deps that have been explicitly specified in the properties.
	// Only updates the
	linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
}

type specifiedDeps struct {
	sharedLibs       []string
	systemSharedLibs []string
}

type installer interface {
+17 −0
Original line number Diff line number Diff line
@@ -817,6 +817,23 @@ func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
	return deps
}

func (library *libraryDecorator) linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps {
	specifiedDeps = library.baseLinker.linkerSpecifiedDeps(specifiedDeps)
	var properties StaticOrSharedProperties
	if library.static() {
		properties = library.StaticProperties.Static
	} else if library.shared() {
		properties = library.SharedProperties.Shared
	}

	specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, properties.Shared_libs...)
	specifiedDeps.systemSharedLibs = append(specifiedDeps.systemSharedLibs, properties.System_shared_libs...)

	specifiedDeps.sharedLibs = android.FirstUniqueStrings(specifiedDeps.sharedLibs)
	specifiedDeps.systemSharedLibs = android.FirstUniqueStrings(specifiedDeps.systemSharedLibs)
	return specifiedDeps
}

func (library *libraryDecorator) linkStatic(ctx ModuleContext,
	flags Flags, deps PathDeps, objs Objects) android.Path {

+31 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import (

	"android/soong/android"
	"github.com/google/blueprint"
	"github.com/google/blueprint/proptools"
)

// This file contains support for using cc library modules within an sdk.
@@ -108,8 +109,11 @@ func (mt *librarySdkMemberType) AddPrebuiltModule(sdkModuleContext android.Modul
}

func (mt *librarySdkMemberType) FinalizeModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember, bpModule android.BpModule) {
	bpModule.AddProperty("stl", "none")
	bpModule.AddProperty("system_shared_libs", []string{})
	ccModule := (member.Variants()[0]).(*Module)
	stl := ccModule.stl.Properties.Stl
	if stl != nil {
		bpModule.AddProperty("stl", proptools.String(stl))
	}
}

func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
@@ -193,6 +197,14 @@ func addPossiblyArchSpecificProperties(sdkModuleContext android.ModuleContext, b
		outputProperties.AddProperty("srcs", []string{nativeLibraryPath})
	}

	if len(libInfo.SharedLibs) > 0 {
		outputProperties.AddPropertyWithTag("shared_libs", libInfo.SharedLibs, builder.SdkMemberReferencePropertyTag(false))
	}

	if len(libInfo.SystemSharedLibs) > 0 {
		outputProperties.AddPropertyWithTag("system_shared_libs", libInfo.SystemSharedLibs, builder.SdkMemberReferencePropertyTag(false))
	}

	// Map from property name to the include dirs to add to the prebuilt module in the snapshot.
	includeDirs := make(map[string][]string)

@@ -299,6 +311,16 @@ type nativeLibInfoProperties struct {
	// This field is exported as its contents may not be arch specific.
	ExportedFlags []string

	// The set of shared libraries
	//
	// This field is exported as its contents may not be arch specific.
	SharedLibs []string

	// The set of system shared libraries
	//
	// This field is exported as its contents may not be arch specific.
	SystemSharedLibs []string

	// outputFile is not exported as it is always arch specific.
	outputFile android.Path
}
@@ -323,6 +345,13 @@ func (p *nativeLibInfoProperties) PopulateFromVariant(variant android.SdkAware)
	p.exportedGeneratedIncludeDirs = exportedGeneratedIncludeDirs
	p.ExportedSystemIncludeDirs = ccModule.ExportedSystemIncludeDirs()
	p.ExportedFlags = ccModule.ExportedFlags()
	if ccModule.linker != nil {
		specifiedDeps := specifiedDeps{}
		specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps)

		p.SharedLibs = specifiedDeps.sharedLibs
		p.SystemSharedLibs = specifiedDeps.systemSharedLibs
	}
	p.exportedGeneratedHeaders = ccModule.ExportedGeneratedHeaders()
}

Loading