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
diff --git a/cc/binary.go b/cc/binary.go
index 1aba6eb..1634a83 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -37,6 +37,10 @@
 	// 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 @@
 	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 @@
 			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) 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)
 	}