Search in sources :

Example 6 with ConfiguredRuleClassProvider

use of com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider in project bazel by bazelbuild.

the class AbstractCommandTest method testGetOptionsYieldsAnnotatedOptions.

@Test
public void testGetOptionsYieldsAnnotatedOptions() {
    ConfiguredRuleClassProvider ruleClassProvider = new ConfiguredRuleClassProvider.Builder().setToolsRepository(TestConstants.TOOLS_REPOSITORY).build();
    assertThat(BlazeCommandUtils.getOptions(TestCommand.class, ImmutableList.<BlazeModule>of(), ruleClassProvider)).containsExactlyElementsIn(optionClassesWithDefault(FooOptions.class, BarOptions.class));
}
Also used : ConfiguredRuleClassProvider(com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider) Test(org.junit.Test)

Example 7 with ConfiguredRuleClassProvider

use of com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider in project bazel by bazelbuild.

the class HelpCommand method exec.

@Override
public ExitCode exec(CommandEnvironment env, OptionsProvider options) {
    env.getEventBus().post(new NoBuildEvent());
    BlazeRuntime runtime = env.getRuntime();
    OutErr outErr = env.getReporter().getOutErr();
    Options helpOptions = options.getOptions(Options.class);
    if (options.getResidue().isEmpty()) {
        emitBlazeVersionInfo(outErr, runtime.getProductName());
        emitGenericHelp(outErr, runtime);
        return ExitCode.SUCCESS;
    }
    if (options.getResidue().size() != 1) {
        env.getReporter().handle(Event.error("You must specify exactly one command"));
        return ExitCode.COMMAND_LINE_ERROR;
    }
    String helpSubject = options.getResidue().get(0);
    if (helpSubject.equals("startup_options")) {
        emitBlazeVersionInfo(outErr, runtime.getProductName());
        emitStartupOptions(outErr, helpOptions.helpVerbosity, runtime, getOptionCategories(runtime));
        return ExitCode.SUCCESS;
    } else if (helpSubject.equals("target-syntax")) {
        emitBlazeVersionInfo(outErr, runtime.getProductName());
        emitTargetSyntaxHelp(outErr, getOptionCategories(runtime), runtime.getProductName());
        return ExitCode.SUCCESS;
    } else if (helpSubject.equals("info-keys")) {
        emitInfoKeysHelp(env, outErr);
        return ExitCode.SUCCESS;
    } else if (helpSubject.equals("completion")) {
        emitCompletionHelp(runtime, outErr);
        return ExitCode.SUCCESS;
    } else if (helpSubject.equals("everything-as-html")) {
        new HtmlEmitter(runtime).emit(outErr);
        return ExitCode.SUCCESS;
    }
    BlazeCommand command = runtime.getCommandMap().get(helpSubject);
    if (command == null) {
        ConfiguredRuleClassProvider provider = runtime.getRuleClassProvider();
        RuleClass ruleClass = provider.getRuleClassMap().get(helpSubject);
        if (ruleClass != null && ruleClass.isDocumented()) {
            // There is a rule with a corresponding name
            outErr.printOut(BlazeRuleHelpPrinter.getRuleDoc(helpSubject, provider));
            return ExitCode.SUCCESS;
        } else {
            env.getReporter().handle(Event.error(null, "'" + helpSubject + "' is neither a command nor a build rule"));
            return ExitCode.COMMAND_LINE_ERROR;
        }
    }
    emitBlazeVersionInfo(outErr, runtime.getProductName());
    outErr.printOut(BlazeCommandUtils.getUsage(command.getClass(), getOptionCategories(runtime), helpOptions.helpVerbosity, runtime.getBlazeModules(), runtime.getRuleClassProvider(), runtime.getProductName()));
    return ExitCode.SUCCESS;
}
Also used : OutErr(com.google.devtools.build.lib.util.io.OutErr) BlazeCommand(com.google.devtools.build.lib.runtime.BlazeCommand) ConfiguredRuleClassProvider(com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider) NoBuildEvent(com.google.devtools.build.lib.analysis.NoBuildEvent) RuleClass(com.google.devtools.build.lib.packages.RuleClass) BlazeRuntime(com.google.devtools.build.lib.runtime.BlazeRuntime)

Example 8 with ConfiguredRuleClassProvider

use of com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider in project bazel by bazelbuild.

the class SkyframeExecutor method skyFunctions.

