From 0507921dcf1820c598122604905c7a54f2025dd7 Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Fri, 20 May 2022 16:41:39 -0700 Subject: [PATCH] gen_module visibility tests. Test: m cts dist reportmissinglicenses Change-Id: Ib2f8d0ad46ffe795d392166a74a7c6309b1246e2 --- android/testing.go | 2 + android/visibility_test.go | 816 +++++++++++++++++++++++++++++++++++-- 2 files changed, 794 insertions(+), 24 deletions(-) diff --git a/android/testing.go b/android/testing.go index ac02db9af..85bdca475 100644 --- a/android/testing.go +++ b/android/testing.go @@ -83,6 +83,8 @@ var PrepareForTestWithLicenses = GroupFixturePreparers( FixtureRegisterWithContext(registerLicenseMutators), ) +var PrepareForTestWithGenNotice = FixtureRegisterWithContext(RegisterGenNoticeBuildComponents) + func registerLicenseMutators(ctx RegistrationContext) { ctx.PreArchMutators(RegisterLicensesPackageMapper) ctx.PreArchMutators(RegisterLicensesPropertyGatherer) diff --git a/android/visibility_test.go b/android/visibility_test.go index 714c92a71..a66f0b698 100644 --- a/android/visibility_test.go +++ b/android/visibility_test.go @@ -135,7 +135,49 @@ var visibilityTests = []struct { name: "libexample", visibility: ["//visibility:public"], } - + + mock_library { + name: "libsamepackage", + deps: ["libexample"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + mock_library { + name: "libnested", + deps: ["libexample"], + } + + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "other/Android.bp": []byte(` + mock_library { + name: "libother", + deps: ["libexample"], + } + + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + }, + { + // Verify that //visibility:private allows the module to be referenced from the current + // directory only. + name: "//visibility:private", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: ["//visibility:private"], + } + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -151,18 +193,61 @@ var visibilityTests = []struct { deps: ["libexample"], }`), }, + expectedErrors: []string{ + `module "libnested" variant "android_common": depends on //top:libexample which is not` + + ` visible to this module`, + `module "libother" variant "android_common": depends on //top:libexample which is not` + + ` visible to this module`, + }, }, { // Verify that //visibility:private allows the module to be referenced from the current // directory only. - name: "//visibility:private", + name: "//visibility:private (notices)", fs: MockFS{ "top/Android.bp": []byte(` mock_library { name: "libexample", visibility: ["//visibility:private"], } - + + mock_library { + name: "libsamepackage", + deps: ["libexample"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "nested-notice" references "//top:libexample" which is not visible to this` + + ` module\nYou may need to add "//top/nested" to its visibility`, + `module "other-notice" references "//top:libexample" which is not visible to this module\n` + + `You may need to add "//other" to its visibility`, + }, + }, + { + // Verify that :__pkg__ allows the module to be referenced from the current directory only. + name: ":__pkg__", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: [":__pkg__"], + } + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -187,34 +272,32 @@ var visibilityTests = []struct { }, { // Verify that :__pkg__ allows the module to be referenced from the current directory only. - name: ":__pkg__", + name: ":__pkg__ (notices)", fs: MockFS{ "top/Android.bp": []byte(` mock_library { name: "libexample", visibility: [":__pkg__"], } - - mock_library { - name: "libsamepackage", - deps: ["libexample"], + + gen_notice { + name: "libexample-notice", + for: ["libexample"], }`), "top/nested/Android.bp": []byte(` - mock_library { - name: "libnested", - deps: ["libexample"], + gen_notice { + name: "nested-notice", + for: ["libexample"], }`), "other/Android.bp": []byte(` - mock_library { - name: "libother", - deps: ["libexample"], + gen_notice { + name: "other-notice", + for: ["libexample"], }`), }, expectedErrors: []string{ - `module "libnested" variant "android_common": depends on //top:libexample which is not` + - ` visible to this module`, - `module "libother" variant "android_common": depends on //top:libexample which is not` + - ` visible to this module`, + `module "nested-notice" references "//top:libexample" which is not visible to this module`, + `module "other-notice" references "//top:libexample" which is not visible to this module`, }, }, { @@ -227,7 +310,7 @@ var visibilityTests = []struct { name: "libexample", visibility: ["//top/nested"], } - + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -255,6 +338,42 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + // Verify that //top/nested allows the module to be referenced from the current directory and + // the top/nested directory only, not a subdirectory of top/nested and not peak directory. + name: "//top/nested (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: ["//top/nested"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "top/nested/again/Android.bp": []byte(` + gen_notice { + name: "nestedagain-notice", + for: ["libexample"], + }`), + "peak/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "other-notice" references "//top:libexample" which is not visible to this module`, + `module "nestedagain-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { // Verify that :__subpackages__ allows the module to be referenced from the current directory // and sub directories but nowhere else. @@ -265,7 +384,7 @@ var visibilityTests = []struct { name: "libexample", visibility: [":__subpackages__"], } - + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -286,6 +405,36 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + // Verify that :__subpackages__ allows the module to be referenced from the current directory + // and sub directories but nowhere else. + name: ":__subpackages__ (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: [":__subpackages__"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "peak/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "other-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { // Verify that //top/nested:__subpackages__ allows the module to be referenced from the current // directory and sub directories but nowhere else. @@ -296,7 +445,7 @@ var visibilityTests = []struct { name: "libexample", visibility: ["//top/nested:__subpackages__", "//other"], } - + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -317,6 +466,36 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + // Verify that //top/nested:__subpackages__ allows the module to be referenced from the current + // directory and sub directories but nowhere else. + name: "//top/nested:__subpackages__ (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: ["//top/nested:__subpackages__", "//other"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "top/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "other-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { // Verify that ["//top/nested", "//peak:__subpackages"] allows the module to be referenced from // the current directory, top/nested and peak and all its subpackages. @@ -327,7 +506,7 @@ var visibilityTests = []struct { name: "libexample", visibility: ["//top/nested", "//peak:__subpackages__"], } - + mock_library { name: "libsamepackage", deps: ["libexample"], @@ -344,6 +523,33 @@ var visibilityTests = []struct { }`), }, }, + { + // Verify that ["//top/nested", "//peak:__subpackages"] allows the module to be referenced from + // the current directory, top/nested and peak and all its subpackages. + name: `["//top/nested", "//peak:__subpackages__ (notices)"]`, + fs: MockFS{ + "top/Android.bp": []byte(` + mock_library { + name: "libexample", + visibility: ["//top/nested", "//peak:__subpackages__"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "peak/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + }, { // Verify that //vendor... cannot be used outside vendor apart from //vendor:__subpackages__ name: `//vendor`, @@ -353,7 +559,7 @@ var visibilityTests = []struct { name: "libexample", visibility: ["//vendor:__subpackages__"], } - + mock_library { name: "libsamepackage", visibility: ["//vendor/apps/AcmeSettings"], @@ -417,6 +623,45 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + // Check that visibility is the union of the defaults modules. + name: "defaults union, basic (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//other"], + } + mock_library { + name: "libexample", + visibility: ["//top/nested"], + defaults: ["libexample_defaults"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "defaults union, multiple defaults", fs: MockFS{ @@ -458,6 +703,47 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "defaults union, multiple defaults (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults_1", + visibility: ["//other"], + } + mock_defaults { + name: "libexample_defaults_2", + visibility: ["//top/nested"], + } + mock_library { + name: "libexample", + defaults: ["libexample_defaults_1", "libexample_defaults_2"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "//visibility:public mixed with other in defaults", fs: MockFS{ @@ -499,6 +785,29 @@ var visibilityTests = []struct { qualifiedModuleName{pkg: "top", name: "libexample"}: {"//visibility:public"}, }, }, + { + name: "//visibility:public overriding defaults (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//namespace"], + } + mock_library { + name: "libexample", + visibility: ["//visibility:public"], + defaults: ["libexample_defaults"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + effectiveVisibility: map[qualifiedModuleName][]string{ + qualifiedModuleName{pkg: "top", name: "libexample"}: {"//visibility:public"}, + }, + }, { name: "//visibility:public mixed with other from different defaults 1", fs: MockFS{ @@ -522,6 +831,34 @@ var visibilityTests = []struct { }`), }, }, + { + name: "//visibility:public mixed with other from different defaults 1", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults_1", + visibility: ["//namespace"], + } + mock_defaults { + name: "libexample_defaults_2", + visibility: ["//visibility:public"], + } + mock_library { + name: "libexample", + defaults: ["libexample_defaults_1", "libexample_defaults_2"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + }, { name: "//visibility:public mixed with other from different defaults 2", fs: MockFS{ @@ -545,6 +882,29 @@ var visibilityTests = []struct { }`), }, }, + { + name: "//visibility:public mixed with other from different defaults 2 (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults_1", + visibility: ["//visibility:public"], + } + mock_defaults { + name: "libexample_defaults_2", + visibility: ["//namespace"], + } + mock_library { + name: "libexample", + defaults: ["libexample_defaults_1", "libexample_defaults_2"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + }, { name: "//visibility:private in defaults", fs: MockFS{ @@ -579,6 +939,39 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "//visibility:private in defaults (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//visibility:private"], + } + mock_library { + name: "libexample", + defaults: ["libexample_defaults"], + } + + gen_notice { + name: "libexample-notice", + for: ["libexample"], + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "nested-notice" references "//top:libexample" which is not visible to this module`, + `module "other-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "//visibility:private mixed with other in defaults", fs: MockFS{ @@ -705,6 +1098,27 @@ var visibilityTests = []struct { }`), }, }, + { + name: "//visibility:override discards //visibility:private (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//visibility:private"], + } + mock_library { + name: "libexample", + // Make this visibility to //other but not //visibility:private + visibility: ["//visibility:override", "//other"], + defaults: ["libexample_defaults"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + }, + }, { name: "//visibility:override discards //visibility:public", fs: MockFS{ @@ -734,6 +1148,35 @@ var visibilityTests = []struct { `module "libnamespace" variant "android_common": depends on //top:libexample which is not visible to this module\nYou may need to add "//namespace" to its visibility`, }, }, + { + name: "//visibility:override discards //visibility:public (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//visibility:public"], + } + mock_library { + name: "libexample", + // Make this visibility to //other but not //visibility:public + visibility: ["//visibility:override", "//other"], + defaults: ["libexample_defaults"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + "namespace/Android.bp": []byte(` + gen_notice { + name: "namespace-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "namespace-notice" references "//top:libexample" which is not visible to this module\nYou may need to add "//namespace" to its visibility`, + }, + }, { name: "//visibility:override discards defaults supplied rules", fs: MockFS{ @@ -763,6 +1206,35 @@ var visibilityTests = []struct { `module "libnamespace" variant "android_common": depends on //top:libexample which is not visible to this module\nYou may need to add "//namespace" to its visibility`, }, }, + { + name: "//visibility:override discards defaults supplied rules (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//namespace"], + } + mock_library { + name: "libexample", + // Make this visibility to //other but not //namespace + visibility: ["//visibility:override", "//other"], + defaults: ["libexample_defaults"], + }`), + "other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libexample"], + }`), + "namespace/Android.bp": []byte(` + gen_notice { + name: "namespace-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "namespace-notice" references "//top:libexample" which is not visible to this module\nYou may need to add "//namespace" to its visibility`, + }, + }, { name: "//visibility:override can override //visibility:public with //visibility:private", fs: MockFS{ @@ -786,6 +1258,29 @@ var visibilityTests = []struct { `module "libnamespace" variant "android_common": depends on //top:libexample which is not visible to this module`, }, }, + { + name: "//visibility:override can override //visibility:public with //visibility:private (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//visibility:public"], + } + mock_library { + name: "libexample", + visibility: ["//visibility:override", "//visibility:private"], + defaults: ["libexample_defaults"], + }`), + "namespace/Android.bp": []byte(` + gen_notice { + name: "namespace-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "namespace-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "//visibility:override can override //visibility:private with //visibility:public", fs: MockFS{ @@ -806,6 +1301,26 @@ var visibilityTests = []struct { }`), }, }, + { + name: "//visibility:override can override //visibility:private with //visibility:public (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults", + visibility: ["//visibility:private"], + } + mock_library { + name: "libexample", + visibility: ["//visibility:override", "//visibility:public"], + defaults: ["libexample_defaults"], + }`), + "namespace/Android.bp": []byte(` + gen_notice { + name: "namespace-notice", + for: ["libexample"], + }`), + }, + }, { name: "//visibility:private mixed with itself", fs: MockFS{ @@ -834,6 +1349,33 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "//visibility:private mixed with itself (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_defaults { + name: "libexample_defaults_1", + visibility: ["//visibility:private"], + } + mock_defaults { + name: "libexample_defaults_2", + visibility: ["//visibility:private"], + } + mock_library { + name: "libexample", + visibility: ["//visibility:private"], + defaults: ["libexample_defaults_1", "libexample_defaults_2"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, // Defaults module's defaults_visibility tests { @@ -902,6 +1444,28 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + // This test relies on the default visibility being legacy_public. + name: "package default_visibility property used when no visibility specified (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: ["//visibility:private"], + } + + mock_library { + name: "libexample", + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "package default_visibility public does not override visibility private", fs: MockFS{ @@ -925,6 +1489,28 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "package default_visibility public does not override visibility private (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: ["//visibility:public"], + } + + mock_library { + name: "libexample", + visibility: ["//visibility:private"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "package default_visibility private does not override visibility public", fs: MockFS{ @@ -944,6 +1530,25 @@ var visibilityTests = []struct { }`), }, }, + { + name: "package default_visibility private does not override visibility public (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: ["//visibility:private"], + } + + mock_library { + name: "libexample", + visibility: ["//visibility:public"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + }, { name: "package default_visibility :__subpackages__", fs: MockFS{ @@ -971,6 +1576,32 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "package default_visibility :__subpackages__ (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: [":__subpackages__"], + } + + mock_library { + name: "libexample", + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "package default_visibility inherited to subpackages", fs: MockFS{ @@ -981,7 +1612,7 @@ var visibilityTests = []struct { mock_library { name: "libexample", - visibility: [":__subpackages__"], + visibility: [":__subpackages__"], }`), "top/nested/Android.bp": []byte(` mock_library { @@ -999,6 +1630,38 @@ var visibilityTests = []struct { ` visible to this module`, }, }, + { + name: "package default_visibility inherited to subpackages (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: ["//outsider"], + } + + mock_library { + name: "libexample", + visibility: [":__subpackages__"], + }`), + "top/nested/Android.bp": []byte(` + mock_library { + name: "libnested", + deps: ["libexample"], + } + + gen_notice { + name: "nested-notice", + for: ["libexample"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libexample", "libnested"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top:libexample" which is not visible to this module`, + }, + }, { name: "package default_visibility inherited to subpackages", fs: MockFS{ @@ -1029,6 +1692,41 @@ var visibilityTests = []struct { ` not visible to this module`, }, }, + { + name: "package default_visibility inherited to subpackages (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + package { + default_visibility: ["//visibility:private"], + }`), + "top/nested/Android.bp": []byte(` + package { + default_visibility: ["//outsider"], + } + + mock_library { + name: "libnested", + }`), + "top/other/Android.bp": []byte(` + mock_library { + name: "libother", + } + + gen_notice { + name: "other-notice", + for: ["libother"], + }`), + "outsider/Android.bp": []byte(` + gen_notice { + name: "outsider-notice", + for: ["libother", "libnested"], + }`), + }, + expectedErrors: []string{ + `module "outsider-notice" references "//top/other:libother" which is not visible to this` + + ` module\nYou may need to add "//outsider" to its visibility`, + }, + }, { name: "verify that prebuilt dependencies are ignored for visibility reasons (not preferred)", fs: MockFS{ @@ -1051,6 +1749,28 @@ var visibilityTests = []struct { }`), }, }, + { + name: "verify that prebuilt dependencies are ignored for visibility reasons (not preferred) (notices)", + fs: MockFS{ + "prebuilts/Android.bp": []byte(` + prebuilt { + name: "module", + visibility: ["//top/other"], + }`), + "top/sources/source_file": nil, + "top/sources/Android.bp": []byte(` + source { + name: "module", + visibility: ["//top/other"], + }`), + "top/other/source_file": nil, + "top/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["module"], + }`), + }, + }, { name: "verify that prebuilt dependencies are ignored for visibility reasons (preferred)", fs: MockFS{ @@ -1074,6 +1794,29 @@ var visibilityTests = []struct { }`), }, }, + { + name: "verify that prebuilt dependencies are ignored for visibility reasons (preferred) (notices)", + fs: MockFS{ + "prebuilts/Android.bp": []byte(` + prebuilt { + name: "module", + visibility: ["//top/other"], + prefer: true, + }`), + "top/sources/source_file": nil, + "top/sources/Android.bp": []byte(` + source { + name: "module", + visibility: ["//top/other"], + }`), + "top/other/source_file": nil, + "top/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["module"], + }`), + }, + }, { name: "ensure visibility properties are checked for correctness", fs: MockFS{ @@ -1137,6 +1880,30 @@ var visibilityTests = []struct { }`), }, }, + { + name: "automatic visibility inheritance enabled (notices)", + fs: MockFS{ + "top/Android.bp": []byte(` + mock_parent { + name: "parent", + visibility: ["//top/nested"], + child: { + name: "libchild", + visibility: ["//top/other"], + }, + }`), + "top/nested/Android.bp": []byte(` + gen_notice { + name: "nested-notice", + for: ["libchild"], + }`), + "top/other/Android.bp": []byte(` + gen_notice { + name: "other-notice", + for: ["libchild"], + }`), + }, + }, } func TestVisibility(t *testing.T) { @@ -1147,6 +1914,7 @@ func TestVisibility(t *testing.T) { // registration order. PrepareForTestWithArchMutator, PrepareForTestWithDefaults, + PrepareForTestWithGenNotice, PrepareForTestWithOverrides, PrepareForTestWithPackageModule, PrepareForTestWithPrebuilts,