1// Copyright (C) 2019 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package robolectric 16 17import ( 18 "fmt" 19 "strings" 20 21 "android/soong/android" 22) 23 24var pctx = android.NewPackageContext("android/soong/robolectric") 25 26func init() { 27 pctx.Import("android/soong/android") 28 android.RegisterModuleType("robolectric_build_props", buildPropsFactory) 29} 30 31type buildProps struct { 32 android.ModuleBase 33 output android.WritablePath 34} 35 36var _ android.SourceFileProducer = (*buildProps)(nil) 37 38func (b *buildProps) Srcs() android.Paths { 39 return android.Paths{b.output} 40} 41 42func (b *buildProps) GenerateAndroidBuildActions(ctx android.ModuleContext) { 43 44 displayID := fmt.Sprintf("robolectric %s %s", 45 ctx.Config().PlatformVersionName(), 46 ctx.Config().BuildId()) 47 48 lines := []string{ 49 "# build properties autogenerated by robolectric.go", 50 "", 51 "ro.build.id=" + ctx.Config().BuildId(), 52 "ro.build.display.id=" + displayID, 53 "ro.product.name=robolectric", 54 "ro.product.device=robolectric", 55 "ro.product.board=robolectric", 56 "ro.product.manufacturer=robolectric", 57 "ro.product.brand=robolectric", 58 "ro.product.model=robolectric", 59 "ro.hardware=robolectric", 60 "ro.build.version.security_patch=" + ctx.Config().PlatformSecurityPatch(), 61 "ro.build.version.sdk=" + ctx.Config().PlatformSdkVersion(), 62 "ro.build.version.release=" + ctx.Config().PlatformVersionName(), 63 "ro.build.version.preview_sdk=" + ctx.Config().PlatformPreviewSdkVersion(), 64 // We don't have the API fingerprint available, just use the preview SDK version. 65 "ro.build.version.preview_sdk_fingerprint=" + ctx.Config().PlatformPreviewSdkVersion(), 66 "ro.build.version.codename=" + ctx.Config().PlatformSdkCodename(), 67 "ro.build.version.all_codenames=" + strings.Join(ctx.Config().PlatformVersionActiveCodenames(), ","), 68 "ro.build.version.min_supported_target_sdk=" + ctx.Config().PlatformMinSupportedTargetSdkVersion(), 69 "ro.build.version.base_os=" + ctx.Config().PlatformBaseOS(), 70 "ro.build.tags=robolectric", 71 "ro.build.fingerprint=robolectric", 72 "ro.build.characteristics=robolectric", 73 "", 74 "# for backwards-compatibility reasons, set CPUs to unknown/ARM", 75 "ro.product.cpu.abi=unknown", 76 "ro.product.cpu.abi2=unknown", 77 "ro.product.cpu.abilist=armeabi-v7a", 78 "ro.product.cpu.abilist32=armeabi-v7a,armeabi", 79 "ro.product.cpu.abilist64=armeabi-v7a,armeabi", 80 "", 81 "# temp fix for robolectric freezing issue b/150011638", 82 "persist.debug.new_insets=0", 83 } 84 85 b.output = android.PathForModuleGen(ctx, "build.prop") 86 87 rule := android.NewRuleBuilder() 88 89 rule.Command().Text("rm").Flag("-f").Output(b.output) 90 for _, l := range lines { 91 rule.Command().Text("echo").Text("'" + l + "'").Text(">>").Output(b.output) 92 } 93 94 rule.Build(pctx, ctx, "build_prop", "robolectric build.prop") 95} 96 97func buildPropsFactory() android.Module { 98 module := &buildProps{} 99 android.InitAndroidModule(module) 100 return module 101} 102