Allow `first_version: "current"` in ndk_library.

Test: Added a test module that uses this
      find $SOONG_OUT -name libfoo.so # only shows up in current
Bug: None

Change-Id: Ic88d7c598cd5b6ded8fb851a7eaf859806336af7
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index d603ad0..f733515 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -109,7 +109,11 @@
 	}
 }
 
-func normalizeNdkApiLevel(apiLevel string, arch android.Arch) (int, error) {
+func normalizeNdkApiLevel(apiLevel string, arch android.Arch) (string, error) {
+	if apiLevel == "current" {
+		return apiLevel, nil
+	}
+
 	minVersion := 9 // Minimum version supported by the NDK.
 	firstArchVersions := map[string]int{
 		"arm":    9,
@@ -125,7 +129,7 @@
 	// supported version here instead.
 	version, err := strconv.Atoi(apiLevel)
 	if err != nil {
-		return -1, fmt.Errorf("API level must be an integer (is %q)", apiLevel)
+		return "", fmt.Errorf("API level must be an integer (is %q)", apiLevel)
 	}
 	version = intMax(version, minVersion)
 
@@ -135,20 +139,35 @@
 		panic(fmt.Errorf("Arch %q not found in firstArchVersions", archStr))
 	}
 
-	return intMax(version, firstArchVersion), nil
+	return strconv.Itoa(intMax(version, firstArchVersion)), nil
+}
+
+func getFirstGeneratedVersion(firstSupportedVersion string, platformVersion int) (int, error) {
+	if firstSupportedVersion == "current" {
+		return platformVersion + 1, nil
+	}
+
+	return strconv.Atoi(firstSupportedVersion)
 }
 
 func generateStubApiVariants(mctx android.BottomUpMutatorContext, c *stubDecorator) {
-	maxVersion := mctx.AConfig().PlatformSdkVersionInt()
+	platformVersion := mctx.AConfig().PlatformSdkVersionInt()
 
-	firstVersion, err := normalizeNdkApiLevel(c.properties.First_version,
+	firstSupportedVersion, err := normalizeNdkApiLevel(c.properties.First_version,
 		mctx.Arch())
 	if err != nil {
 		mctx.PropertyErrorf("first_version", err.Error())
 	}
 
+	firstGenVersion, err := getFirstGeneratedVersion(firstSupportedVersion, platformVersion)
+	if err != nil {
+		// In theory this is impossible because we've already run this through
+		// normalizeNdkApiLevel above.
+		mctx.PropertyErrorf("first_version", err.Error())
+	}
+
 	var versionStrs []string
-	for version := firstVersion; version <= maxVersion; version++ {
+	for version := firstGenVersion; version <= platformVersion; version++ {
 		versionStrs = append(versionStrs, strconv.Itoa(version))
 	}
 	versionStrs = append(versionStrs, "current")