• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.tradefed.result.skipped;
17 
18 import build.bazel.remote.execution.v2.Digest;
19 
20 import java.util.Map;
21 import java.util.Set;
22 
23 /** Representation of the context surrounding decision about skipping or caching of results. */
24 public class SkipContext {
25 
26     private final Set<String> unchangedModules;
27     private final boolean presubmit;
28     private final Map<String, Digest> imageToDigest;
29 
SkipContext( boolean presubmit, Set<String> unchangedModules, Map<String, Digest> imageToDigest)30     public SkipContext(
31             boolean presubmit, Set<String> unchangedModules, Map<String, Digest> imageToDigest) {
32         this.presubmit = presubmit;
33         this.unchangedModules = unchangedModules;
34         this.imageToDigest = imageToDigest;
35     }
36 
37     /**
38      * Only skip unchanged modules in presubmit. At this stage the unchanged modules are known
39      * (based on unchanged device image and test artifacts)
40      */
shouldSkipModule(String moduleName)41     public boolean shouldSkipModule(String moduleName) {
42         return presubmit && unchangedModules.contains(moduleName);
43     }
44 
45     /** Reports whether to use caching or not. */
shouldUseCache()46     public boolean shouldUseCache() {
47         // TODO: Distinguish caching situation
48         return true;
49     }
50 
isPresubmit()51     public boolean isPresubmit() {
52         return presubmit;
53     }
54 
getImageToDigest()55     public Map<String, Digest> getImageToDigest() {
56         return imageToDigest;
57     }
58 }
59