Search in sources :

Example 6 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class ArtifactCacheHandler method handleGet.

private int handleGet(Request baseRequest, HttpServletResponse response) throws IOException {
    if (!artifactCache.isPresent()) {
        response.getWriter().write("Serving local cache is disabled for this instance.");
        return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }
    String path = baseRequest.getUri().getPath();
    String[] pathElements = path.split("/");
    if (pathElements.length != 4 || !pathElements[2].equals("key")) {
        response.getWriter().write("Incorrect url format.");
        return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }
    RuleKey ruleKey = new RuleKey(pathElements[3]);
    Path temp = null;
    try {
        projectFilesystem.mkdirs(projectFilesystem.getBuckPaths().getScratchDir());
        temp = projectFilesystem.createTempFile(projectFilesystem.getBuckPaths().getScratchDir(), "outgoing_rulekey", ".tmp");
        CacheResult fetchResult = artifactCache.get().fetch(ruleKey, LazyPath.ofInstance(temp));
        if (!fetchResult.getType().isSuccess()) {
            return HttpServletResponse.SC_NOT_FOUND;
        }
        final Path tempFinal = temp;
        HttpArtifactCacheBinaryProtocol.FetchResponse fetchResponse = new HttpArtifactCacheBinaryProtocol.FetchResponse(ImmutableSet.of(ruleKey), fetchResult.getMetadata(), new ByteSource() {

            @Override
            public InputStream openStream() throws IOException {
                return projectFilesystem.newFileInputStream(tempFinal);
            }
        });
        fetchResponse.write(response.getOutputStream());
        response.setContentLengthLong(fetchResponse.getContentLength());
        return HttpServletResponse.SC_OK;
    } finally {
        if (temp != null) {
            projectFilesystem.deleteFileAtPathIfExists(temp);
        }
    }
}
Also used : BorrowablePath(com.facebook.buck.io.BorrowablePath) LazyPath(com.facebook.buck.io.LazyPath) Path(java.nio.file.Path) RuleKey(com.facebook.buck.rules.RuleKey) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) HttpArtifactCacheBinaryProtocol(com.facebook.buck.artifact_cache.HttpArtifactCacheBinaryProtocol) CacheResult(com.facebook.buck.artifact_cache.CacheResult) ByteSource(com.google.common.io.ByteSource) IOException(java.io.IOException)

Example 7 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class AaptPackageResourcesTest method testThatChangingAndroidManifestChangesRuleKey.

@Test
public void testThatChangingAndroidManifestChangesRuleKey() {
    // Generate a rule key for the defaults.
    AaptConstructorArgs args = new AaptConstructorArgs();
    args.manifest = createPathSourcePath("AndroidManifest.xml", "same_content");
    RuleKey previousRuleKey = calculateRuleKey(args);
    args.manifest = createPathSourcePath("other/AndroidManifest.xml", "same_content");
    previousRuleKey = assertKeyChanged(previousRuleKey, args);
    args.manifest = createPathSourcePath("other/AndroidManifest.xml", "different_content");
    previousRuleKey = assertKeyChanged(previousRuleKey, args);
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) Test(org.junit.Test)

Example 8 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class AaptPackageResourcesTest method testThatChangingResourceDirectoryOrderChangesRulekey.

@Test
public void testThatChangingResourceDirectoryOrderChangesRulekey() {
    // Generate a rule key for the defaults.
    AaptConstructorArgs args = new AaptConstructorArgs();
    RuleKey previousRuleKey = calculateRuleKey(args);
    args.hasAndroidResourceDeps = ImmutableList.of(resource1, resource2);
    args.filteredResourcesProvider = new IdentityResourcesProvider(ImmutableList.of(Paths.get("res1"), Paths.get("res2")));
    previousRuleKey = assertKeyChanged(previousRuleKey, args);
    args.hasAndroidResourceDeps = ImmutableList.of(resource1, resource2);
    args.filteredResourcesProvider = new IdentityResourcesProvider(ImmutableList.of(Paths.get("res2"), Paths.get("res1")));
// TODO(cjhopman): AaptPackageResources' rulekey doesn't properly reflect changes in the
// ordering of resource-only dependencies.
// previousRuleKey = assertKeyChanged(previousRuleKey, args);
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) Test(org.junit.Test)

Example 9 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class AaptPackageResourcesTest method testThatChangingResourcesChangesRuleKey.

@Test
public void testThatChangingResourcesChangesRuleKey() {
    // Generate a rule key for the defaults.
    AaptConstructorArgs args = new AaptConstructorArgs();
    RuleKey previousRuleKey = calculateRuleKey(args);
    args.hasAndroidResourceDeps = ImmutableList.of(resource1);
    previousRuleKey = assertKeyChanged(previousRuleKey, args);
    createPathSourcePath("res1", "different_value");
    previousRuleKey = assertKeyChanged(previousRuleKey, args);
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) Test(org.junit.Test)

Example 10 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class AaptPackageResourcesTest method testThatChangingManifestEntriesChangesRuleKey.

@Test
public void testThatChangingManifestEntriesChangesRuleKey() {
    // Generate a rule key for the defaults.
    AaptConstructorArgs args = new AaptConstructorArgs();
    args.manifestEntries = ManifestEntries.builder().setDebugMode(false).build();
    RuleKey previousRuleKey = calculateRuleKey(args);
    args.manifestEntries = ManifestEntries.builder().setDebugMode(true).build();
    previousRuleKey = assertKeyChanged(previousRuleKey, args);
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) Test(org.junit.Test)

Aggregations

RuleKey (com.facebook.buck.rules.RuleKey)149 Test (org.junit.Test)112 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)71 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)71 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)71 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)70 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)57 Path (java.nio.file.Path)57 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)42 BuildTarget (com.facebook.buck.model.BuildTarget)42 BuildRule (com.facebook.buck.rules.BuildRule)42 LazyPath (com.facebook.buck.io.LazyPath)34 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)34 PathSourcePath (com.facebook.buck.rules.PathSourcePath)33 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)30 SourcePath (com.facebook.buck.rules.SourcePath)28 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)27 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)25 IOException (java.io.IOException)25 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)23