diff options
author | 2023-02-03 18:12:15 -0500 | |
---|---|---|
committer | 2023-02-07 16:50:30 -0500 | |
commit | 4ed95e263fa738ca4eda663ab8e1d9871397a8e6 (patch) | |
tree | 69c3a6a32d031f6a35a60082d5688d0ee78ed000 /cc/library_test.go | |
parent | cb3c52c7665b2bded1a800f33718d57a5db5c6c5 (diff) |
mixed build targets need transitive tidy files
Previously in mixed builds, only the tidy files for the boundary module
were built, whereas all of its transitive dependencies' tidy files were
not being built. Instead we should export the list of transitive tidy
files for a module so that we can run clang-tidy for the boundary module
as well as its dependencies.
Bug: 195029134
Test: WITH_TIDY=1 DISABLE_ARTIFACT_PATH_REQUIREMENTS=true mss tidy-packages-modules-NeuralNetworks --bazel-mode-dev
Change-Id: I463646d2ae1fc4aa075a54c264e1c34571c3fd5c
Diffstat (limited to 'cc/library_test.go')
-rw-r--r-- | cc/library_test.go | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/cc/library_test.go b/cc/library_test.go index dab5bb804..de3db99db 100644 --- a/cc/library_test.go +++ b/cc/library_test.go @@ -308,6 +308,75 @@ cc_library { android.AssertPathsRelativeToTopEquals(t, "deps", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.Deps) } +func TestCcLibraryWithBazelValidations(t *testing.T) { + t.Parallel() + bp := ` +cc_library { + name: "foo", + srcs: ["foo.cc"], + bazel_module: { label: "//foo/bar:bar" }, + tidy: true, +}` + config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) + config.BazelContext = android.MockBazelContext{ + OutputBaseDir: "outputbase", + LabelToCcInfo: map[string]cquery.CcInfo{ + "//foo/bar:bar": cquery.CcInfo{ + CcObjectFiles: []string{"foo.o"}, + Includes: []string{"include"}, + SystemIncludes: []string{"system_include"}, + Headers: []string{"foo.h"}, + RootDynamicLibraries: []string{"foo.so"}, + UnstrippedOutput: "foo_unstripped.so", + }, + "//foo/bar:bar_bp2build_cc_library_static": cquery.CcInfo{ + CcObjectFiles: []string{"foo.o"}, + Includes: []string{"include"}, + SystemIncludes: []string{"system_include"}, + Headers: []string{"foo.h"}, + RootStaticArchives: []string{"foo.a"}, + TidyFiles: []string{"foo.c.tidy"}, + }, + }, + } + ctx := android.GroupFixturePreparers( + prepareForCcTest, + android.FixtureMergeEnv(map[string]string{ + "ALLOW_LOCAL_TIDY_TRUE": "1", + }), + ).RunTestWithConfig(t, config).TestContext + + staticFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_static").Module() + outputFiles, err := staticFoo.(android.OutputFileProducer).OutputFiles("") + if err != nil { + t.Errorf("Unexpected error getting cc_object outputfiles %s", err) + } + + expectedOutputFiles := []string{"out/soong/.intermediates/foo/android_arm_armv7-a-neon_static/validated/foo.a"} + android.AssertPathsRelativeToTopEquals(t, "output files", expectedOutputFiles, outputFiles) + + flagExporter := ctx.ModuleProvider(staticFoo, FlagExporterInfoProvider).(FlagExporterInfo) + android.AssertPathsRelativeToTopEquals(t, "exported include dirs", []string{"outputbase/execroot/__main__/include"}, flagExporter.IncludeDirs) + android.AssertPathsRelativeToTopEquals(t, "exported system include dirs", []string{"outputbase/execroot/__main__/system_include"}, flagExporter.SystemIncludeDirs) + android.AssertPathsRelativeToTopEquals(t, "exported headers", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.GeneratedHeaders) + android.AssertPathsRelativeToTopEquals(t, "deps", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.Deps) + + sharedFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module() + outputFiles, err = sharedFoo.(android.OutputFileProducer).OutputFiles("") + if err != nil { + t.Errorf("Unexpected error getting cc_library outputfiles %s", err) + } + expectedOutputFiles = []string{"outputbase/execroot/__main__/foo.so"} + android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings()) + + android.AssertStringEquals(t, "unstripped shared library", "outputbase/execroot/__main__/foo_unstripped.so", sharedFoo.(*Module).linker.unstrippedOutputFilePath().String()) + flagExporter = ctx.ModuleProvider(sharedFoo, FlagExporterInfoProvider).(FlagExporterInfo) + android.AssertPathsRelativeToTopEquals(t, "exported include dirs", []string{"outputbase/execroot/__main__/include"}, flagExporter.IncludeDirs) + android.AssertPathsRelativeToTopEquals(t, "exported system include dirs", []string{"outputbase/execroot/__main__/system_include"}, flagExporter.SystemIncludeDirs) + android.AssertPathsRelativeToTopEquals(t, "exported headers", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.GeneratedHeaders) + android.AssertPathsRelativeToTopEquals(t, "deps", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.Deps) +} + func TestLibraryVersionScript(t *testing.T) { t.Parallel() result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, ` @@ -344,6 +413,59 @@ func TestLibraryDynamicList(t *testing.T) { } +func TestCcLibrarySharedWithBazelValidations(t *testing.T) { + t.Parallel() + bp := ` +cc_library_shared { + name: "foo", + srcs: ["foo.cc"], + bazel_module: { label: "//foo/bar:bar" }, + tidy: true, +}` + config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) + config.BazelContext = android.MockBazelContext{ + OutputBaseDir: "outputbase", + LabelToCcInfo: map[string]cquery.CcInfo{ + "//foo/bar:bar": cquery.CcInfo{ + CcObjectFiles: []string{"foo.o"}, + Includes: []string{"include"}, + SystemIncludes: []string{"system_include"}, + RootDynamicLibraries: []string{"foo.so"}, + TocFile: "foo.so.toc", + TidyFiles: []string{"foo.c.tidy"}, + }, + }, + } + ctx := android.GroupFixturePreparers( + prepareForCcTest, + android.FixtureMergeEnv(map[string]string{ + "ALLOW_LOCAL_TIDY_TRUE": "1", + }), + ).RunTestWithConfig(t, config).TestContext + + sharedFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module() + producer := sharedFoo.(android.OutputFileProducer) + outputFiles, err := producer.OutputFiles("") + if err != nil { + t.Errorf("Unexpected error getting cc_object outputfiles %s", err) + } + expectedOutputFiles := []string{"out/soong/.intermediates/foo/android_arm_armv7-a-neon_shared/validated/foo.so"} + android.AssertPathsRelativeToTopEquals(t, "output files", expectedOutputFiles, outputFiles) + + tocFilePath := sharedFoo.(*Module).Toc() + if !tocFilePath.Valid() { + t.Errorf("Invalid tocFilePath: %s", tocFilePath) + } + tocFile := tocFilePath.Path() + expectedToc := "outputbase/execroot/__main__/foo.so.toc" + android.AssertStringEquals(t, "toc file", expectedToc, tocFile.String()) + + entries := android.AndroidMkEntriesForTest(t, ctx, sharedFoo)[0] + expectedFlags := []string{"-Ioutputbase/execroot/__main__/include", "-isystem outputbase/execroot/__main__/system_include"} + gotFlags := entries.EntryMap["LOCAL_EXPORT_CFLAGS"] + android.AssertDeepEquals(t, "androidmk exported cflags", expectedFlags, gotFlags) +} + func TestCcLibrarySharedWithBazel(t *testing.T) { t.Parallel() bp := ` |