Search in sources :

Example 1 with PathFragment

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

the class BazelConfiguration method pathOrDefault.

private static String pathOrDefault(@Nullable String path, @Nullable PathFragment sh) {
    if (OS.getCurrent() != OS.WINDOWS) {
        return path == null ? "/bin:/usr/bin" : path;
    }
    // Attempt to compute the MSYS root (the real Windows path of "/") from `sh`.
    String newPath = "";
    if (sh != null && sh.getParentDirectory() != null) {
        newPath = sh.getParentDirectory().getPathString();
        if (sh.getParentDirectory().endsWith(new PathFragment("usr/bin"))) {
            newPath += ";" + sh.getParentDirectory().getParentDirectory().replaceName("bin").getPathString();
        } else if (sh.getParentDirectory().endsWith(new PathFragment("bin"))) {
            newPath += ";" + sh.getParentDirectory().replaceName("usr").getRelative("bin").getPathString();
        }
        newPath = newPath.replace('/', '\\');
        if (path != null) {
            newPath += ";" + path;
        }
    }
    return newPath;
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 2 with PathFragment

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

the class AndroidNdkRepositoryFunction method fetch.

@Override
public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env, Map<String, String> markerData) throws InterruptedException, RepositoryFunctionException {
    Map<String, String> environ = declareEnvironmentDependencies(markerData, env, PATH_ENV_VAR_AS_LIST);
    if (environ == null) {
        return null;
    }
    prepareLocalRepositorySymlinkTree(rule, outputDirectory);
    WorkspaceAttributeMapper attributes = WorkspaceAttributeMapper.of(rule);
    PathFragment pathFragment;
    if (attributes.isAttributeValueExplicitlySpecified("path")) {
        pathFragment = getTargetPath(rule, directories.getWorkspace());
    } else if (environ.get(PATH_ENV_VAR) != null) {
        pathFragment = getAndroidNdkHomeEnvironmentVar(directories.getWorkspace(), environ);
    } else {
        throw new RepositoryFunctionException(new EvalException(rule.getLocation(), "Either the path attribute of android_ndk_repository or the ANDROID_NDK_HOME " + " environment variable must be set."), Transience.PERSISTENT);
    }
    Path ndkSymlinkTreeDirectory = outputDirectory.getRelative("ndk");
    try {
        ndkSymlinkTreeDirectory.createDirectory();
    } catch (IOException e) {
        throw new RepositoryFunctionException(e, Transience.TRANSIENT);
    }
    Path ndkHome = directories.getOutputBase().getFileSystem().getPath(pathFragment);
    if (!symlinkLocalRepositoryContents(ndkSymlinkTreeDirectory, ndkHome)) {
        return null;
    }
    String ruleName = rule.getName();
    // We need to fetch the NDK release info from the actual home to avoid cycle in the
    // dependency graph (the path relative to the repository root depends on the
    // repository being fetched).
    NdkRelease ndkRelease = getNdkRelease(ndkHome, env);
    if (env.valuesMissing()) {
        return null;
    }
    String apiLevelString;
    if (attributes.isAttributeValueExplicitlySpecified("api_level")) {
        try {
            apiLevelString = attributes.get("api_level", Type.INTEGER).toString();
        } catch (EvalException e) {
            throw new RepositoryFunctionException(e, Transience.PERSISTENT);
        }
    } else {
        DirectoryListingValue platformsDirectoryValue = AndroidRepositoryUtils.getDirectoryListing(ndkHome, PLATFORMS_DIR, env);
        if (platformsDirectoryValue == null) {
            return null;
        }
        ImmutableSortedSet<Integer> apiLevels = AndroidRepositoryUtils.getApiLevels(platformsDirectoryValue.getDirents());
        if (apiLevels.isEmpty()) {
            // themselves.
            throw new RepositoryFunctionException(new EvalException(rule.getLocation(), "android_ndk_repository requires that at least one Android platform is present in " + "the Android NDK platforms directory. Please ensure that the path attribute " + "or the ANDROID_NDK_HOME environment variable points to a valid NDK."), Transience.PERSISTENT);
        }
        apiLevelString = apiLevels.first().toString();
    }
    // NDK minor revisions should be backwards compatible within a major revision, the crosstools
    // we generate don't care about the minor revision.
    NdkMajorRevision ndkMajorRevision;
    if (!ndkRelease.isValid) {
        String warningMessage = String.format("The revision of the Android NDK referenced by android_ndk_repository rule '%s' " + "could not be determined (the revision string found is '%s'). Defaulting to " + "revision %s.", ruleName, ndkRelease.rawRelease, AndroidNdkCrosstools.LATEST_KNOWN_REVISION.getKey());
        env.getListener().handle(Event.warn(warningMessage));
        ndkMajorRevision = AndroidNdkCrosstools.LATEST_KNOWN_REVISION.getValue();
    } else if (!AndroidNdkCrosstools.isKnownNDKRevision(ndkRelease)) {
        String warningMessage = String.format("The major revision of the Android NDK referenced by android_ndk_repository rule " + "'%s' is %s. The major revisions supported by Bazel are %s. Defaulting to " + "revision %s.", ruleName, ndkRelease.majorRevision, AndroidNdkCrosstools.KNOWN_NDK_MAJOR_REVISIONS.keySet(), AndroidNdkCrosstools.LATEST_KNOWN_REVISION.getKey());
        env.getListener().handle(Event.warn(warningMessage));
        ndkMajorRevision = AndroidNdkCrosstools.LATEST_KNOWN_REVISION.getValue();
    } else {
        ndkMajorRevision = AndroidNdkCrosstools.KNOWN_NDK_MAJOR_REVISIONS.get(ndkRelease.majorRevision);
    }
    ApiLevel apiLevel = ndkMajorRevision.apiLevel(env.getListener(), ruleName, apiLevelString);
    ImmutableList.Builder<CrosstoolStlPair> crosstoolsAndStls = ImmutableList.builder();
    try {
        String hostPlatform = AndroidNdkCrosstools.getHostPlatform(ndkRelease);
        NdkPaths ndkPaths = new NdkPaths(ruleName, hostPlatform, apiLevel);
        for (StlImpl stlImpl : StlImpls.get(ndkPaths)) {
            CrosstoolRelease crosstoolRelease = ndkMajorRevision.crosstoolRelease(ndkPaths, stlImpl, hostPlatform);
            crosstoolsAndStls.add(new CrosstoolStlPair(crosstoolRelease, stlImpl));
        }
    } catch (NdkCrosstoolsException e) {
        throw new RepositoryFunctionException(new IOException(e), Transience.PERSISTENT);
    }
    String buildFile = createBuildFile(ruleName, crosstoolsAndStls.build());
    writeBuildFile(outputDirectory, buildFile);
    return RepositoryDirectoryValue.builder().setPath(outputDirectory);
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) ToolPath(com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.ToolPath) Path(com.google.devtools.build.lib.vfs.Path) NdkRelease(com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.NdkRelease) ImmutableList(com.google.common.collect.ImmutableList) StlImpl(com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.StlImpl) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) EvalException(com.google.devtools.build.lib.syntax.EvalException) IOException(java.io.IOException) NdkPaths(com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.NdkPaths) DirectoryListingValue(com.google.devtools.build.lib.skyframe.DirectoryListingValue) NdkMajorRevision(com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.NdkMajorRevision) ApiLevel(com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.ApiLevel) CrosstoolRelease(com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CrosstoolRelease) WorkspaceAttributeMapper(com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper) NdkCrosstoolsException(com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.AndroidNdkCrosstools.NdkCrosstoolsException)

