github.com/distbuild/reclient@v0.0.0-20240401075343-3de72e395564/internal/pkg/inputprocessor/action/d8/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 d8 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 TestD8Preprocessor(t *testing.T) { 35 er, cleanup := execroot.Setup(t, []string{"a", "b", "c", "lib", "d8.jar", "java", "file.jar"}) 36 defer cleanup() 37 execroot.AddFileWithContent(t, filepath.Join(er, "java_remote_toolchain_inputs"), []byte("lib")) 38 execroot.AddDirs(t, er, []string{"dex"}) 39 cmd := []string{"d8", "-J-Xmx2048M", "--output", "dex", "--lib", "a", "--lib", "b", "--main-dex-list=c", "file.jar"} 40 ctx := context.Background() 41 pp := &Preprocessor{ 42 &inputprocessor.BasePreprocessor{ 43 Ctx: ctx, 44 }, 45 } 46 gotSpec, err := inputprocessor.Compute(pp, inputprocessor.Options{ 47 ExecRoot: er, 48 ToolchainInputs: []string{"java"}, 49 Cmd: cmd, 50 Inputs: &command.InputSpec{Inputs: []string{"d8.jar"}}, 51 }) 52 if err != nil { 53 t.Errorf("Compute() returned error: %v", err) 54 } 55 wantSpec := &inputprocessor.ActionSpec{ 56 InputSpec: &command.InputSpec{ 57 Inputs: []string{"a", "b", "c", "file.jar", "lib", "d8.jar", "java"}, 58 EnvironmentVariables: map[string]string{ 59 "PATH": ".:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 60 }, 61 VirtualInputs: []*command.VirtualInput{ 62 &command.VirtualInput{Path: "dex", IsEmptyDirectory: true}, 63 }, 64 }, 65 OutputDirectories: []string{"dex"}, 66 } 67 if diff := cmp.Diff(wantSpec, gotSpec, strSliceCmp); diff != "" { 68 t.Errorf("GetActionSpec() returned diff in ActionSpec, (-want +got): %s", diff) 69 } 70 }