@@ -157,7 +157,7 @@ type outputConfigs struct {
157157 // licence will contain the OSS license applicable for the generated configs.
158158 license generatedFile
159159 // cppConfigsTarball is the path to the tarball file containing the C++ configs generated by
160- // Bazel inside the toolchain container .
160+ // Bazel inside the runner .
161161 cppConfigsTarball string
162162 // configBuild represents the BUILD file containing the C++ crosstool top toolchain target
163163 // and the default platform definition.
@@ -181,8 +181,8 @@ func BazeliskDownloadInfo(os string) (string, string, error) {
181181}
182182
183183// installBazelisk downloads bazelisk locally to the specified directory for the given os and copies
184- // it into the running toolchain container .
185- // Returns the path Bazelisk was installed to inside the running toolchain container .
184+ // it into the runner .
185+ // Returns the path Bazelisk was installed to inside the runner .
186186func installBazelisk (r runner.Runner , downloadDir , execOS string ) (string , error ) {
187187 url , filename , err := BazeliskDownloadInfo (execOS )
188188 if err != nil {
@@ -210,7 +210,7 @@ func installBazelisk(r runner.Runner, downloadDir, execOS string) (string, error
210210 }
211211
212212 if _ , err := r .ExecCmd ("chmod" , "+x" , bazeliskRunnerPath ); err != nil {
213- return "" , fmt .Errorf ("failed to mark the Bazelisk binary as executable inside the container : %w" , err )
213+ return "" , fmt .Errorf ("failed to mark the Bazelisk binary as executable inside the runner : %w" , err )
214214 }
215215 return bazeliskRunnerPath , nil
216216}
@@ -243,10 +243,10 @@ func appendCppEnv(env map[string]string, o *options.Options) (map[string]string,
243243 return env , nil
244244}
245245
246- // genCppConfigs generates C++ configs inside the running toolchain container represented by the
247- // given docker runner according to the given options. bazeliskPath is the path to the bazelisk
248- // binary inside the running toolchain container .
249- // The return value is the path to the C++ configs tarball copied out of the toolchain container .
246+ // genCppConfigs generates C++ configs inside the runner represented by the
247+ // given runner according to the given options. bazeliskPath is the path to the bazelisk
248+ // binary inside the runner .
249+ // The return value is the path to the C++ configs tarball copied out of the runner .
250250func genCppConfigs (r runner.Runner , o * options.Options , bazeliskPath string ) (string , error ) {
251251 if ! o .GenCPPConfigs {
252252 return "" , nil
@@ -256,7 +256,7 @@ func genCppConfigs(r runner.Runner, o *options.Options, bazeliskPath string) (st
256256 // command we run in this function.
257257 cppProjDir := path .Join (r .GetWorkdir (), "cpp_configs_project" )
258258 if _ , err := r .ExecCmd ("mkdir" , cppProjDir ); err != nil {
259- return "" , fmt .Errorf ("failed to create empty directory %q inside the toolchain container : %w" , cppProjDir , err )
259+ return "" , fmt .Errorf ("failed to create empty directory %q inside the runner : %w" , cppProjDir , err )
260260 }
261261 oldWorkDir := r .GetWorkdir ()
262262 if err := r .SetWorkdir (cppProjDir ); err != nil {
@@ -265,7 +265,7 @@ func genCppConfigs(r runner.Runner, o *options.Options, bazeliskPath string) (st
265265 defer r .SetWorkdir (oldWorkDir )
266266
267267 if _ , err := r .ExecCmd ("touch" , "WORKSPACE" , "BUILD.bazel" ); err != nil {
268- return "" , fmt .Errorf ("failed to create empty build & workspace files in the container to initialize a blank Bazel repository: %w" , err )
268+ return "" , fmt .Errorf ("failed to create empty build & workspace files in the runner to initialize a blank Bazel repository: %w" , err )
269269 }
270270
271271 // Backup the current environment & restore it before returning.
@@ -280,24 +280,24 @@ func genCppConfigs(r runner.Runner, o *options.Options, bazeliskPath string) (st
280280 // logs.
281281 generationEnv , err := appendCppEnv (bazeliskEnv , o )
282282 if err != nil {
283- return "" , fmt .Errorf ("failed to add additional environment variables to the C++ config generation docker command: %w" , err )
283+ return "" , fmt .Errorf ("failed to add additional environment variables to the C++ config generation command: %w" , err )
284284 }
285285 r .SetAdditionalEnv (generationEnv )
286286
287287 args := []string {o .CppBazelCmd }
288288 args = append (args , o .CPPConfigTargets ... )
289289 if _ , err := r .ExecCmd (bazeliskPath , args ... ); err != nil {
290- return "" , fmt .Errorf ("Bazel was unable to build the C++ config generation targets in the toolchain container : %w" , err )
290+ return "" , fmt .Errorf ("Bazel was unable to build the C++ config generation targets in the runner : %w" , err )
291291 }
292292
293293 // Restore the env needed for Bazelisk.
294294 r .SetAdditionalEnv (bazeliskEnv )
295295 bazelOutputRoot , err := r .ExecCmd (bazeliskPath , "info" , "output_base" )
296296 if err != nil {
297- return "" , fmt .Errorf ("unable to determine the build output directory where Bazel produced C++ configs in the toolchain container : %w" , err )
297+ return "" , fmt .Errorf ("unable to determine the build output directory where Bazel produced C++ configs in the runner : %w" , err )
298298 }
299299 cppConfigDir := path .Join (bazelOutputRoot , "external" , o .CPPConfigRepo )
300- log .Printf ("Extracting C++ config files generated by Bazel at %q from the toolchain container ." , cppConfigDir )
300+ log .Printf ("Extracting C++ config files generated by Bazel at %q from the runner ." , cppConfigDir )
301301
302302 // Restore the old env now that we're done with Bazelisk commands. This is purely to reduce
303303 // noise in the logs.
@@ -306,7 +306,7 @@ func genCppConfigs(r runner.Runner, o *options.Options, bazeliskPath string) (st
306306 // 1. Get a list of symlinks in the config output directory.
307307 // 2. Harden each link.
308308 // 3. Archive the contents of the config output directory into a tarball.
309- // 4. Copy the tarball from the container to the local temp directory.
309+ // 4. Copy the tarball from the runner to the local temp directory.
310310 var out string
311311 if o .ExecOS == "windows" {
312312 out , err = r .ExecCmd ("cmd" , "/r" , "dir" , filepath .Clean (cppConfigDir ), "/a:l" , "/b" )
@@ -332,7 +332,7 @@ func genCppConfigs(r runner.Runner, o *options.Options, bazeliskPath string) (st
332332 }
333333 resolvedPath , err := r .ExecCmd ("readlink" , s )
334334 if err != nil {
335- return "" , fmt .Errorf ("unable to determine what the symlink %q in %q in the toolchain container points to: %w" , s , cppConfigDir , err )
335+ return "" , fmt .Errorf ("unable to determine what the symlink %q in %q in the runner points to: %w" , s , cppConfigDir , err )
336336 }
337337 if _ , err := r .ExecCmd ("ln" , "-f" , resolvedPath , s ); err != nil {
338338 return "" , fmt .Errorf ("failed to harden symlink %q in %q pointing to %q: %w" , s , cppConfigDir , resolvedPath , err )
@@ -342,11 +342,11 @@ func genCppConfigs(r runner.Runner, o *options.Options, bazeliskPath string) (st
342342 outputTarball := "cpp_configs.tar"
343343 // Explicitly use absolute paths to avoid confusion on what's the working directory.
344344 outputTarballPath := path .Join (o .TempWorkDir , outputTarball )
345- outputTarballContainerPath := path .Join (cppProjDir , outputTarball )
346- if _ , err := r .ExecCmd ("tar" , "-cf" , outputTarballContainerPath , "-C" , cppConfigDir , "." ); err != nil {
345+ outputTarballRunnerPath := path .Join (cppProjDir , outputTarball )
346+ if _ , err := r .ExecCmd ("tar" , "-cf" , outputTarballRunnerPath , "-C" , cppConfigDir , "." ); err != nil {
347347 return "" , fmt .Errorf ("failed to archive the C++ configs into a tarball inside the toolchain container: %w" , err )
348348 }
349- if err := r .CopyFrom (outputTarballContainerPath , outputTarballPath ); err != nil {
349+ if err := r .CopyFrom (outputTarballRunnerPath , outputTarballPath ); err != nil {
350350 return "" , fmt .Errorf ("failed to copy the C++ config tarball out of the toolchain container: %w" , err )
351351 }
352352 log .Printf ("Generated C++ configs at %s." , outputTarballPath )
@@ -368,20 +368,20 @@ func UsesLocalJavaRuntime(bazelVersion string) (bool, error) {
368368
369369// genJavaConfigs returns a BUILD file containing a Java toolchain rule definition that contains
370370// the following attributes determined by probing details about the JDK version installed in the
371- // running toolchain container .
372- // 1. Value of the JAVA_HOME environment variable set in the toolchain image .
371+ // runner .
372+ // 1. Value of the JAVA_HOME environment variable set in the runner or as reported by java binary .
373373// 2. Value of the Java version as reported by the java binary installed in JAVA_HOME inside the
374- // running toolchain container .
374+ // runner .
375375func genJavaConfigs (r runner.Runner , o * options.Options ) (generatedFile , error ) {
376376 if ! o .GenJavaConfigs {
377377 return generatedFile {}, nil
378378 }
379379 javaBin := "java"
380- imageEnv , err := r .GetEnv ()
380+ runnerEnv , err := r .GetEnv ()
381381 if err != nil {
382382 return generatedFile {}, fmt .Errorf ("unable to get the environment of the toolchain image to determine JAVA_HOME: %w" , err )
383383 }
384- javaHome , ok := imageEnv ["JAVA_HOME" ]
384+ javaHome , ok := runnerEnv ["JAVA_HOME" ]
385385 if ok && len (javaHome ) > 0 {
386386 log .Printf ("JAVA_HOME was %q." , javaHome )
387387 javaBin = path .Join (javaHome , "bin/java" )
@@ -392,7 +392,7 @@ func genJavaConfigs(r runner.Runner, o *options.Options) (generatedFile, error)
392392 // some non-deterministic prefix.
393393 out , err := r .ExecCmd (javaBin , "-XshowSettings:properties" , "-version" )
394394 if err != nil {
395- return generatedFile {}, fmt .Errorf ("unable to determine the Java version installed in the toolchain container : %w" , err )
395+ return generatedFile {}, fmt .Errorf ("unable to determine the Java version installed in the runner : %w" , err )
396396 }
397397 javaVersion := ""
398398 for _ , line := range strings .Split (out , "\n " ) {
@@ -412,9 +412,13 @@ func genJavaConfigs(r runner.Runner, o *options.Options) (generatedFile, error)
412412 }
413413 }
414414 if len (javaVersion ) == 0 {
415- return generatedFile {}, fmt .Errorf ("unable to determine the java version installed in the container by running 'java -XshowSettings:properties' in the container because it didn't return a line that looked like java.version = <version>" )
415+ return generatedFile {}, fmt .Errorf ("unable to determine the java version installed in the runner by running 'java -XshowSettings:properties' because it didn't return a line that looked like java.version = <version>" )
416416 }
417417 log .Printf ("Java version: '%s'." , javaVersion )
418+ if len (javaHome ) == 0 {
419+ return generatedFile {}, fmt .Errorf ("unable to determine the JAVA_HOME installed in the runner: not in env, not returned as line `java.home = <path>` by 'java -XshowSettings:properties'" )
420+ }
421+ log .Printf ("Java home: '%s'." , javaHome )
418422
419423 usesNewJavaRule , err := UsesLocalJavaRuntime (o .BazelVersion )
420424 if err != nil {
@@ -770,10 +774,11 @@ func createManifest(o *options.Options) error {
770774 }
771775 // Extract the sha256 digest from the image name to be included in the manifest.
772776 s := imageDigestRegexp .FindStringSubmatch (o .PlatformParams .ToolchainContainer )
773- if len (s ) != 2 {
777+ if len (s ) != 2 && o . Runner == "docker" {
774778 return fmt .Errorf ("failed to extract sha256 digest using regex from image name %q, got %d substrings, want 2" , o .PlatformParams .ToolchainContainer , len (s ))
779+ } else if len (s ) == 2 {
780+ m .ImageDigest = s [1 ]
775781 }
776- m .ImageDigest = s [1 ]
777782 // Include the sha256 digest of the configs tarball if output tarball generation was enabled by
778783 // actually hashing the contents of the output tarball.
779784 if len (o .OutputTarball ) != 0 {
0 commit comments