Install symlinks with same suffix and extension as installed file

Move symlink installation into the binaryDecorator so that it can
access the suffix and extension when installing symlinks.  Also
consolidates the symlink and symlink_preferred_arch handling.

Test: m -j clang, ls -l out/host/windows-x86/bin/clang++.exe
Change-Id: I1204afb71fac87b276bd6b625b52ee21274855a0
This commit is contained in:
Colin Cross 2016-12-07 13:37:42 -08:00
parent 8cc1cb68cd
commit 9b09f248d8
3 changed files with 36 additions and 22 deletions

View File

@ -140,6 +140,11 @@ func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.Andr
if Bool(binary.Properties.Static_executable) {
fmt.Fprintln(w, "LOCAL_FORCE_STATIC_EXECUTABLE := true")
}
if len(binary.symlinks) > 0 {
fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS := "+strings.Join(binary.symlinks, " "))
}
return nil
})
}
@ -211,9 +216,6 @@ func (installer *baseInstaller) AndroidMk(ctx AndroidMkContext, ret *android.And
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file))
fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
if len(installer.Properties.Symlinks) > 0 {
fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS := "+strings.Join(installer.Properties.Symlinks, " "))
}
return nil
})
}

View File

@ -37,6 +37,10 @@ type BinaryLinkerProperties struct {
// if set, install a symlink to the preferred architecture
Symlink_preferred_arch bool
// install symlinks to the binary. Symlink names will have the suffix and the binary
// extension (if any) appended
Symlinks []string `android:"arch_variant"`
DynamicLinker string `blueprint:"mutated"`
}
@ -69,6 +73,9 @@ type binaryDecorator struct {
Properties BinaryLinkerProperties
toolPath android.OptionalPath
// Names of symlinks to be installed for use in LOCAL_MODULE_SYMLINKS
symlinks []string
}
var _ linker = (*binaryDecorator)(nil)
@ -173,16 +180,6 @@ func (binary *binaryDecorator) linkerInit(ctx BaseModuleContext) {
binary.Properties.Static_executable = nil
}
}
if binary.Properties.Symlink_preferred_arch {
if binary.Properties.Stem == "" && binary.Properties.Suffix == "" {
ctx.PropertyErrorf("symlink_preferred_arch", "must also specify stem or suffix")
}
if ctx.TargetPrimary() {
binary.baseInstaller.Properties.Symlinks = append(binary.baseInstaller.Properties.Symlinks,
ctx.baseModuleName())
}
}
}
func (binary *binaryDecorator) static() bool {
@ -302,6 +299,24 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
func (binary *binaryDecorator) install(ctx ModuleContext, file android.Path) {
binary.baseInstaller.install(ctx, file)
for _, symlink := range binary.Properties.Symlinks {
binary.symlinks = append(binary.symlinks,
symlink+binary.Properties.Suffix+binary.baseInstaller.path.Ext())
}
if binary.Properties.Symlink_preferred_arch {
if binary.Properties.Stem == "" && binary.Properties.Suffix == "" {
ctx.PropertyErrorf("symlink_preferred_arch", "must also specify stem or suffix")
}
if ctx.TargetPrimary() {
binary.symlinks = append(binary.symlinks, ctx.baseModuleName())
}
}
for _, symlink := range binary.symlinks {
ctx.InstallSymlink(binary.baseInstaller.installDir(ctx), symlink, binary.baseInstaller.path)
}
if ctx.Os().Class == android.Host {
binary.toolPath = android.OptionalPathForPath(binary.baseInstaller.path)
}

View File

@ -25,9 +25,6 @@ import (
type InstallerProperties struct {
// install to a subdirectory of the default install path for the module
Relative_install_path string `android:"arch_variant"`
// install symlinks to the module
Symlinks []string `android:"arch_variant"`
}
type installLocation int
@ -62,7 +59,7 @@ func (installer *baseInstaller) installerProps() []interface{} {
return []interface{}{&installer.Properties}
}
func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
func (installer *baseInstaller) installDir(ctx ModuleContext) android.OutputPath {
subDir := installer.dir
if ctx.toolchain().Is64Bit() && installer.dir64 != "" {
subDir = installer.dir64
@ -70,11 +67,11 @@ func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
if !ctx.Host() && !ctx.Arch().Native {
subDir = filepath.Join(subDir, ctx.Arch().ArchType.String())
}
dir := android.PathForModuleInstall(ctx, subDir, installer.Properties.Relative_install_path, installer.relative)
installer.path = ctx.InstallFile(dir, file)
for _, symlink := range installer.Properties.Symlinks {
ctx.InstallSymlink(dir, symlink, installer.path)
}
return android.PathForModuleInstall(ctx, subDir, installer.Properties.Relative_install_path, installer.relative)
}
func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
installer.path = ctx.InstallFile(installer.installDir(ctx), file)
}
func (installer *baseInstaller) inData() bool {