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

Commit 4762436a authored by Paul Duffin's avatar Paul Duffin
Browse files

Retry: "java_sdk_library: Extract common stubs redirect code"

The java_sdk_library and java_sdk_library_import redirect a request for
header and implementation jars to broadly the same place although the
java_sdk_library does have some special code that is mixed in with the
common code.

This change separates the java_sdk_library special code from the common
code and moves the common code into its own method for use by both
module types. That makes the special behavior clearer and ensures the
common behavior remains consistent in future.

Test: m nothing
Bug: 155164730
(cherry picked from commit b05d4295)
Change-Id: Id21cc74d2d37c5a75983fdcd7393f6a37f8872c9
parent 933e19a5
Loading
Loading
Loading
Loading
+39 −50
Original line number Diff line number Diff line
@@ -564,6 +564,31 @@ func (c *commonToSdkLibraryAndImport) getScopePaths(scope *apiScope) *scopePaths
	return paths
}

func (c *commonToSdkLibraryAndImport) sdkJarsCommon(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths {

	// If a specific numeric version has been requested then use prebuilt versions of the sdk.
	if sdkVersion.version.isNumbered() {
		return PrebuiltJars(ctx, c.moduleBase.BaseModuleName(), sdkVersion)
	}

	var apiScope *apiScope
	switch sdkVersion.kind {
	case sdkSystem:
		apiScope = apiScopeSystem
	case sdkTest:
		apiScope = apiScopeTest
	default:
		apiScope = apiScopePublic
	}

	paths := c.getScopePaths(apiScope)
	if headerJars {
		return paths.stubsHeaderPath
	} else {
		return paths.stubsImplPath
	}
}

type SdkLibrary struct {
	Library

@@ -1015,41 +1040,20 @@ func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) and
	return android.Paths{jarPath.Path()}
}

func (module *SdkLibrary) sdkJars(
	ctx android.BaseModuleContext,
	sdkVersion sdkSpec,
	headerJars bool) android.Paths {
func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths {

	// If a specific numeric version has been requested then use prebuilt versions of the sdk.
	if sdkVersion.version.isNumbered() {
		return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion)
	} else {
	// Check any special cases for java_sdk_library.
	if !sdkVersion.specified() {
		if headerJars {
			return module.HeaderJars()
		} else {
			return module.ImplementationJars()
		}
		}
		var apiScope *apiScope
		switch sdkVersion.kind {
		case sdkSystem:
			apiScope = apiScopeSystem
		case sdkTest:
			apiScope = apiScopeTest
		case sdkPrivate:
	} else if sdkVersion.kind == sdkPrivate {
		return module.HeaderJars()
		default:
			apiScope = apiScopePublic
	}

		paths := module.getScopePaths(apiScope)
		if headerJars {
			return paths.stubsHeaderPath
		} else {
			return paths.stubsImplPath
		}
	}
	return module.sdkJarsCommon(ctx, sdkVersion, headerJars)
}

// to satisfy SdkLibraryDependency interface
@@ -1463,27 +1467,12 @@ func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
	})
}

func (module *sdkLibraryImport) sdkJars(
	ctx android.BaseModuleContext,
	sdkVersion sdkSpec) android.Paths {
func (module *sdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {

	// If a specific numeric version has been requested then use prebuilt versions of the sdk.
	if sdkVersion.version.isNumbered() {
		return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion)
	}

	var apiScope *apiScope
	switch sdkVersion.kind {
	case sdkSystem:
		apiScope = apiScopeSystem
	case sdkTest:
		apiScope = apiScopeTest
	default:
		apiScope = apiScopePublic
	}

	paths := module.getScopePaths(apiScope)
	return paths.stubsHeaderPath
	// The java_sdk_library_import can only ever give back header jars as it does not
	// have an implementation jar.
	headerJars := true
	return module.sdkJarsCommon(ctx, sdkVersion, headerJars)
}

// to satisfy SdkLibraryDependency interface