// Copyright 2014 The Bazel Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.lib.rules.java; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.analysis.RedirectChaser; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.ConfigurationEnvironment; import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory; import com.google.devtools.build.lib.analysis.config.FragmentOptions; import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.NoSuchPackageException; import com.google.devtools.build.lib.packages.NoSuchTargetException; import com.google.devtools.build.lib.packages.RawAttributeMapper; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.vfs.PathFragment; import java.util.List; import javax.annotation.Nullable; /** * A provider to load jvm configurations from the package path. * *
If the given {@code javaHome} is a label, i.e. starts with {@code "//"},
* then the loader will look at the target it refers to. If the target is a
* filegroup, then the loader will look in it's srcs for a filegroup that ends
* with {@code - The loader also supports legacy mode, where the JVM can be defined with an abolute path.
*/
public final class JvmConfigurationLoader implements ConfigurationFragmentFactory {
private final JavaCpuSupplier cpuSupplier;
public JvmConfigurationLoader(JavaCpuSupplier cpuSupplier) {
this.cpuSupplier = cpuSupplier;
}
@Override
public Jvm create(ConfigurationEnvironment env, BuildOptions buildOptions)
throws InvalidConfigurationException, InterruptedException {
JavaOptions javaOptions = buildOptions.get(JavaOptions.class);
if (javaOptions.disableJvm) {
// TODO(bazel-team): Instead of returning null here, add another method to the interface.
return null;
}
String javaHome = javaOptions.javaBase;
String cpu = cpuSupplier.getJavaCpu(buildOptions, env);
if (cpu == null) {
return null;
}
try {
return createDefault(env, javaHome, cpu);
} catch (LabelSyntaxException e) {
// Try again with legacy
}
return createLegacy(javaHome);
}
@Override
public Class extends Fragment> creates() {
return Jvm.class;
}
@Override
public ImmutableSet