Search in sources :

Example 6 with SkylarkCallable

use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.

the class CcSkylarkApiProvider method getIncludeDirs.

@SkylarkCallable(name = "include_directories", structField = true, doc = "Returns the immutable set of include directories used to compile this target " + "(possibly empty but never None).")
public ImmutableList<String> getIncludeDirs() {
    CppCompilationContext ccContext = getInfo().getProvider(CppCompilationContext.class);
    if (ccContext == null) {
        return ImmutableList.of();
    }
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (PathFragment path : ccContext.getIncludeDirs()) {
        builder.add(path.getSafePathString());
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SkylarkCallable(com.google.devtools.build.lib.skylarkinterface.SkylarkCallable)

Example 7 with SkylarkCallable

use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.

the class CcSkylarkApiProvider method getSystemIncludeDirs.

@SkylarkCallable(name = "system_include_directories", structField = true, doc = "Returns the immutable set of system include directories used to compile this target " + "(possibly empty but never None).")
public ImmutableList<String> getSystemIncludeDirs() {
    CppCompilationContext ccContext = getInfo().getProvider(CppCompilationContext.class);
    if (ccContext == null) {
        return ImmutableList.of();
    }
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (PathFragment path : ccContext.getSystemIncludeDirs()) {
        builder.add(path.getSafePathString());
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SkylarkCallable(com.google.devtools.build.lib.skylarkinterface.SkylarkCallable)

Example 8 with SkylarkCallable

use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.

the class CcSkylarkApiProvider method getQuoteIncludeDirs.

@SkylarkCallable(name = "quote_include_directories", structField = true, doc = "Returns the immutable set of quote include directories used to compile this target " + "(possibly empty but never None).")
public ImmutableList<String> getQuoteIncludeDirs() {
    CppCompilationContext ccContext = getInfo().getProvider(CppCompilationContext.class);
    if (ccContext == null) {
        return ImmutableList.of();
    }
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (PathFragment path : ccContext.getQuoteIncludeDirs()) {
        builder.add(path.getSafePathString());
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SkylarkCallable(com.google.devtools.build.lib.skylarkinterface.SkylarkCallable)

Example 9 with SkylarkCallable

use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.

the class SkylarkDocumentationCollector method collectJavaObjects.

/**
   * Collects and returns all the Java objects reachable in Skylark from (and including)
   * firstClass with the corresponding SkylarkModule annotation.
   *
   * <p>Note that the {@link SkylarkModule} annotation for firstClass - firstModule -
   * is also an input parameter, because some top level Skylark built-in objects and methods
   * are not annotated on the class, but on a field referencing them.
   */
@VisibleForTesting
static void collectJavaObjects(SkylarkModule firstModule, Class<?> firstClass, Map<String, SkylarkModuleDoc> modules) {
    Set<Class<?>> done = new HashSet<>();
    Deque<Class<?>> toProcess = new LinkedList<>();
    Map<Class<?>, SkylarkModule> annotations = new HashMap<>();
    toProcess.addLast(firstClass);
    annotations.put(firstClass, firstModule);
    while (!toProcess.isEmpty()) {
        Class<?> c = toProcess.removeFirst();
        SkylarkModule annotation = annotations.get(c);
        done.add(c);
        if (!modules.containsKey(annotation.name())) {
            modules.put(annotation.name(), new SkylarkModuleDoc(annotation, c));
        }
        SkylarkModuleDoc module = modules.get(annotation.name());
        if (module.javaMethodsNotCollected()) {
            ImmutableMap<Method, SkylarkCallable> methods = FuncallExpression.collectSkylarkMethodsWithAnnotation(c);
            for (Map.Entry<Method, SkylarkCallable> entry : methods.entrySet()) {
                module.addMethod(new SkylarkJavaMethodDoc(module, entry.getKey(), entry.getValue()));
            }
            for (Map.Entry<Method, SkylarkCallable> method : methods.entrySet()) {
                Class<?> returnClass = method.getKey().getReturnType();
                if (returnClass.isAnnotationPresent(SkylarkModule.class) && !done.contains(returnClass)) {
                    toProcess.addLast(returnClass);
                    annotations.put(returnClass, returnClass.getAnnotation(SkylarkModule.class));
                }
            }
        }
    }
}
Also used : SkylarkCallable(com.google.devtools.build.lib.skylarkinterface.SkylarkCallable) HashMap(java.util.HashMap) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) SkylarkJavaMethodDoc(com.google.devtools.build.docgen.skylark.SkylarkJavaMethodDoc) SkylarkModule(com.google.devtools.build.lib.skylarkinterface.SkylarkModule) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SkylarkModuleDoc(com.google.devtools.build.docgen.skylark.SkylarkModuleDoc) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 10 with SkylarkCallable

use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.

the class SkylarkRuleContext method newFile.

// Kept for compatibility with old code.
@SkylarkCallable(documented = false)
public Artifact newFile(Root root, Artifact baseArtifact, String suffix) {
    PathFragment original = baseArtifact.getRootRelativePath();
    PathFragment fragment = original.replaceName(original.getBaseName() + suffix);
    return ruleContext.getDerivedArtifact(fragment, root);
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SkylarkCallable(com.google.devtools.build.lib.skylarkinterface.SkylarkCallable)

Aggregations

SkylarkCallable (com.google.devtools.build.lib.skylarkinterface.SkylarkCallable)27 Method (java.lang.reflect.Method)8 Test (org.junit.Test)7 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)6 ImmutableList (com.google.common.collect.ImmutableList)5 RepositoryFunctionException (com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException)5 IOException (java.io.IOException)5 ImmutableMap (com.google.common.collect.ImmutableMap)2 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2 Param (com.google.devtools.build.lib.skylarkinterface.Param)2 OutputStream (java.io.OutputStream)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SkylarkJavaMethodDoc (com.google.devtools.build.docgen.skylark.SkylarkJavaMethodDoc)1 SkylarkModuleDoc (com.google.devtools.build.docgen.skylark.SkylarkModuleDoc)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 Root (com.google.devtools.build.lib.actions.Root)1 MiddlemanProvider (com.google.devtools.build.lib.analysis.MiddlemanProvider)1