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

Commit 1202729c authored by Spandan Das's avatar Spandan Das
Browse files

Use cp instead of install for ndk_headers

ndk_headers currently use ctx.Install to install headers in
out/soong/ndk/sysroot. The files are subsequently used to compile ndk
variants of cc libraries on host.

Since these headers are not actually installed on device, use android.Cp
to assemble the NDK sysroot. By itself, it should be a no-op, but
androd.Cp is more friendly with restricting the installation rules to
PRODUCT_PACKAGES.

To make it explicit that the sysroot is not a typical installation path,
this CL also modifies the type to OutputPath

Test: m
Bug: 332778109
Change-Id: I1131c3c764443cbaac525c6022cd09c47695d275
parent 219ce554
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -1831,17 +1831,13 @@ func pathForInstall(ctx PathContext, os OsType, arch ArchType, partition string,
	return base.Join(ctx, pathComponents...)
}

func pathForNdkOrSdkInstall(ctx PathContext, prefix string, paths []string) InstallPath {
	base := pathForPartitionInstallDir(ctx, "", prefix, false)
	return base.Join(ctx, paths...)
}

func PathForNdkInstall(ctx PathContext, paths ...string) InstallPath {
	return pathForNdkOrSdkInstall(ctx, "ndk", paths)
func PathForNdkInstall(ctx PathContext, paths ...string) OutputPath {
	return PathForOutput(ctx, append([]string{"ndk"}, paths...)...)
}

func PathForMainlineSdksInstall(ctx PathContext, paths ...string) InstallPath {
	return pathForNdkOrSdkInstall(ctx, "mainline-sdks", paths)
	base := pathForPartitionInstallDir(ctx, "", "mainline-sdks", false)
	return base.Join(ctx, paths...)
}

func InstallPathToOnDevicePath(ctx PathContext, path InstallPath) string {
+7 −9
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
package cc

import (
	"fmt"
	"path/filepath"

	"android/soong/android"
@@ -45,7 +44,7 @@ func init() {
}

// Returns the NDK base include path for use with sdk_version current. Usable with -I.
func getCurrentIncludePath(ctx android.ModuleContext) android.InstallPath {
func getCurrentIncludePath(ctx android.ModuleContext) android.OutputPath {
	return getNdkSysrootBase(ctx).Join(ctx, "usr/include")
}

@@ -87,7 +86,7 @@ type headerModule struct {
}

func getHeaderInstallDir(ctx android.ModuleContext, header android.Path, from string,
	to string) android.InstallPath {
	to string) android.OutputPath {
	// Output path is the sysroot base + "usr/include" + to directory + directory component
	// of the file without the leading from directory stripped.
	//
@@ -129,13 +128,12 @@ func (m *headerModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	for _, header := range m.srcPaths {
		installDir := getHeaderInstallDir(ctx, header, String(m.properties.From),
			String(m.properties.To))
		installedPath := ctx.InstallFile(installDir, header.Base(), header)
		installPath := installDir.Join(ctx, header.Base())
		if installPath != installedPath {
			panic(fmt.Sprintf(
				"expected header install path (%q) not equal to actual install path %q",
				installPath, installedPath))
		}
		ctx.Build(pctx, android.BuildParams{
			Rule:   android.Cp,
			Input:  header,
			Output: installPath,
		})
		m.installPaths = append(m.installPaths, installPath)
	}

+3 −3
Original line number Diff line number Diff line
@@ -518,19 +518,19 @@ func (stub *stubDecorator) nativeCoverage() bool {

// Returns the install path for unversioned NDK libraries (currently only static
// libraries).
func getUnversionedLibraryInstallPath(ctx ModuleContext) android.InstallPath {
func getUnversionedLibraryInstallPath(ctx ModuleContext) android.OutputPath {
	return getNdkSysrootBase(ctx).Join(ctx, "usr/lib", config.NDKTriple(ctx.toolchain()))
}

// Returns the install path for versioned NDK libraries. These are most often
// stubs, but the same paths are used for CRT objects.
func getVersionedLibraryInstallPath(ctx ModuleContext, apiLevel android.ApiLevel) android.InstallPath {
func getVersionedLibraryInstallPath(ctx ModuleContext, apiLevel android.ApiLevel) android.OutputPath {
	return getUnversionedLibraryInstallPath(ctx).Join(ctx, apiLevel.String())
}

func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) {
	installDir := getVersionedLibraryInstallPath(ctx, stub.apiLevel)
	stub.installPath = ctx.InstallFile(installDir, path.Base(), path)
	stub.installPath = installDir.Join(ctx, path.Base())
}

func newStubLibrary() *Module {
+2 −2
Original line number Diff line number Diff line
@@ -69,12 +69,12 @@ func RegisterNdkModuleTypes(ctx android.RegistrationContext) {
	ctx.RegisterParallelSingletonType("ndk", NdkSingleton)
}

func getNdkInstallBase(ctx android.PathContext) android.InstallPath {
func getNdkInstallBase(ctx android.PathContext) android.OutputPath {
	return android.PathForNdkInstall(ctx)
}

// Returns the main install directory for the NDK sysroot. Usable with --sysroot.
func getNdkSysrootBase(ctx android.PathContext) android.InstallPath {
func getNdkSysrootBase(ctx android.PathContext) android.OutputPath {
	return getNdkInstallBase(ctx).Join(ctx, "sysroot")
}