Class GenruleBuildable

  • All Implemented Interfaces:
    AddsToRuleKey, Buildable

    public class GenruleBuildable
    extends Object
    implements Buildable
    Buildable for Genrule suitable for building Genrules directly and also for subclasses extending the functionality of a bare Genrule.
    • Field Detail

      • SRC_DIRECTORY_PATTERN

        protected static final String SRC_DIRECTORY_PATTERN
        Name of the "srcs" subdirectory in the gen directory tree. GenruleBuildable symlinks all source files into this directory and sets this directory to be the working directory of the command.
        See Also:
        Constant Field Values
      • buildTarget

        protected final BuildTarget buildTarget
        The build target for this genrule.
      • srcs

        protected final SourceSet srcs
        SourceSet for this Genrule, exposed as SRCS in the genrule command.

        The order in which elements are specified in the srcs attribute of a genrule matters.

      • cmd

        protected final Optional<Arg> cmd
        The shell command to run to generate the output file. Used as the fallback if neither bash nor cmdExe are provided.
      • bash

        protected final Optional<Arg> bash
        The bash shell command to generate the output file. Only used on platforms that have bash.
      • cmdExe

        protected final Optional<Arg> cmdExe
        The cmd shell command to generate the output file. Only used on Windows.
      • out

        protected final Optional<String> out
        The name of the output file that this genrule intends to generate. One and only one of out and outs must be present.
      • outs

        protected final Optional<com.google.common.collect.ImmutableMap<OutputLabel,​com.google.common.collect.ImmutableSet<String>>> outs
        The names of the output files that this genrule intends to generate relative to $OUT mapped to their respective output group names.
      • outputPath

        protected final Optional<PublicOutputPath> outputPath
        The output path of the file generated by this genrule, if present. Note that this output path is Public because it uses a folder name that is exactly equal to the target name, unlike other MBRs which use the target name suffixed by the flavor (or __ if no flavor is provided). This is for backwards compatability with users of Buck that have hardcoded their paths. One and only one of outputPath and outputPaths must be present.
      • outputPaths

        protected final Optional<com.google.common.collect.ImmutableMap<OutputLabel,​com.google.common.collect.ImmutableSet<OutputPath>>> outputPaths
        The output paths of the files generated by this genrule organized by their output labels.

        The paths are relative to the directory buck-out/gen/__. For example, if the target is named "foo", the output paths in this map would be relative to buck-out/gen/foo__. Note that outputPath places the output in buck-out/gen/foo.

        One and only one of outputPath and outputPaths must be present.

      • isCacheable

        protected final boolean isCacheable
        Whether or not this genrule can be cached. This is not used within this class, but is required to be a part of the rule key.
      • type

        protected final Optional<String> type
        Type for this genrule, if one was provided.
    • Method Detail

      • getOutputs

        public com.google.common.collect.ImmutableSet<OutputPath> getOutputs​(OutputLabel outputLabel)
        Returns the set of OutputPath instances associated with the given OutputLabel.

        If multiple outputs are available, returns either the default or named output group. The default output group is the set of all named outputs.

        If multiple outputs are not available, returns a set containing the single output.

      • getOutputLabels

        public com.google.common.collect.ImmutableSet<OutputLabel> getOutputLabels()
        Returns a set of output labels associated with this buildable.
      • getOutputName

        public String getOutputName​(OutputLabel outputLabel)
        Returns a String representation of the output path relative to the root output directory.
      • shouldExecuteRemotely

        public final boolean shouldExecuteRemotely()
      • addEnvironmentVariables

        public void addEnvironmentVariables​(SourcePathResolverAdapter pathResolver,
                                            OutputPathResolver outputPathResolver,
                                            ProjectFilesystem filesystem,
                                            Path srcPath,
                                            Path tmpPath,
                                            com.google.common.collect.ImmutableMap.Builder<String,​String> environmentVariablesBuilder)
        Adds the standard set of environment variables to the genrule, which are then exposed to the genrule command.

        This method populates these well-known environment variables:

        • SRCS, a delimited list of source file inputs to the genrule
        • OUT, the genrule's output file
        • GEN_DIR, Buck's gendir
        • SRCDIR, the symlink-populated source directory readable to the command
        • TMP, the temp directory usable by the command
        • ANDROID_HOME, deprecated, the path to the Android SDK (if present)
        • ANDROID_SDK_ROOT, the path to the Android SDK (if present)
        • DX, the path to the Android DX executable (if present)
        • ZIPALIGN, the path to the Android Zipalign executable (if present)
        • AAPT, the path to the Android AAPT executable (if present)
        • AAPT2, the path to the Android AAPT2 executable (if present)
        • NDK_HOME, the path to the Android NDK (if present)
        This method also sets NO_BUCKD to 1.
        Parameters:
        pathResolver - Path resolver for resolving paths for SRCS
        outputPathResolver - Path resolver for resolving OUT
        filesystem - Filesystem for resolving relative paths for SRCDIR and TMP
        srcPath - Path to the generated symlink source directory
        tmpPath - Path to the genrule temporary directory
        environmentVariablesBuilder - Environment map builder