kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/extractors/gcp/config/common.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 "fmt" 21 "path" 22 23 "kythe.io/kythe/go/extractors/constants" 24 25 "google.golang.org/api/cloudbuild/v1" 26 ) 27 28 const cloneStepID = "CLONE" 29 const checkoutStepID = "CHECKOUT" 30 const javaArtifactsID = "JAVA-ARTIFACTS" 31 const preStepID = "PREPROCESS" 32 const extractStepID = "EXTRACT" 33 const mergeStepID = "MERGE" 34 const renameStepID = "RENAME" 35 36 // commonSteps returns cloudbuild BuildSteps for copying a repo and creating 37 // an output directory. 38 // 39 // The BuildStep for the repo copy uses id cloneStepID, as described in 40 // https://cloud.google.com/cloud-build/docs/build-config#id, for any future 41 // steps that need to depend on the repo clone step. The repo copy step puts 42 // the code into /workspace/code. 43 // 44 // The output directory is /workspace/out. 45 func commonSteps(repo string) []*cloudbuild.BuildStep { 46 return []*cloudbuild.BuildStep{ 47 &cloudbuild.BuildStep{ 48 Name: constants.GCRGitImage, // This triggers with command 'git'. 49 Args: []string{"clone", repo, codeDirectory}, 50 Id: cloneStepID, 51 WaitFor: []string{"-"}, 52 }, 53 &cloudbuild.BuildStep{ 54 Name: constants.GCRGitImage, // This triggers with command 'git'. 55 Args: []string{"checkout", defaultVersion}, 56 Dir: codeDirectory, 57 Id: checkoutStepID, 58 WaitFor: []string{cloneStepID}, 59 }, 60 } 61 } 62 63 func preprocessorStep(build string, idSuffix string) *cloudbuild.BuildStep { 64 return &cloudbuild.BuildStep{ 65 Name: constants.KytheBuildPreprocessorImage, 66 Args: []string{build}, 67 Id: preStepID + idSuffix, 68 WaitFor: []string{checkoutStepID}, 69 } 70 } 71 72 // TODO(#3095): This step needs to be configurable by the java version used for 73 // a given BuildTarget. 74 func javaExtractorsStep() *cloudbuild.BuildStep { 75 return &cloudbuild.BuildStep{ 76 Name: constants.KytheJavacExtractorArtifactsImage, 77 Volumes: []*cloudbuild.Volume{ 78 &cloudbuild.Volume{ 79 Name: javaVolumeName, 80 Path: constants.DefaultExtractorsDir, 81 }, 82 }, 83 Id: javaArtifactsID, 84 // Don't need to wait for anything, because this is just sideloading 85 // another docker image. 86 WaitFor: []string{"-"}, 87 } 88 } 89 90 func zipMergeStep(corpus string) *cloudbuild.BuildStep { 91 return &cloudbuild.BuildStep{ 92 Name: constants.KytheKzipToolsImage, 93 Entrypoint: "bash", 94 Args: []string{ 95 "-c", 96 fmt.Sprintf( 97 "%s merge --output %s %s/*.kzip", 98 constants.DefaultKzipToolLocation, 99 path.Join(outputDirectory, outputFileName()), 100 outputDirectory), 101 }, 102 Id: mergeStepID, 103 // We explicitly don't include a WaitFor here because that is equivalent 104 // to waiting for everything. This step should be done at the end, so 105 // it gets no WaitFor (== wait for everything). 106 } 107 }