Search in sources :

Example 31 with Path

use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.

the class Root method middlemanRoot.

// TODO(kchodorow): remove once roots don't need to know if they're in the main repo.
public static Root middlemanRoot(Path execRoot, Path outputDir, boolean isMainRepo) {
    Path root = outputDir.getRelative("internal");
    Preconditions.checkArgument(root.startsWith(execRoot));
    Preconditions.checkArgument(!root.equals(execRoot));
    return new Root(execRoot, root, true, isMainRepo);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path)

Example 32 with Path

use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.

the class ArtifactFactory method getFilesetArtifact.

/**
   * Returns an artifact that represents the output directory of a Fileset at the given
   * root-relative path under the given root, creating it if not found. This method only works for
   * normalized, relative paths.
   *
   * <p>The root must be below the execRootParent, and the execPath of the resulting Artifact is
   * computed as {@code root.getRelative(rootRelativePath).relativeTo(root.execRoot)}.
   */
public Artifact getFilesetArtifact(PathFragment rootRelativePath, Root root, ArtifactOwner owner) {
    validatePath(rootRelativePath, root);
    Path path = root.getPath().getRelative(rootRelativePath);
    return getArtifact(path, root, path.relativeTo(root.getExecRoot()), owner, SpecialArtifactType.FILESET);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path)

Example 33 with Path

use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.

the class ArtifactFactory method getConstantMetadataArtifact.

public Artifact getConstantMetadataArtifact(PathFragment rootRelativePath, Root root, ArtifactOwner owner) {
    validatePath(rootRelativePath, root);
    Path path = root.getPath().getRelative(rootRelativePath);
    return getArtifact(path, root, path.relativeTo(root.getExecRoot()), owner, SpecialArtifactType.CONSTANT_METADATA);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path)

Example 34 with Path

use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.

the class ProfileCommand method exec.

@Override
public ExitCode exec(final CommandEnvironment env, OptionsProvider options) {
    ProfileOptions opts = options.getOptions(ProfileOptions.class);
    if (!opts.vfsStats) {
        opts.vfsStatsLimit = 0;
    }
    try (PrintStream out = new PrintStream(env.getReporter().getOutErr().getOutputStream())) {
        env.getReporter().handle(Event.warn(null, "This information is intended for consumption by Blaze developers" + " only, and may change at any time.  Script against it at your own risk"));
        if (opts.combine != null && opts.dumpMode == null) {
            MultiProfileStatistics statistics = new MultiProfileStatistics(env.getWorkingDirectory(), env.getWorkspaceName(), options.getResidue(), getInfoListener(env), opts.vfsStatsLimit > 0);
            Path outputFile = env.getWorkingDirectory().getRelative(opts.combine);
            try (PrintStream output = new PrintStream(new BufferedOutputStream(outputFile.getOutputStream()))) {
                if (opts.html) {
                    env.getReporter().handle(Event.info("Creating HTML output in " + outputFile));
                    HtmlCreator.create(output, statistics, opts.htmlDetails, opts.htmlPixelsPerSecond, opts.vfsStatsLimit);
                } else {
                    env.getReporter().handle(Event.info("Creating text output in " + outputFile));
                    new PhaseText(output, statistics.getSummaryStatistics(), statistics.getSummaryPhaseStatistics(), Optional.<CriticalPathStatistics>absent(), statistics.getMissingActionsCount(), opts.vfsStatsLimit).print();
                }
            } catch (IOException e) {
                env.getReporter().handle(Event.error("Failed to write to output file " + outputFile + ":" + e.getMessage()));
            }
        } else {
            for (String name : options.getResidue()) {
                Path profileFile = env.getWorkingDirectory().getRelative(name);
                try {
                    ProfileInfo info = ProfileInfo.loadProfileVerbosely(profileFile, getInfoListener(env));
                    if (opts.dumpMode == null || !opts.dumpMode.contains("unsorted")) {
                        ProfileInfo.aggregateProfile(info, getInfoListener(env));
                    }
                    if (opts.taskTree != null) {
                        printTaskTree(out, name, info, opts.taskTree, opts.taskTreeThreshold);
                        continue;
                    }
                    if (opts.dumpMode != null) {
                        dumpProfile(info, out, opts.dumpMode);
                        continue;
                    }
                    PhaseSummaryStatistics phaseSummaryStatistics = new PhaseSummaryStatistics(info);
                    EnumMap<ProfilePhase, PhaseStatistics> phaseStatistics = new EnumMap<>(ProfilePhase.class);
                    for (ProfilePhase phase : ProfilePhase.values()) {
                        phaseStatistics.put(phase, new PhaseStatistics(phase, info, env.getWorkspaceName(), opts.vfsStatsLimit > 0));
                    }
                    CriticalPathStatistics critPathStats = new CriticalPathStatistics(info);
                    if (opts.html) {
                        Path htmlFile = profileFile.getParentDirectory().getChild(profileFile.getBaseName() + ".html");
                        env.getReporter().handle(Event.info("Creating HTML output in " + htmlFile));
                        HtmlCreator.create(info, htmlFile, phaseSummaryStatistics, phaseStatistics, critPathStats, info.getMissingActionsCount(), opts.htmlDetails, opts.htmlPixelsPerSecond, opts.vfsStatsLimit, opts.chart, opts.htmlHistograms);
                    } else {
                        new PhaseText(out, phaseSummaryStatistics, phaseStatistics, Optional.of(critPathStats), info.getMissingActionsCount(), opts.vfsStatsLimit).print();
                    }
                } catch (IOException e) {
                    System.out.println(e);
                    env.getReporter().handle(Event.error("Failed to analyze profile file(s): " + e.getMessage()));
                }
            }
        }
    }
    return ExitCode.SUCCESS;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PrintStream(java.io.PrintStream) PhaseText(com.google.devtools.build.lib.profiler.output.PhaseText) MultiProfileStatistics(com.google.devtools.build.lib.profiler.statistics.MultiProfileStatistics) IOException(java.io.IOException) ProfileInfo(com.google.devtools.build.lib.profiler.ProfileInfo) PhaseSummaryStatistics(com.google.devtools.build.lib.profiler.statistics.PhaseSummaryStatistics) ProfilePhase(com.google.devtools.build.lib.profiler.ProfilePhase) PhaseStatistics(com.google.devtools.build.lib.profiler.statistics.PhaseStatistics) BufferedOutputStream(java.io.BufferedOutputStream) EnumMap(java.util.EnumMap) CriticalPathStatistics(com.google.devtools.build.lib.profiler.statistics.CriticalPathStatistics)

Example 35 with Path

use of com.google.devtools.build.lib.vfs.Path 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

Path (com.google.devtools.build.lib.vfs.Path)492 Test (org.junit.Test)250 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)111 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)105 IOException (java.io.IOException)102 Artifact (com.google.devtools.build.lib.actions.Artifact)37 SkyKey (com.google.devtools.build.skyframe.SkyKey)37 ArrayList (java.util.ArrayList)29 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)17 FileSystem (com.google.devtools.build.lib.vfs.FileSystem)17 InMemoryFileSystem (com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem)17 HashMap (java.util.HashMap)17 WindowsPath (com.google.devtools.build.lib.windows.WindowsFileSystem.WindowsPath)16 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)14 Before (org.junit.Before)14 Package (com.google.devtools.build.lib.packages.Package)13 FileStatus (com.google.devtools.build.lib.vfs.FileStatus)13 Map (java.util.Map)12 Nullable (javax.annotation.Nullable)12 Executor (com.google.devtools.build.lib.actions.Executor)10