kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/extractors/gcp/config/gradle.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  	"path/filepath"
    22  
    23  	"kythe.io/kythe/go/extractors/constants"
    24  
    25  	rpb "kythe.io/kythe/proto/repo_go_proto"
    26  
    27  	"google.golang.org/api/cloudbuild/v1"
    28  )
    29  
    30  type gradleGenerator struct{}
    31  
    32  // preExtractSteps implements parts of buildSystemElaborator
    33  func (g gradleGenerator) preExtractSteps() []*cloudbuild.BuildStep {
    34  	return []*cloudbuild.BuildStep{
    35  		javaExtractorsStep(),
    36  	}
    37  }
    38  
    39  // extractSteps implements parts of buildSystemElaborator
    40  func (g gradleGenerator) extractSteps(corpus string, target *rpb.ExtractionTarget, idSuffix string) []*cloudbuild.BuildStep {
    41  	buildfile := path.Join(codeDirectory, target.Path)
    42  	targetPath, _ := filepath.Split(target.Path)
    43  	return []*cloudbuild.BuildStep{
    44  		preprocessorStep(buildfile, idSuffix),
    45  		&cloudbuild.BuildStep{
    46  			Name:       constants.GradleJDK8Image,
    47  			Entrypoint: "gradle",
    48  			Args: []string{
    49  				"clean",
    50  				// TODO(#3126): If compile-test has to be done as a separate
    51  				// step, then we also need to fix this in the same way as we do
    52  				// for multiple repo support.  Probably this would need to be
    53  				// done with multiple steps (but making sure to not clobber
    54  				// output).
    55  				// The alternative here is to fall back to using clean install,
    56  				// which should also work.
    57  				"build",
    58  				"-b", // Points directly at a specific build.gradle file:
    59  				buildfile,
    60  			},
    61  			Volumes: []*cloudbuild.Volume{
    62  				&cloudbuild.Volume{
    63  					Name: javaVolumeName,
    64  					Path: constants.DefaultExtractorsDir,
    65  				},
    66  			},
    67  			Env: []string{
    68  				"KYTHE_CORPUS=" + corpus,
    69  				"KYTHE_OUTPUT_DIRECTORY=" + outputDirectory,
    70  				"KYTHE_ROOT_DIRECTORY=" + filepath.Join(codeDirectory, targetPath),
    71  				"JAVAC_EXTRACTOR_JAR=" + constants.DefaultJavaExtractorLocation,
    72  				"REAL_JAVAC=" + constants.DefaultJavacLocation,
    73  				"KYTHE_JAVA_RUNTIME_OPTIONS=-Xbootclasspath/p:" + constants.DefaultJava9ToolsLocation,
    74  			},
    75  			Id:      extractStepID + idSuffix,
    76  			WaitFor: []string{javaArtifactsID, preStepID + idSuffix},
    77  		},
    78  	}
    79  }
    80  
    81  // postExtractSteps implements parts of buildSystemElaborator
    82  func (g gradleGenerator) postExtractSteps(corpus string) []*cloudbuild.BuildStep {
    83  	return []*cloudbuild.BuildStep{
    84  		zipMergeStep(corpus),
    85  	}
    86  }
    87  
    88  // defaultConfigFile implements parts of buildSystemElaborator
    89  func (g gradleGenerator) defaultExtractionTarget() *rpb.ExtractionTarget {
    90  	return &rpb.ExtractionTarget{
    91  		Path: "build.gradle",
    92  	}
    93  }