From 6dcbd9c2392b0c9d53142d2a21db30d84f27d8b3 Mon Sep 17 00:00:00 2001 From: Prashanth Swaminathan Date: Tue, 18 Jul 2023 17:55:01 -0700 Subject: [PATCH] Convert requested SDK version if preview API level The 'sdk_version' flag should be allowed to specify a preview API level codename. Convert the raw name into an integer using the common library functions. This also switches out the comparison logic to use the ApiLevel as defined by the 'android' library instead of doing string-to-int conversion on the output. Test: Verified that setting VIC as an sdk_version does not crash. Change-Id: I6ed5fb7ff0dcfa3598e74faa656cde7fa2085bae --- cc/cc.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index 608797092..ec4566c43 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -2945,20 +2945,20 @@ func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to Lin ctx.ModuleErrorf("links %q built against newer API version %q", ctx.OtherModuleName(to.Module()), "current") } else { - fromApi, err := strconv.Atoi(from.SdkVersion()) + fromApi, err := android.ApiLevelFromUserWithConfig(ctx.Config(), from.SdkVersion()) if err != nil { ctx.PropertyErrorf("sdk_version", - "Invalid sdk_version value (must be int or current): %q", + "Invalid sdk_version value (must be int, preview or current): %q", from.SdkVersion()) } - toApi, err := strconv.Atoi(to.SdkVersion()) + toApi, err := android.ApiLevelFromUserWithConfig(ctx.Config(), to.SdkVersion()) if err != nil { ctx.PropertyErrorf("sdk_version", - "Invalid sdk_version value (must be int or current): %q", + "Invalid sdk_version value (must be int, preview or current): %q", to.SdkVersion()) } - if toApi > fromApi { + if toApi.GreaterThan(fromApi) { ctx.ModuleErrorf("links %q built against newer API version %q", ctx.OtherModuleName(to.Module()), to.SdkVersion()) }