kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/extractors/cmd/bazel/extract_kzip/extract_kzip.go (about) 1 /* 2 * Copyright 2017 The Kythe Authors. All rights reserved. 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 17 // Program extract_kzip implements a Bazel extra action that captures a Kythe 18 // compilation record for a "spawn" action. 19 package main 20 21 import ( 22 "context" 23 "flag" 24 "time" 25 26 "kythe.io/kythe/go/extractors/bazel" 27 "kythe.io/kythe/go/extractors/bazel/extutil" 28 "kythe.io/kythe/go/util/log" 29 ) 30 31 var ( 32 outputPath = flag.String("output", "", "Path of output index file (required)") 33 34 settings bazel.Settings 35 ) 36 37 func init() { 38 flag.Usage = settings.SetFlags(nil, "") 39 } 40 41 func main() { 42 flag.Parse() 43 44 // Verify that required flags are set. 45 if *outputPath == "" { 46 log.Fatal("You must provide a non-empty --output file path") 47 } 48 49 config, info, err := bazel.NewFromSettings(settings) 50 if err != nil { 51 log.Fatalf("Invalid config settings: %v", err) 52 } 53 54 ctx := context.Background() 55 start := time.Now() 56 ai, err := bazel.SpawnAction(info) 57 if err != nil { 58 log.Fatalf("Invalid extra action: %v", err) 59 } 60 if err := extutil.ExtractAndWrite(ctx, config, ai, *outputPath); err != nil { 61 log.Fatalf("Extraction failed: %v", err) 62 } 63 log.Infof("Finished extracting [%v elapsed]", time.Since(start)) 64 }