github.com/distbuild/reclient@v0.0.0-20240401075343-3de72e395564/internal/pkg/inputprocessor/action/headerabi/preprocessor.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 headerabi performs include processing given a valid ABI header dump action. 16 package headerabi 17 18 import ( 19 "fmt" 20 21 "github.com/bazelbuild/reclient/internal/pkg/inputprocessor/action/cppcompile" 22 "github.com/bazelbuild/reclient/internal/pkg/inputprocessor/flags" 23 ) 24 25 // Preprocessor is the preprocessor of header-abi-dumper actions. 26 type Preprocessor struct { 27 *cppcompile.Preprocessor 28 } 29 30 // ParseFlags parses the commands flags and populates the ActionSpec object with inferred 31 // information. 32 func (p *Preprocessor) ParseFlags() error { 33 f, err := Parser{}.ParseFlags(p.Ctx, p.Options.Cmd, p.Options.WorkingDir, p.Options.ExecRoot) 34 if err != nil { 35 p.Err = fmt.Errorf("flag parsing failed. %v", err) 36 return p.Err 37 } 38 p.Flags = f 39 p.FlagsToActionSpec() 40 return nil 41 } 42 43 // ComputeSpec computes cpp header dependencies. 44 func (p *Preprocessor) ComputeSpec() error { 45 p.Flags = headerABIToCppFlags(p.Flags) 46 return p.Preprocessor.ComputeSpec() 47 } 48 49 func headerABIToCppFlags(f *flags.CommandFlags) *flags.CommandFlags { 50 // Ignore --root-dir argument since it is specific to the header-abi-dumper 51 // command and doesn't translate into a clang-argument. 52 res := f.Copy() 53 res.Flags = []*flags.Flag{} 54 for i := 0; i < len(f.Flags); i++ { 55 if f.Flags[i].Key == "--root-dir" { 56 continue 57 } 58 res.Flags = append(res.Flags, f.Flags[i]) 59 } 60 return res 61 }