libclang_rt_prebuilt_library_shared mixed builds
Also fix nil deref in setting $LOCAL_SOONG_UNSTRIPPED_BINARY
Bug: 201802518
Test: request_type_test.go
Test: prebuilt_test.go:TestPrebuiltLibrarySharedWithBazel
Test: mixed_{libc,droid}.sh
Change-Id: I22afb56c4b42d3412c2b2e1f079f1bcf8f3129a7
This commit is contained in:
parent
2c32bbfd73
commit
c3b97c3568
@@ -14,6 +14,7 @@ var (
|
||||
type CcInfo struct {
|
||||
OutputFiles []string
|
||||
CcObjectFiles []string
|
||||
CcSharedLibraryFiles []string
|
||||
CcStaticLibraryFiles []string
|
||||
Includes []string
|
||||
SystemIncludes []string
|
||||
@@ -128,28 +129,43 @@ else:
|
||||
if linker_input.owner == target.label:
|
||||
rootStaticArchives.append(library.static_library.path)
|
||||
|
||||
rootDynamicLibraries = []
|
||||
sharedLibraries = []
|
||||
rootSharedLibraries = []
|
||||
|
||||
shared_info_tag = "@rules_cc//examples:experimental_cc_shared_library.bzl%CcSharedLibraryInfo"
|
||||
if shared_info_tag in providers(target):
|
||||
shared_info = providers(target)[shared_info_tag]
|
||||
for lib in shared_info.linker_input.libraries:
|
||||
rootDynamicLibraries += [lib.dynamic_library.path]
|
||||
path = lib.dynamic_library.path
|
||||
rootSharedLibraries += [path]
|
||||
sharedLibraries.append(path)
|
||||
else:
|
||||
for linker_input in linker_inputs:
|
||||
for library in linker_input.libraries:
|
||||
if library.dynamic_library:
|
||||
path = library.dynamic_library.path
|
||||
sharedLibraries.append(path)
|
||||
if linker_input.owner == target.label:
|
||||
rootSharedLibraries.append(path)
|
||||
|
||||
toc_file = ""
|
||||
toc_file_tag = "//build/bazel/rules:generate_toc.bzl%CcTocInfo"
|
||||
if toc_file_tag in providers(target):
|
||||
toc_file = providers(target)[toc_file_tag].toc.path
|
||||
else:
|
||||
# NOTE: It's OK if there's no ToC, as Soong just uses it for optimization
|
||||
pass
|
||||
|
||||
returns = [
|
||||
outputFiles,
|
||||
staticLibraries,
|
||||
ccObjectFiles,
|
||||
sharedLibraries,
|
||||
staticLibraries,
|
||||
includes,
|
||||
system_includes,
|
||||
headers,
|
||||
rootStaticArchives,
|
||||
rootDynamicLibraries,
|
||||
rootSharedLibraries,
|
||||
[toc_file]
|
||||
]
|
||||
|
||||
@@ -160,28 +176,35 @@ return "|".join([", ".join(r) for r in returns])`
|
||||
// The given rawString must correspond to the string output which was created by evaluating the
|
||||
// Starlark given in StarlarkFunctionBody.
|
||||
func (g getCcInfoType) ParseResult(rawString string) (CcInfo, error) {
|
||||
var outputFiles []string
|
||||
var ccObjects []string
|
||||
|
||||
const expectedLen = 10
|
||||
splitString := strings.Split(rawString, "|")
|
||||
if expectedLen := 9; len(splitString) != expectedLen {
|
||||
if len(splitString) != expectedLen {
|
||||
return CcInfo{}, fmt.Errorf("Expected %d items, got %q", expectedLen, splitString)
|
||||
}
|
||||
outputFilesString := splitString[0]
|
||||
ccStaticLibrariesString := splitString[1]
|
||||
ccObjectsString := splitString[2]
|
||||
outputFiles = splitOrEmpty(outputFilesString, ", ")
|
||||
ccObjectsString := splitString[1]
|
||||
ccSharedLibrariesString := splitString[2]
|
||||
ccStaticLibrariesString := splitString[3]
|
||||
includesString := splitString[4]
|
||||
systemIncludesString := splitString[5]
|
||||
headersString := splitString[6]
|
||||
rootStaticArchivesString := splitString[7]
|
||||
rootDynamicLibrariesString := splitString[8]
|
||||
tocFile := splitString[9] // NOTE: Will be the empty string if there wasn't
|
||||
|
||||
outputFiles := splitOrEmpty(outputFilesString, ", ")
|
||||
ccObjects := splitOrEmpty(ccObjectsString, ", ")
|
||||
ccSharedLibraries := splitOrEmpty(ccSharedLibrariesString, ", ")
|
||||
ccStaticLibraries := splitOrEmpty(ccStaticLibrariesString, ", ")
|
||||
ccObjects = splitOrEmpty(ccObjectsString, ", ")
|
||||
includes := splitOrEmpty(splitString[3], ", ")
|
||||
systemIncludes := splitOrEmpty(splitString[4], ", ")
|
||||
headers := splitOrEmpty(splitString[5], ", ")
|
||||
rootStaticArchives := splitOrEmpty(splitString[6], ", ")
|
||||
rootDynamicLibraries := splitOrEmpty(splitString[7], ", ")
|
||||
tocFile := splitString[8] // NOTE: Will be the empty string if there wasn't
|
||||
includes := splitOrEmpty(includesString, ", ")
|
||||
systemIncludes := splitOrEmpty(systemIncludesString, ", ")
|
||||
headers := splitOrEmpty(headersString, ", ")
|
||||
rootStaticArchives := splitOrEmpty(rootStaticArchivesString, ", ")
|
||||
rootDynamicLibraries := splitOrEmpty(rootDynamicLibrariesString, ", ")
|
||||
return CcInfo{
|
||||
OutputFiles: outputFiles,
|
||||
CcObjectFiles: ccObjects,
|
||||
CcSharedLibraryFiles: ccSharedLibraries,
|
||||
CcStaticLibraryFiles: ccStaticLibraries,
|
||||
Includes: includes,
|
||||
SystemIncludes: systemIncludes,
|
||||
|
||||
@@ -63,6 +63,8 @@ func TestGetPythonBinaryParseResults(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCcInfoParseResults(t *testing.T) {
|
||||
const expectedSplits = 10
|
||||
noResult := strings.Repeat("|", expectedSplits-1)
|
||||
testCases := []struct {
|
||||
description string
|
||||
input string
|
||||
@@ -71,10 +73,11 @@ func TestGetCcInfoParseResults(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
description: "no result",
|
||||
input: "||||||||",
|
||||
input: noResult,
|
||||
expectedOutput: CcInfo{
|
||||
OutputFiles: []string{},
|
||||
CcObjectFiles: []string{},
|
||||
CcSharedLibraryFiles: []string{},
|
||||
CcStaticLibraryFiles: []string{},
|
||||
Includes: []string{},
|
||||
SystemIncludes: []string{},
|
||||
@@ -86,10 +89,11 @@ func TestGetCcInfoParseResults(t *testing.T) {
|
||||
},
|
||||
{
|
||||
description: "only output",
|
||||
input: "test||||||||",
|
||||
input: "test" + noResult,
|
||||
expectedOutput: CcInfo{
|
||||
OutputFiles: []string{"test"},
|
||||
CcObjectFiles: []string{},
|
||||
CcSharedLibraryFiles: []string{},
|
||||
CcStaticLibraryFiles: []string{},
|
||||
Includes: []string{},
|
||||
SystemIncludes: []string{},
|
||||
@@ -99,12 +103,38 @@ func TestGetCcInfoParseResults(t *testing.T) {
|
||||
TocFile: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "only ToC",
|
||||
input: noResult + "test",
|
||||
expectedOutput: CcInfo{
|
||||
OutputFiles: []string{},
|
||||
CcObjectFiles: []string{},
|
||||
CcSharedLibraryFiles: []string{},
|
||||
CcStaticLibraryFiles: []string{},
|
||||
Includes: []string{},
|
||||
SystemIncludes: []string{},
|
||||
Headers: []string{},
|
||||
RootStaticArchives: []string{},
|
||||
RootDynamicLibraries: []string{},
|
||||
TocFile: "test",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "all items set",
|
||||
input: "out1, out2|static_lib1, static_lib2|object1, object2|., dir/subdir|system/dir, system/other/dir|dir/subdir/hdr.h|rootstaticarchive1|rootdynamiclibrary1|lib.so.toc",
|
||||
input: "out1, out2" +
|
||||
"|object1, object2" +
|
||||
"|shared_lib1, shared_lib2" +
|
||||
"|static_lib1, static_lib2" +
|
||||
"|., dir/subdir" +
|
||||
"|system/dir, system/other/dir" +
|
||||
"|dir/subdir/hdr.h" +
|
||||
"|rootstaticarchive1" +
|
||||
"|rootdynamiclibrary1" +
|
||||
"|lib.so.toc",
|
||||
expectedOutput: CcInfo{
|
||||
OutputFiles: []string{"out1", "out2"},
|
||||
CcObjectFiles: []string{"object1", "object2"},
|
||||
CcSharedLibraryFiles: []string{"shared_lib1", "shared_lib2"},
|
||||
CcStaticLibraryFiles: []string{"static_lib1", "static_lib2"},
|
||||
Includes: []string{".", "dir/subdir"},
|
||||
SystemIncludes: []string{"system/dir", "system/other/dir"},
|
||||
@@ -118,22 +148,22 @@ func TestGetCcInfoParseResults(t *testing.T) {
|
||||
description: "too few result splits",
|
||||
input: "|",
|
||||
expectedOutput: CcInfo{},
|
||||
expectedErrorMessage: fmt.Sprintf("Expected %d items, got %q", 9, []string{"", ""}),
|
||||
expectedErrorMessage: fmt.Sprintf("Expected %d items, got %q", expectedSplits, []string{"", ""}),
|
||||
},
|
||||
{
|
||||
description: "too many result splits",
|
||||
input: strings.Repeat("|", 50),
|
||||
input: strings.Repeat("|", expectedSplits+1), // 2 too many
|
||||
expectedOutput: CcInfo{},
|
||||
expectedErrorMessage: fmt.Sprintf("Expected %d items, got %q", 9, make([]string, 51)),
|
||||
expectedErrorMessage: fmt.Sprintf("Expected %d items, got %q", expectedSplits, make([]string, expectedSplits+2)),
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
actualOutput, err := GetCcInfo.ParseResult(tc.input)
|
||||
if (err == nil && tc.expectedErrorMessage != "") ||
|
||||
(err != nil && err.Error() != tc.expectedErrorMessage) {
|
||||
t.Errorf("%q: expected Error %s, got %s", tc.description, tc.expectedErrorMessage, err)
|
||||
t.Errorf("%q:\nexpected Error %s\n, got %s", tc.description, tc.expectedErrorMessage, err)
|
||||
} else if err == nil && !reflect.DeepEqual(tc.expectedOutput, actualOutput) {
|
||||
t.Errorf("%q: expected %#v != actual %#v", tc.description, tc.expectedOutput, actualOutput)
|
||||
t.Errorf("%q:\n expected %#v\n!= actual %#v", tc.description, tc.expectedOutput, actualOutput)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user