use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.
the class SkylarkRuleContext method getBuildFileRelativePath.
@SkylarkCallable(name = "build_file_path", structField = true, documented = true, doc = "Returns path to the BUILD file for this rule, relative to the source root.")
public String getBuildFileRelativePath() {
Package pkg = ruleContext.getRule().getPackage();
Root root = Root.asSourceRoot(pkg.getSourceRoot(), pkg.getPackageIdentifier().getRepository().isMain());
return pkg.getBuildFile().getPath().relativeTo(root.getPath()).getPathString();
}
use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.
the class SkylarkRuleContext method newFile.
@SkylarkCallable(doc = "Creates a new file object in the same directory as the original file. " + DOC_NEW_FILE_TAIL)
public Artifact newFile(Artifact baseArtifact, String newBaseName) {
PathFragment original = baseArtifact.getRootRelativePath();
PathFragment fragment = original.replaceName(newBaseName);
return ruleContext.getDerivedArtifact(fragment, newFileRoot());
}
use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.
the class SkylarkRuleContext method instrumentCoverage.
@SkylarkCallable(name = "coverage_instrumented", doc = "Returns whether code coverage instrumentation should be generated when performing " + "compilation actions for this rule or, if <code>target</code> is provided, the rule " + "specified by that Target. (If a non-rule Target is provided, this returns False.) This " + "differs from <code>coverage_enabled</code> in the <a href=\"configuration.html\">" + "configuration</a>, which notes whether coverage data collection is enabled for the " + "entire run, but not whether a specific target should be instrumented.", parameters = { @Param(name = "target", type = TransitiveInfoCollection.class, defaultValue = "None", noneable = true, named = true, doc = "A Target specifying a rule. If not provided, defaults to the current rule.") })
public boolean instrumentCoverage(Object targetUnchecked) {
BuildConfiguration config = ruleContext.getConfiguration();
if (!config.isCodeCoverageEnabled()) {
return false;
}
if (targetUnchecked == Runtime.NONE) {
return InstrumentedFilesCollector.shouldIncludeLocalSources(ruleContext);
}
TransitiveInfoCollection target = (TransitiveInfoCollection) targetUnchecked;
return (target.getProvider(InstrumentedFilesProvider.class) != null) && InstrumentedFilesCollector.shouldIncludeLocalSources(config, target);
}
use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.
the class CcSkylarkApiProvider method getCcFlags.
@SkylarkCallable(name = "compile_flags", structField = true, doc = "Returns the immutable set of flags used to compile this target " + "(possibly empty but never None).")
public ImmutableList<String> getCcFlags() {
CppCompilationContext ccContext = getInfo().getProvider(CppCompilationContext.class);
ImmutableList.Builder<String> options = ImmutableList.builder();
for (String define : ccContext.getDefines()) {
options.add("-D" + define);
}
for (PathFragment path : ccContext.getSystemIncludeDirs()) {
options.add("-isystem " + path.getSafePathString());
}
for (PathFragment path : ccContext.getIncludeDirs()) {
options.add("-I " + path.getSafePathString());
}
for (PathFragment path : ccContext.getQuoteIncludeDirs()) {
options.add("-iquote " + path.getSafePathString());
}
return options.build();
}
use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.
the class JavaSkylarkCommon method createJavaCompileAction.
@SkylarkCallable(name = "compile", doc = "Compiles Java source files/jars from the implementation of a Skylark rule and returns a " + "provider that represents the results of the compilation and can be added to the set of " + "providers emitted by this rule.", // There is one mandatory positional: the Skylark rule context.
mandatoryPositionals = 1, parameters = { @Param(name = "source_jars", positional = false, named = true, type = SkylarkList.class, generic1 = Artifact.class, defaultValue = "[]", doc = "A list of the jars to be compiled. At least one of source_jars or source_files" + " should be specified."), @Param(name = "source_files", positional = false, named = true, type = SkylarkList.class, generic1 = Artifact.class, defaultValue = "[]", doc = "A list of the Java source files to be compiled. At least one of source_jars or " + "source_files should be specified."), @Param(name = "output", positional = false, named = true, type = Artifact.class), @Param(name = "javac_opts", positional = false, named = true, type = SkylarkList.class, generic1 = String.class, doc = "A list of the desired javac options. Optional."), @Param(name = "deps", positional = false, named = true, type = SkylarkList.class, generic1 = JavaProvider.class, doc = "A list of dependencies. Optional."), @Param(name = "strict_deps", defaultValue = "OFF", positional = false, named = true, type = String.class, doc = "A string that specifies how to handle strict deps. Possible values: 'OFF' (silently" + " allowing referencing transitive dependencies) and 'ERROR' (failing to build when" + " transitive dependencies are used directly). By default 'OFF'."), @Param(name = "java_toolchain", positional = false, named = true, type = ConfiguredTarget.class, doc = "A label pointing to a java_toolchain rule to be used for this compilation. " + "Mandatory."), @Param(name = "host_javabase", positional = false, named = true, type = ConfiguredTarget.class, doc = "A label pointing to a JDK to be used for this compilation. Mandatory.") })
public JavaProvider createJavaCompileAction(SkylarkRuleContext skylarkRuleContext, SkylarkList<Artifact> sourceJars, SkylarkList<Artifact> sourceFiles, Artifact outputJar, SkylarkList<String> javacOpts, SkylarkList<JavaProvider> deps, String strictDepsMode, ConfiguredTarget javaToolchain, ConfiguredTarget hostJavabase) {
JavaLibraryHelper helper = new JavaLibraryHelper(skylarkRuleContext.getRuleContext()).setOutput(outputJar).addSourceJars(sourceJars).addSourceFiles(sourceFiles).setJavacOpts(javacOpts);
List<JavaCompilationArgsProvider> compilationArgsProviders = JavaProvider.fetchProvidersFromList(deps, JavaCompilationArgsProvider.class);
helper.addAllDeps(compilationArgsProviders);
helper.setCompilationStrictDepsMode(getStrictDepsMode(strictDepsMode));
MiddlemanProvider hostJavabaseProvider = hostJavabase.getProvider(MiddlemanProvider.class);
NestedSet<Artifact> hostJavabaseArtifacts = hostJavabaseProvider == null ? NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER) : hostJavabaseProvider.getMiddlemanArtifact();
JavaToolchainProvider javaToolchainProvider = checkNotNull(javaToolchain.getProvider(JavaToolchainProvider.class));
JavaCompilationArgs artifacts = helper.build(javaSemantics, javaToolchainProvider, hostJavabaseArtifacts, SkylarkList.createImmutable(ImmutableList.<Artifact>of()));
JavaRuleOutputJarsProvider javaRuleOutputJarsProvider = JavaRuleOutputJarsProvider.builder().addOutputJar(new JavaRuleOutputJarsProvider.OutputJar(outputJar, /* ijar */
null, sourceJars)).build();
return JavaProvider.Builder.create().addProvider(JavaCompilationArgsProvider.class, helper.buildCompilationArgsProvider(artifacts, true)).addProvider(JavaSourceJarsProvider.class, createJavaSourceJarsProvider(sourceJars)).addProvider(JavaRuleOutputJarsProvider.class, javaRuleOutputJarsProvider).build();
}
Aggregations