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