Search in sources :

Example 1 with ProjectFile

use of com.google.devtools.build.lib.runtime.ProjectFile in project bazel by bazelbuild.

the class ProjectFileSupport method handleProjectFiles.

/**
   * Reads any project files specified on the command line and updates the options parser
   * accordingly. If project files cannot be read or if they contain unparsable options, or if they
   * are not enabled, then it throws an exception instead.
   */
public static void handleProjectFiles(CommandEnvironment env, OptionsParser optionsParser, String command) throws OptionsParsingException {
    BlazeRuntime runtime = env.getRuntime();
    List<String> targets = optionsParser.getResidue();
    ProjectFile.Provider projectFileProvider = runtime.getProjectFileProvider();
    if (projectFileProvider != null && !targets.isEmpty() && targets.get(0).startsWith(PROJECT_FILE_PREFIX)) {
        if (targets.size() > 1) {
            throw new OptionsParsingException("Cannot handle more than one +<file> argument yet");
        }
        if (!optionsParser.getOptions(CommonCommandOptions.class).allowProjectFiles) {
            throw new OptionsParsingException("project file support is not enabled");
        }
        // TODO(bazel-team): This is currently treated as a path relative to the workspace - if the
        // cwd is a subdirectory of the workspace, that will be surprising, and we should interpret it
        // relative to the cwd instead.
        PathFragment projectFilePath = new PathFragment(targets.get(0).substring(1));
        List<Path> packagePath = PathPackageLocator.create(env.getOutputBase(), optionsParser.getOptions(PackageCacheOptions.class).packagePath, env.getReporter(), env.getWorkspace(), env.getWorkingDirectory()).getPathEntries();
        ProjectFile projectFile = projectFileProvider.getProjectFile(env.getWorkingDirectory(), packagePath, projectFilePath);
        env.getReporter().handle(Event.info("Using " + projectFile.getName()));
        optionsParser.parse(OptionPriority.RC_FILE, projectFile.getName(), projectFile.getCommandLineFor(command));
        env.getEventBus().post(new GotProjectFileEvent(projectFile.getName()));
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ProjectFile(com.google.devtools.build.lib.runtime.ProjectFile) OptionsParsingException(com.google.devtools.common.options.OptionsParsingException) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) BlazeRuntime(com.google.devtools.build.lib.runtime.BlazeRuntime)

Aggregations

PackageCacheOptions (com.google.devtools.build.lib.pkgcache.PackageCacheOptions)1 BlazeRuntime (com.google.devtools.build.lib.runtime.BlazeRuntime)1 ProjectFile (com.google.devtools.build.lib.runtime.ProjectFile)1 Path (com.google.devtools.build.lib.vfs.Path)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 OptionsParsingException (com.google.devtools.common.options.OptionsParsingException)1