github.com/distbuild/reclient@v0.0.0-20240401075343-3de72e395564/internal/pkg/inputprocessor/action/r8/preprocessor_test.go (about) 1 // Copyright 2023 Google LLC 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 15 package r8 16 17 import ( 18 "context" 19 "path/filepath" 20 "testing" 21 22 "github.com/bazelbuild/reclient/internal/pkg/execroot" 23 "github.com/bazelbuild/reclient/internal/pkg/inputprocessor" 24 25 "github.com/bazelbuild/remote-apis-sdks/go/pkg/command" 26 "github.com/google/go-cmp/cmp" 27 "github.com/google/go-cmp/cmp/cmpopts" 28 ) 29 30 var ( 31 strSliceCmp = cmpopts.SortSlices(func(a, b string) bool { return a < b }) 32 ) 33 34 func TestR8Preprocessor(t *testing.T) { 35 er, cleanup := execroot.Setup(t, []string{"a", "b", "c", "lib", "r8.jar", "java", "file.jar"}) 36 defer cleanup() 37 execroot.AddFilesWithContent(t, er, map[string][]byte{ 38 "subdir/proguard.flags": []byte("flag\n-include sibling.flags"), 39 "subdir/sibling.flags": []byte("flag\n-include ../base.flags"), 40 "base.flags": []byte("flag"), 41 "java_remote_toolchain_inputs": []byte("lib"), 42 }) 43 execroot.AddDirs(t, er, []string{"dex"}) 44 cmd := []string{"r8-compat-proguard", "-J-Xmx2048M", "-injars", "file.jar", "--output", "dex", "-printmapping", "proguard_dict", "-printconfiguration", "print_conf", "-libraryjars", "a:b:c", "-include", "d", "-include", "e", "--main-dex-list", "f", "-include", "subdir/proguard.flags"} 45 pp := &Preprocessor{ 46 &inputprocessor.BasePreprocessor{ 47 Ctx: context.Background(), 48 }, 49 } 50 gotSpec, err := inputprocessor.Compute(pp, inputprocessor.Options{ 51 ExecRoot: er, 52 ToolchainInputs: []string{"java"}, 53 Cmd: cmd, 54 Inputs: &command.InputSpec{Inputs: []string{"r8.jar"}}, 55 }) 56 if err != nil { 57 t.Errorf("Compute() returned error: %v", err) 58 } 59 60 wantSpec := &inputprocessor.ActionSpec{ 61 InputSpec: &command.InputSpec{ 62 Inputs: []string{"a", "b", "c", "file.jar", "lib", "r8.jar", "java", 63 filepath.Clean("subdir/proguard.flags"), filepath.Clean("subdir/sibling.flags"), "base.flags"}, 64 EnvironmentVariables: map[string]string{ 65 "PATH": ".:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 66 }, 67 VirtualInputs: []*command.VirtualInput{ 68 &command.VirtualInput{Path: "dex", IsEmptyDirectory: true}, 69 }, 70 }, 71 OutputFiles: []string{"print_conf", "proguard_dict"}, 72 OutputDirectories: []string{"dex"}, 73 } 74 if diff := cmp.Diff(wantSpec, gotSpec, strSliceCmp); diff != "" { 75 t.Errorf("Compute() returned diff in ActionSpec, (-want +got): %s", diff) 76 } 77 }