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

Commit 33ee2546 authored by Paul Duffin's avatar Paul Duffin Committed by Gerrit Code Review
Browse files

Merge changes I42cb181f,I6413c9b1

* changes:
  Add sdk_version:"core_platform" to replace no_framework_libs:true
  Remove the no_standard_libs property
parents 2deb017c 50c217c7
Loading
Loading
Loading
Loading
+2 −16
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ func createNeverAllows() []*rule {
	rules = append(rules, createTrebleRules()...)
	rules = append(rules, createLibcoreRules()...)
	rules = append(rules, createJavaDeviceForHostRules()...)
	rules = append(rules, createJavaLibraryHostRules()...)
	return rules
}

@@ -101,13 +100,9 @@ func createLibcoreRules() []*rule {
		"development",
	}

	// Core library constraints. The no_standard_libs can only be used in core
	// library projects. Access to core library targets is restricted using
	// visibility rules.
	// Core library constraints. The sdk_version: "none" can only be used in core library projects.
	// Access to core library targets is restricted using visibility rules.
	rules := []*rule{
		neverallow().
			notIn(coreLibraryProjects...).
			with("no_standard_libs", "true"),
		neverallow().
			notIn(coreLibraryProjects...).
			with("sdk_version", "none"),
@@ -131,15 +126,6 @@ func createJavaDeviceForHostRules() []*rule {
	}
}

func createJavaLibraryHostRules() []*rule {
	return []*rule{
		neverallow().
			moduleType("java_library_host").
			with("no_standard_libs", "true").
			because("no_standard_libs makes no sense with java_library_host"),
	}
}

func neverallowMutator(ctx BottomUpMutatorContext) {
	m, ok := ctx.Module().(Module)
	if !ok {
+2 −46
Original line number Diff line number Diff line
@@ -147,37 +147,6 @@ var neverallowTests = []struct {
		expectedError: "java_device_for_host can only be used in whitelisted projects",
	},
	// Libcore rule tests
	{
		name: "no_standard_libs: true inside core libraries",
		fs: map[string][]byte{
			"libcore/Blueprints": []byte(`
				java_library {
					name: "inside_core_libraries",
					no_standard_libs: true,
				}`),
		},
	},
	{
		name: "no_standard_libs: true outside core libraries",
		fs: map[string][]byte{
			"Blueprints": []byte(`
				java_library {
					name: "outside_core_libraries",
					no_standard_libs: true,
				}`),
		},
		expectedError: "module \"outside_core_libraries\": violates neverallow",
	},
	{
		name: "no_standard_libs: false",
		fs: map[string][]byte{
			"Blueprints": []byte(`
				java_library {
					name: "outside_core_libraries",
					no_standard_libs: false,
				}`),
		},
	},
	{
		name: "sdk_version: \"none\" inside core libraries",
		fs: map[string][]byte{
@@ -209,18 +178,6 @@ var neverallowTests = []struct {
				}`),
		},
	},
	// java_library_host rule tests
	{
		name: "java_library_host with no_standard_libs: true",
		fs: map[string][]byte{
			"libcore/Blueprints": []byte(`
				java_library_host {
					name: "inside_core_libraries",
					no_standard_libs: true,
				}`),
		},
		expectedError: "module \"inside_core_libraries\": violates neverallow",
	},
}

func TestNeverallow(t *testing.T) {
@@ -296,7 +253,6 @@ func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) {

type mockJavaLibraryProperties struct {
	Libs        []string
	No_standard_libs *bool
	Sdk_version *string
}

+0 −1
Original line number Diff line number Diff line
@@ -185,7 +185,6 @@ func init() {
			"LOCAL_NO_CRT":                     "nocrt",
			"LOCAL_ALLOW_UNDEFINED_SYMBOLS":    "allow_undefined_symbols",
			"LOCAL_RTTI_FLAG":                  "rtti",
			"LOCAL_NO_STANDARD_LIBRARIES":      "no_standard_libs",
			"LOCAL_PACK_MODULE_RELOCATIONS":    "pack_relocations",
			"LOCAL_TIDY":                       "tidy",
			"LOCAL_USE_CLANG_LLD":              "use_clang_lld",
+0 −4
Original line number Diff line number Diff line
@@ -517,10 +517,6 @@ func (a *AARImport) noFrameworkLibs() bool {
	return false
}

func (a *AARImport) noStandardLibs() bool {
	return false
}

var _ AndroidLibraryDependency = (*AARImport)(nil)

func (a *AARImport) ExportPackage() android.Path {
+157 −2
Original line number Diff line number Diff line
@@ -546,7 +546,7 @@ func TestAppSdkVersion(t *testing.T) {
	}
}

func TestJNIABI(t *testing.T) {
func TestJNIABI_no_framework_libs_true(t *testing.T) {
	ctx := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
		cc_library {
			name: "libjni",
@@ -619,7 +619,80 @@ func TestJNIABI(t *testing.T) {
	}
}

func TestJNIPackaging(t *testing.T) {
func TestJNIABI(t *testing.T) {
	ctx := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
		cc_library {
			name: "libjni",
			system_shared_libs: [],
			stl: "none",
		}

		android_test {
			name: "test",
			sdk_version: "core_platform",
			jni_libs: ["libjni"],
		}

		android_test {
			name: "test_first",
			sdk_version: "core_platform",
			compile_multilib: "first",
			jni_libs: ["libjni"],
		}

		android_test {
			name: "test_both",
			sdk_version: "core_platform",
			compile_multilib: "both",
			jni_libs: ["libjni"],
		}

		android_test {
			name: "test_32",
			sdk_version: "core_platform",
			compile_multilib: "32",
			jni_libs: ["libjni"],
		}

		android_test {
			name: "test_64",
			sdk_version: "core_platform",
			compile_multilib: "64",
			jni_libs: ["libjni"],
		}
		`)

	testCases := []struct {
		name string
		abis []string
	}{
		{"test", []string{"arm64-v8a"}},
		{"test_first", []string{"arm64-v8a"}},
		{"test_both", []string{"arm64-v8a", "armeabi-v7a"}},
		{"test_32", []string{"armeabi-v7a"}},
		{"test_64", []string{"arm64-v8a"}},
	}

	for _, test := range testCases {
		t.Run(test.name, func(t *testing.T) {
			app := ctx.ModuleForTests(test.name, "android_common")
			jniLibZip := app.Output("jnilibs.zip")
			var abis []string
			args := strings.Fields(jniLibZip.Args["jarArgs"])
			for i := 0; i < len(args); i++ {
				if args[i] == "-P" {
					abis = append(abis, filepath.Base(args[i+1]))
					i++
				}
			}
			if !reflect.DeepEqual(abis, test.abis) {
				t.Errorf("want abis %v, got %v", test.abis, abis)
			}
		})
	}
}

func TestJNIPackaging_no_framework_libs_true(t *testing.T) {
	ctx := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
		cc_library {
			name: "libjni",
@@ -700,7 +773,89 @@ func TestJNIPackaging(t *testing.T) {
			}
		})
	}
}

