1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.cuttlefish.test; 17 18 import com.android.tradefed.build.IBuildInfo; 19 import com.google.inject.Inject; 20 import javax.annotation.Nullable; 21 22 /** 23 * Manager for a dedicated GCE instance for every @Test function. 24 * 25 * Must be constructed through Guice injection. Calls out to the cvd_test_gce_driver binary to 26 * create the GCE instances. 27 */ 28 public final class BuildChooser { 29 @Inject(optional = true) 30 @SetOption("build-flavor") 31 @Nullable 32 private String buildFlavorOption = null; 33 34 @Inject(optional = true) @SetOption("build-id") @Nullable private String buildIdOption = null; 35 36 @Inject private IBuildInfo buildInfo; 37 fetchCvdBuild()38 public String fetchCvdBuild() { 39 return buildId() + "/" + buildFlavor(); 40 } 41 buildProto()42 public Build buildProto() { 43 return Build.newBuilder().setId(buildId()).setTarget(buildFlavor()).build(); 44 } 45 buildFlavor()46 public String buildFlavor() { 47 if (buildFlavorOption != null) { 48 return buildFlavorOption; 49 } 50 return buildInfo.getBuildFlavor(); 51 } 52 buildId()53 public String buildId() { 54 if (buildIdOption != null) { 55 return buildIdOption; 56 } 57 return buildInfo.getBuildId(); 58 } 59 } 60