Stop using GCC in toolchain_library

Instead, hardcode the ~dozen paths into build/soong/Android.bp, which
will unblock removing more GCC support.

Bug: 114286031
Test: m
Change-Id: I2508432e00b1469141f01e667f3c6a2fe30cd805
diff --git a/Android.bp b/Android.bp
index ccab727..aeabb13 100644
--- a/Android.bp
+++ b/Android.bp
@@ -360,9 +360,19 @@
     defaults: ["linux_bionic_supported"],
     vendor_available: true,
     recovery_available: true,
+
     arch: {
         arm: {
-            instruction_set: "arm",
+            src: "prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/arm-linux-androideabi/lib/libatomic.a",
+        },
+        arm64: {
+            src: "prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/lib64/libatomic.a",
+        },
+        x86: {
+            src: "prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/x86_64-linux-android/lib/libatomic.a",
+        },
+        x86_64: {
+            src: "prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/x86_64-linux-android/lib64/libatomic.a",
         },
     },
 }
@@ -372,9 +382,19 @@
     defaults: ["linux_bionic_supported"],
     vendor_available: true,
     recovery_available: true,
+
     arch: {
         arm: {
-            instruction_set: "arm",
+            src: "prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/lib/gcc/arm-linux-androideabi/4.9.x/libgcc.a",
+        },
+        arm64: {
+            src: "prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/lib/gcc/aarch64-linux-android/4.9.x/libgcc.a",
+        },
+        x86: {
+            src: "prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/lib/gcc/x86_64-linux-android/4.9.x/32/libgcc.a",
+        },
+        x86_64: {
+            src: "prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/lib/gcc/x86_64-linux-android/4.9.x/libgcc.a",
         },
     },
 }
@@ -387,15 +407,31 @@
         windows: {
             enabled: true,
         },
+        windows_x86: {
+            src: "prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32/lib32/libwinpthread.a",
+        },
+        windows_x86_64: {
+            src: "prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32/lib/libwinpthread.a",
+        },
     },
 }
 
 toolchain_library {
     name: "libgcov",
     defaults: ["linux_bionic_supported"],
+
     arch: {
         arm: {
-            instruction_set: "arm",
+            src: "prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/lib/gcc/arm-linux-androideabi/4.9.x/libgcov.a",
+        },
+        arm64: {
+            src: "prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/lib/gcc/aarch64-linux-android/4.9.x/libgcov.a",
+        },
+        x86: {
+            src: "prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/lib/gcc/x86_64-linux-android/4.9.x/32/libgcov.a",
+        },
+        x86_64: {
+            src: "prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/lib/gcc/x86_64-linux-android/4.9.x/libgcov.a",
         },
     },
 }
diff --git a/cc/builder.go b/cc/builder.go
index 58196f4..d1bc23f 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -127,17 +127,6 @@
 			Command: "rm -f $out && touch $out",
 		})
 
-	_ = pctx.SourcePathVariable("copyGccLibPath", "build/soong/scripts/copygcclib.sh")
-
-	copyGccLib = pctx.AndroidStaticRule("copyGccLib",
-		blueprint.RuleParams{
-			Depfile:     "${out}.d",
-			Deps:        blueprint.DepsGCC,
-			Command:     "$copyGccLibPath $out $ccCmd $cFlags -print-file-name=${libName}",
-			CommandDeps: []string{"$copyGccLibPath", "$ccCmd"},
-		},
-		"ccCmd", "cFlags", "libName")
-
 	_ = pctx.SourcePathVariable("tocPath", "build/soong/scripts/toc.sh")
 
 	toc = pctx.AndroidStaticRule("toc",
@@ -880,21 +869,6 @@
 	return android.OptionalPath{}
 }
 
-func CopyGccLib(ctx android.ModuleContext, libName string,
-	flags builderFlags, outputFile android.WritablePath) {
-
-	ctx.Build(pctx, android.BuildParams{
-		Rule:        copyGccLib,
-		Description: "copy gcc library " + libName,
-		Output:      outputFile,
-		Args: map[string]string{
-			"ccCmd":   gccCmd(flags.toolchain, "gcc"),
-			"cFlags":  flags.globalFlags,
-			"libName": libName,
-		},
-	})
-}
-
 func gccCmd(toolchain config.Toolchain, cmd string) string {
 	return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd)
 }
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 3d5dfb1..01beb66 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -76,18 +76,21 @@
 			name: "libatomic",
 			vendor_available: true,
 			recovery_available: true,
+			src: "",
 		}
 
 		toolchain_library {
 			name: "libcompiler_rt-extras",
 			vendor_available: true,
 			recovery_available: true,
+			src: "",
 		}
 
 		toolchain_library {
 			name: "libgcc",
 			vendor_available: true,
 			recovery_available: true,
+			src: "",
 		}
 
 		cc_library {
diff --git a/cc/toolchain_library.go b/cc/toolchain_library.go
index 2b117b3..20b0f85 100644
--- a/cc/toolchain_library.go
+++ b/cc/toolchain_library.go
@@ -26,8 +26,15 @@
 	android.RegisterModuleType("toolchain_library", toolchainLibraryFactory)
 }
 
+type toolchainLibraryProperties struct {
+	// the prebuilt toolchain library, as a path from the top of the source tree
+	Src *string `android:"arch_variant"`
+}
+
 type toolchainLibraryDecorator struct {
 	*libraryDecorator
+
+	Properties toolchainLibraryProperties
 }
 
 func (*toolchainLibraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
@@ -35,6 +42,12 @@
 	return deps
 }
 
+func (library *toolchainLibraryDecorator) linkerProps() []interface{} {
+	var props []interface{}
+	props = append(props, library.libraryDecorator.linkerProps()...)
+	return append(props, &library.Properties)
+}
+
 func toolchainLibraryFactory() android.Module {
 	module, library := NewLibrary(android.HostAndDeviceSupported)
 	library.BuildOnlyStatic()
@@ -58,16 +71,10 @@
 func (library *toolchainLibraryDecorator) link(ctx ModuleContext,
 	flags Flags, deps PathDeps, objs Objects) android.Path {
 
-	libName := ctx.ModuleName() + staticLibraryExtension
-	outputFile := android.PathForModuleOut(ctx, libName)
-
-	if flags.Clang {
-		ctx.ModuleErrorf("toolchain_library must use GCC, not Clang")
+	if library.Properties.Src == nil {
+		ctx.PropertyErrorf("src", "No library source specified")
+		return android.PathForSource(ctx, "")
 	}
 
-	CopyGccLib(ctx, libName, flagsToBuilderFlags(flags), outputFile)
-
-	ctx.CheckbuildFile(outputFile)
-
-	return outputFile
+	return android.PathForSource(ctx, *library.Properties.Src)
 }
diff --git a/scripts/copygcclib.sh b/scripts/copygcclib.sh
deleted file mode 100755
index 28359fc..0000000
--- a/scripts/copygcclib.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/bash -e
-
-# Copyright 2017 Google Inc. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-OUT=$1
-shift
-LIBPATH=$($@ | sed -e "s|^$PWD/||")
-cp -f $LIBPATH $OUT
-echo "$OUT: $LIBPATH" > ${OUT}.d