func TestJNIPackaging(t *testing.T) {
	ctx := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
		cc_library {
			name: "libjni",
			system_shared_libs: [],
			stl: "none",
		}

		android_app {
			name: "app",
			jni_libs: ["libjni"],
		}

		android_app {
			name: "app_noembed",
			jni_libs: ["libjni"],
			use_embedded_native_libs: false,
		}

		android_app {
			name: "app_embed",
			jni_libs: ["libjni"],
			use_embedded_native_libs: true,
		}

		android_test {
			name: "test",
			sdk_version: "core_platform",
			jni_libs: ["libjni"],
		}

		android_test {
			name: "test_noembed",
			sdk_version: "core_platform",
			jni_libs: ["libjni"],
			use_embedded_native_libs: false,
		}

		android_test_helper_app {
			name: "test_helper",
			sdk_version: "core_platform",
			jni_libs: ["libjni"],
		}

		android_test_helper_app {
			name: "test_helper_noembed",
			sdk_version: "core_platform",
			jni_libs: ["libjni"],
			use_embedded_native_libs: false,
		}
		`)

	testCases := []struct {
		name       string
		packaged   bool
		compressed bool
	}{
		{"app", false, false},
		{"app_noembed", false, false},
		{"app_embed", true, false},
		{"test", true, false},
		{"test_noembed", true, true},
		{"test_helper", true, false},
		{"test_helper_noembed", true, true},
	}

	for _, test := range testCases {
		t.Run(test.name, func(t *testing.T) {
			app := ctx.ModuleForTests(test.name, "android_common")
			jniLibZip := app.MaybeOutput("jnilibs.zip")
			if g, w := (jniLibZip.Rule != nil), test.packaged; g != w {
				t.Errorf("expected jni packaged %v, got %v", w, g)
			}

			if jniLibZip.Rule != nil {
				if g, w := !strings.Contains(jniLibZip.Args["jarArgs"], "-L 0"), test.compressed; g != w {
					t.Errorf("expected jni compressed %v, got %v", w, g)
				}
			}
		})
	}
}

func TestCertificates(t *testing.T) {
Loading