private ImmutableMap<SkyFunctionName, SkyFunction> skyFunctions(PackageFactory pkgFactory, Predicate<PathFragment> allowedMissingInputs) {
    ConfiguredRuleClassProvider ruleClassProvider = (ConfiguredRuleClassProvider) pkgFactory.getRuleClassProvider();
    // TODO(janakr): use this semaphore to bound memory usage for SkyFunctions besides
    // ConfiguredTargetFunction that may have a large temporary memory blow-up.
    Semaphore cpuBoundSemaphore = new Semaphore(ResourceUsage.getAvailableProcessors());
    // We use an immutable map builder for the nice side effect that it throws if a duplicate key
    // is inserted.
    ImmutableMap.Builder<SkyFunctionName, SkyFunction> map = ImmutableMap.builder();
    map.put(SkyFunctions.PRECOMPUTED, new PrecomputedFunction());
    map.put(SkyFunctions.CLIENT_ENVIRONMENT_VARIABLE, new ClientEnvironmentFunction(clientEnv));
    map.put(SkyFunctions.ACTION_ENVIRONMENT_VARIABLE, new ActionEnvironmentFunction());
    map.put(SkyFunctions.FILE_STATE, new FileStateFunction(tsgm, externalFilesHelper));
    map.put(SkyFunctions.DIRECTORY_LISTING_STATE, new DirectoryListingStateFunction(externalFilesHelper));
    map.put(SkyFunctions.FILE_SYMLINK_CYCLE_UNIQUENESS, new FileSymlinkCycleUniquenessFunction());
    map.put(SkyFunctions.FILE_SYMLINK_INFINITE_EXPANSION_UNIQUENESS, new FileSymlinkInfiniteExpansionUniquenessFunction());
    map.put(SkyFunctions.FILE, new FileFunction(pkgLocator));
    map.put(SkyFunctions.DIRECTORY_LISTING, new DirectoryListingFunction());
    map.put(SkyFunctions.PACKAGE_LOOKUP, new PackageLookupFunction(deletedPackages, crossRepositoryLabelViolationStrategy, buildFilesByPriority));
    map.put(SkyFunctions.CONTAINING_PACKAGE_LOOKUP, new ContainingPackageLookupFunction());
    map.put(SkyFunctions.AST_FILE_LOOKUP, new ASTFileLookupFunction(ruleClassProvider));
    map.put(SkyFunctions.SKYLARK_IMPORTS_LOOKUP, newSkylarkImportLookupFunction(ruleClassProvider, pkgFactory));
    map.put(SkyFunctions.GLOB, newGlobFunction());
    map.put(SkyFunctions.TARGET_PATTERN, new TargetPatternFunction());
    map.put(SkyFunctions.PREPARE_DEPS_OF_PATTERNS, new PrepareDepsOfPatternsFunction());
    map.put(SkyFunctions.PREPARE_DEPS_OF_PATTERN, new PrepareDepsOfPatternFunction(pkgLocator));
    map.put(SkyFunctions.PREPARE_DEPS_OF_TARGETS_UNDER_DIRECTORY, new PrepareDepsOfTargetsUnderDirectoryFunction(directories));
    map.put(SkyFunctions.COLLECT_TARGETS_IN_PACKAGE, new CollectTargetsInPackageFunction());
    map.put(SkyFunctions.COLLECT_PACKAGES_UNDER_DIRECTORY, new CollectPackagesUnderDirectoryFunction(directories));
    map.put(SkyFunctions.BLACKLISTED_PACKAGE_PREFIXES, new BlacklistedPackagePrefixesFunction());
    map.put(SkyFunctions.TESTS_IN_SUITE, new TestsInSuiteFunction());
    map.put(SkyFunctions.TEST_SUITE_EXPANSION, new TestSuiteExpansionFunction());
    map.put(SkyFunctions.TARGET_PATTERN_PHASE, new TargetPatternPhaseFunction());
    map.put(SkyFunctions.RECURSIVE_PKG, new RecursivePkgFunction(directories));
    map.put(SkyFunctions.PACKAGE, newPackageFunction(pkgFactory, packageManager, showLoadingProgress, packageFunctionCache, astCache, numPackagesLoaded, ruleClassProvider, packageProgress));
    map.put(SkyFunctions.PACKAGE_ERROR, new PackageErrorFunction());
    map.put(SkyFunctions.TARGET_MARKER, new TargetMarkerFunction());
    map.put(SkyFunctions.TRANSITIVE_TARGET, new TransitiveTargetFunction(ruleClassProvider));
    map.put(SkyFunctions.TRANSITIVE_TRAVERSAL, new TransitiveTraversalFunction());
    map.put(SkyFunctions.CONFIGURED_TARGET, new ConfiguredTargetFunction(new BuildViewProvider(), ruleClassProvider, cpuBoundSemaphore));
    map.put(SkyFunctions.ASPECT, new AspectFunction(new BuildViewProvider(), ruleClassProvider));
    map.put(SkyFunctions.LOAD_SKYLARK_ASPECT, new ToplevelSkylarkAspectFunction());
    map.put(SkyFunctions.POST_CONFIGURED_TARGET, new PostConfiguredTargetFunction(new BuildViewProvider(), ruleClassProvider));
    map.put(SkyFunctions.BUILD_CONFIGURATION, new BuildConfigurationFunction(directories, ruleClassProvider));
    map.put(SkyFunctions.CONFIGURATION_COLLECTION, new ConfigurationCollectionFunction(configurationFactory, ruleClassProvider));
    map.put(SkyFunctions.CONFIGURATION_FRAGMENT, new ConfigurationFragmentFunction(configurationFragments, ruleClassProvider));
    map.put(SkyFunctions.WORKSPACE_NAME, new WorkspaceNameFunction());
    map.put(SkyFunctions.WORKSPACE_AST, new WorkspaceASTFunction(ruleClassProvider));
    map.put(SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction(ruleClassProvider, pkgFactory, directories));
    map.put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction());
    map.put(SkyFunctions.TARGET_COMPLETION, CompletionFunction.targetCompletionFunction(eventBus));
    map.put(SkyFunctions.ASPECT_COMPLETION, CompletionFunction.aspectCompletionFunction(eventBus));
    map.put(SkyFunctions.TEST_COMPLETION, new TestCompletionFunction());
    map.put(SkyFunctions.ARTIFACT, new ArtifactFunction(allowedMissingInputs));
    map.put(SkyFunctions.BUILD_INFO_COLLECTION, new BuildInfoCollectionFunction(artifactFactory));
    map.put(SkyFunctions.BUILD_INFO, new WorkspaceStatusFunction());
    map.put(SkyFunctions.COVERAGE_REPORT, new CoverageReportFunction());
    ActionExecutionFunction actionExecutionFunction = new ActionExecutionFunction(skyframeActionExecutor, tsgm);
    map.put(SkyFunctions.ACTION_EXECUTION, actionExecutionFunction);
    this.actionExecutionFunction = actionExecutionFunction;
    map.put(SkyFunctions.RECURSIVE_FILESYSTEM_TRAVERSAL, new RecursiveFilesystemTraversalFunction());
    map.put(SkyFunctions.FILESET_ENTRY, new FilesetEntryFunction());
    map.put(SkyFunctions.ACTION_TEMPLATE_EXPANSION, new ActionTemplateExpansionFunction());
    map.put(SkyFunctions.LOCAL_REPOSITORY_LOOKUP, new LocalRepositoryLookupFunction());
    map.putAll(extraSkyFunctions);
    return map.build();
}
Also used : SkyFunction(com.google.devtools.build.skyframe.SkyFunction) ImmutableMap(com.google.common.collect.ImmutableMap) ConfiguredRuleClassProvider(com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider) Semaphore(java.util.concurrent.Semaphore) SkyFunctionName(com.google.devtools.build.skyframe.SkyFunctionName)