Example 3 with PathFragment

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

the class BazelJavaSemantics method getExtraArguments.

@Override
public List<String> getExtraArguments(RuleContext ruleContext, ImmutableList<Artifact> sources) {
    if (ruleContext.getRule().getRuleClass().equals("java_test")) {
        if (useLegacyJavaTest(ruleContext)) {
            if (ruleContext.getConfiguration().getTestArguments().isEmpty() && !ruleContext.attributes().isAttributeValueExplicitlySpecified("args")) {
                ImmutableList.Builder<String> builder = ImmutableList.builder();
                for (Artifact artifact : sources) {
                    PathFragment path = artifact.getRootRelativePath();
                    String className = JavaUtil.getJavaFullClassname(FileSystemUtils.removeExtension(path));
                    if (className != null) {
                        builder.add(className);
                    }
                }
                return builder.build();
            }
        }
    }
    return ImmutableList.<String>of();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 4 with PathFragment

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

the class AndroidStudioInfoAspect method makeArtifactLocation.

private static ArtifactLocation makeArtifactLocation(Package pkg, Label label) {
    Root root = Root.asSourceRoot(pkg.getSourceRoot(), pkg.getPackageIdentifier().getRepository().isMain());
    PathFragment relativePath = pkg.getBuildFile().getPath().relativeTo(root.getPath());
    return makeArtifactLocation(root, relativePath, isExternal(label));
}
Also used : Root(com.google.devtools.build.lib.actions.Root) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 5 with PathFragment

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

the class AndroidStudioInfoAspect method getOutputFilePath.

private static PathFragment getOutputFilePath(ConfiguredTarget base, RuleContext ruleContext, String suffix) {
    PathFragment packagePathFragment = ruleContext.getLabel().getPackageIdentifier().getSourceRoot();
    String name = base.getLabel().getName();
    return new PathFragment(packagePathFragment, new PathFragment(name + suffix));
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Aggregations

PathFragment (com.google.devtools.build.lib.vfs.PathFragment)512 Test (org.junit.Test)208 Artifact (com.google.devtools.build.lib.actions.Artifact)184 Path (com.google.devtools.build.lib.vfs.Path)111 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)65 SkyKey (com.google.devtools.build.skyframe.SkyKey)56 IOException (java.io.IOException)38 ArrayList (java.util.ArrayList)35 ImmutableList (com.google.common.collect.ImmutableList)32 Root (com.google.devtools.build.lib.actions.Root)32 HashMap (java.util.HashMap)27 Label (com.google.devtools.build.lib.cmdline.Label)26 LinkedHashMap (java.util.LinkedHashMap)26 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)23 ImmutableMap (com.google.common.collect.ImmutableMap)22 Map (java.util.Map)21 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)20 FilesetTraversalParams (com.google.devtools.build.lib.actions.FilesetTraversalParams)16 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)16 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)16