Pass pointer to dependencyTag instead of copying struct

A follow up change will add some more fields to the tag which will make
passing the struct around by value will get more expensive. Switching
to pointers will make this slightly more efficient.

Changing the type of the tags from dependencyTag to *dependencyTag
broke a test. Rather than simply patch the test and then maybe have to
patch it again in the next change this adds a a String() method that
will insulate the test from being affected by changes in the
dependencyTag contents.

Bug: 232401814
Test: m nothing
Change-Id: I23da742ebffb74ef3b9b68f772519ceb38332f5f
(cherry picked from commit 520917af9d)
Merged-In: I23da742ebffb74ef3b9b68f772519ceb38332f5f
This commit is contained in:
Paul Duffin
2022-05-13 13:01:59 +00:00
committed by Cherrypicker Worker
parent 09bb15da5e
commit e4713a88cb
2 changed files with 24 additions and 20 deletions

View File

@@ -606,30 +606,34 @@ type dependencyTag struct {
sourceOnly bool
}
func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
func (d *dependencyTag) String() string {
return fmt.Sprintf("apex.dependencyTag{%q}", d.name)
}
func (d *dependencyTag) ReplaceSourceWithPrebuilt() bool {
return !d.sourceOnly
}
var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
var (
androidAppTag = dependencyTag{name: "androidApp", payload: true}
bpfTag = dependencyTag{name: "bpf", payload: true}
certificateTag = dependencyTag{name: "certificate"}
executableTag = dependencyTag{name: "executable", payload: true}
fsTag = dependencyTag{name: "filesystem", payload: true}
bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
javaLibTag = dependencyTag{name: "javaLib", payload: true}
jniLibTag = dependencyTag{name: "jniLib", payload: true}
keyTag = dependencyTag{name: "key"}
prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
rroTag = dependencyTag{name: "rro", payload: true}
sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
testForTag = dependencyTag{name: "test for"}
testTag = dependencyTag{name: "test", payload: true}
shBinaryTag = dependencyTag{name: "shBinary", payload: true}
androidAppTag = &dependencyTag{name: "androidApp", payload: true}
bpfTag = &dependencyTag{name: "bpf", payload: true}
certificateTag = &dependencyTag{name: "certificate"}
executableTag = &dependencyTag{name: "executable", payload: true}
fsTag = &dependencyTag{name: "filesystem", payload: true}
bcpfTag = &dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
sscpfTag = &dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
compatConfigTag = &dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
javaLibTag = &dependencyTag{name: "javaLib", payload: true}
jniLibTag = &dependencyTag{name: "jniLib", payload: true}
keyTag = &dependencyTag{name: "key"}
prebuiltTag = &dependencyTag{name: "prebuilt", payload: true}
rroTag = &dependencyTag{name: "rro", payload: true}
sharedLibTag = &dependencyTag{name: "sharedLib", payload: true}
testForTag = &dependencyTag{name: "test for"}
testTag = &dependencyTag{name: "test", payload: true}
shBinaryTag = &dependencyTag{name: "shBinary", payload: true}
)
// TODO(jiyong): shorten this function signature
@@ -1735,7 +1739,7 @@ func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.Paylo
if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
return false
}
if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
if dt, ok := depTag.(*dependencyTag); ok && !dt.payload {
return false
}

View File

@@ -5931,7 +5931,7 @@ func TestApexAvailable_DirectDep(t *testing.T) {
func TestApexAvailable_IndirectDep(t *testing.T) {
// libbbaz is an indirect dep
testApexError(t, `requires "libbaz" that doesn't list the APEX under 'apex_available'.\n\nDependency path:
.*via tag apex\.dependencyTag.*name:sharedLib.*
.*via tag apex\.dependencyTag\{"sharedLib"\}
.*-> libfoo.*link:shared.*
.*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.*
.*-> libbar.*link:shared.*