Example 9 with ConfiguredRuleClassProvider

use of com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider in project bazel by bazelbuild.

the class BuildEncyclopediaGenerator method createRuleClassProvider.

private static ConfiguredRuleClassProvider createRuleClassProvider(String classProvider) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    Class<?> providerClass = Class.forName(classProvider);
    Method createMethod = providerClass.getMethod("create");
    return (ConfiguredRuleClassProvider) createMethod.invoke(null);
}
Also used : ConfiguredRuleClassProvider(com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider) Method(java.lang.reflect.Method)

Example 10 with ConfiguredRuleClassProvider

use of com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider in project bazel by bazelbuild.

the class ListRuleMain method createRuleClassProvider.

private static ConfiguredRuleClassProvider createRuleClassProvider(String classProvider) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    Class<?> providerClass = Class.forName(classProvider);
    Method createMethod = providerClass.getMethod("create");
    return (ConfiguredRuleClassProvider) createMethod.invoke(null);
}
Also used : ConfiguredRuleClassProvider(com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider) Method(java.lang.reflect.Method)

Aggregations

ConfiguredRuleClassProvider (com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider)14 Before (org.junit.Before)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)2 RuleClass (com.google.devtools.build.lib.packages.RuleClass)2 PathPackageLocator (com.google.devtools.build.lib.pkgcache.PathPackageLocator)2 BlazeCommand (com.google.devtools.build.lib.runtime.BlazeCommand)2 SkyFunction (com.google.devtools.build.skyframe.SkyFunction)2 SkyFunctionName (com.google.devtools.build.skyframe.SkyFunctionName)2 Method (java.lang.reflect.Method)2 Test (org.junit.Test)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Builder (com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider.Builder)1 RuleSet (com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider.RuleSet)1 NoBuildEvent (com.google.devtools.build.lib.analysis.NoBuildEvent)1 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)1 ConfigurationFactory (com.google.devtools.build.lib.analysis.config.ConfigurationFactory)1 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)1