kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/extractors/gcp/config/bazel.go (about) 1 /* 2 * Copyright 2018 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 package config 18 19 import ( 20 "path" 21 22 "kythe.io/kythe/go/extractors/constants" 23 24 rpb "kythe.io/kythe/proto/repo_go_proto" 25 26 "google.golang.org/api/cloudbuild/v1" 27 ) 28 29 type bazelGenerator struct{} 30 31 const defaultBazelTarget = "//..." 32 33 // preExtractSteps implements parts of buildSystemElaborator 34 func (b bazelGenerator) preExtractSteps() []*cloudbuild.BuildStep { 35 return []*cloudbuild.BuildStep{} 36 } 37 38 // extractSteps implements parts of buildSystemElaborator 39 func (b bazelGenerator) extractSteps(corpus string, target *rpb.ExtractionTarget, _ string /* unused prefix */) []*cloudbuild.BuildStep { 40 args := []string{ 41 "build", 42 "-k", 43 "--define", 44 "kythe_corpus=${_CORPUS}", 45 } 46 47 // Default target to just //... 48 if len(target.IndividualTargets) == 0 { 49 args = append(args, defaultBazelTarget) 50 } else { 51 args = append(args, target.IndividualTargets...) 52 } 53 54 return []*cloudbuild.BuildStep{ 55 56 &cloudbuild.BuildStep{ 57 Name: constants.BazelImage, 58 Args: args, 59 Dir: codeDirectory, 60 Id: extractStepID, 61 }, 62 } 63 } 64 65 // postExtractSteps implements parts of buildSystemElaborator 66 func (b bazelGenerator) postExtractSteps(corpus string) []*cloudbuild.BuildStep { 67 // kythe-public/bazel-extractor includes zipmerge already, because we won't 68 // know where bazel deposits kzips ahead of time. 69 return []*cloudbuild.BuildStep{ 70 &cloudbuild.BuildStep{ 71 Name: "ubuntu", 72 Args: []string{ 73 "mv", 74 path.Join(outputDirectory, "compilations.kzip"), 75 path.Join(outputDirectory, outputFileName()), 76 }, 77 Id: renameStepID, 78 }, 79 } 80 } 81 82 // defaultConfigFile implements parts of buildSystemElaborator 83 func (b bazelGenerator) defaultExtractionTarget() *rpb.ExtractionTarget { 84 return &rpb.ExtractionTarget{ 85 Path: "build.gradle", 86 } 87 }