Search in sources :

Example 1 with HeaderMap

use of com.facebook.buck.apple.clang.HeaderMap in project buck by facebook.

the class ProjectGeneratorTest method assertThatHeaderMapWithoutSymLinksContains.

private void assertThatHeaderMapWithoutSymLinksContains(Path root, ImmutableMap<String, String> content) throws IOException {
    // Read the tree's header map.
    byte[] headerMapBytes;
    try (InputStream headerMapInputStream = projectFilesystem.newFileInputStream(root.resolve(".hmap"))) {
        headerMapBytes = ByteStreams.toByteArray(headerMapInputStream);
    }
    HeaderMap headerMap = HeaderMap.deserialize(headerMapBytes);
    assertNotNull(headerMap);
    assertThat(headerMap.getNumEntries(), equalTo(content.size()));
    for (Map.Entry<String, String> entry : content.entrySet()) {
        String key = entry.getKey();
        Path target = Paths.get(entry.getValue()).toAbsolutePath();
        // Check the header map
        assertThat(headerMap.lookup(key), equalTo(target.toString()));
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) HeaderMap(com.facebook.buck.apple.clang.HeaderMap)

Example 2 with HeaderMap

use of com.facebook.buck.apple.clang.HeaderMap in project buck by facebook.

the class HeaderMapStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException {
    LOG.debug("Writing header map with %d entries to %s", entries.size(), output);
    HeaderMap.Builder builder = HeaderMap.builder();
    for (Map.Entry<Path, Path> entry : entries.entrySet()) {
        builder.add(entry.getKey().toString(), entry.getValue());
    }
    HeaderMap headerMap = builder.build();
    filesystem.writeBytesToPath(headerMap.getBytes(), output);
    return StepExecutionResult.SUCCESS;
}
Also used : Path(java.nio.file.Path) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) HeaderMap(com.facebook.buck.apple.clang.HeaderMap)

Example 3 with HeaderMap

use of com.facebook.buck.apple.clang.HeaderMap in project buck by facebook.

the class CxxCompilationDatabaseIntegrationTest method verifyHeaders.

private void verifyHeaders(ProjectWorkspace projectWorkspace, Path path, String... headers) throws IOException {
    Path resolvedPath = headerSymlinkTreePath(path);
    if (PREPROCESSOR_SUPPORTS_HEADER_MAPS) {
        final List<String> presentHeaders = new ArrayList<>();
        HeaderMap headerMap = HeaderMap.loadFromFile(projectWorkspace.getPath(resolvedPath).toFile());
        headerMap.visit((str, prefix, suffix) -> presentHeaders.add(str));
        assertThat(presentHeaders, containsInAnyOrder(headers));
    } else {
        for (String header : headers) {
            assertThat(Files.exists(projectWorkspace.getPath(resolvedPath.resolve(header))), is(true));
        }
    }
}
Also used : Path(java.nio.file.Path) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) ArrayList(java.util.ArrayList)

Example 4 with HeaderMap

use of com.facebook.buck.apple.clang.HeaderMap in project buck by facebook.

the class HeaderMapStepTest method testHeaderMap.

@Test
public void testHeaderMap() throws IOException {
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmpDir.getRoot().toPath());
    ExecutionContext context = TestExecutionContext.newInstance();
    Path output = Paths.get("headers.hmap");
    ImmutableMap<Path, Path> entries = ImmutableMap.of(Paths.get("file1.h"), Paths.get("/some/absolute/path.h"), Paths.get("file2.h"), Paths.get("/other/absolute/path.h"), Paths.get("prefix/file1.h"), Paths.get("/some/absolute/path.h"));
    HeaderMapStep step = new HeaderMapStep(projectFilesystem, output, entries);
    step.execute(context);
    assertTrue(projectFilesystem.exists(output));
    byte[] headerMapBytes = ByteStreams.toByteArray(projectFilesystem.newFileInputStream(output));
    HeaderMap headerMap = HeaderMap.deserialize(headerMapBytes);
    assertNotNull(headerMap);
    assertThat(headerMap.getNumEntries(), equalTo(entries.size()));
    for (Map.Entry<Path, Path> entry : entries.entrySet()) {
        assertThat(headerMap.lookup(entry.getKey().toString()), equalTo(entry.getValue().toString()));
    }
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) Test(org.junit.Test)

Example 5 with HeaderMap

use of com.facebook.buck.apple.clang.HeaderMap in project buck by facebook.

the class ProjectGeneratorTest method assertThatHeaderSymlinkTreeContains.

private void assertThatHeaderSymlinkTreeContains(Path root, ImmutableMap<String, String> content) throws IOException {
    // Read the tree's header map.
    byte[] headerMapBytes;
    try (InputStream headerMapInputStream = projectFilesystem.newFileInputStream(root.resolve(".hmap"))) {
        headerMapBytes = ByteStreams.toByteArray(headerMapInputStream);
    }
    HeaderMap headerMap = HeaderMap.deserialize(headerMapBytes);
    assertNotNull(headerMap);
    assertThat(headerMap.getNumEntries(), equalTo(content.size()));
    for (Map.Entry<String, String> entry : content.entrySet()) {
        String key = entry.getKey();
        Path link = root.resolve(Paths.get(key));
        Path target = Paths.get(entry.getValue()).toAbsolutePath();
        // Check the filesystem symlink
        assertTrue(projectFilesystem.isSymLink(link));
        assertEquals(target, projectFilesystem.readSymLink(link));
        // Check the header map
        assertThat(headerMap.lookup(key), equalTo(Paths.get("../../").resolve(projectCell.getRoot().getFileName()).resolve(link).toString()));
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) HeaderMap(com.facebook.buck.apple.clang.HeaderMap)

Aggregations

HeaderMap (com.facebook.buck.apple.clang.HeaderMap)5 Path (java.nio.file.Path)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 NSString (com.dd.plist.NSString)2 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)2 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)2 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)2 PathSourcePath (com.facebook.buck.rules.PathSourcePath)2 SourcePath (com.facebook.buck.rules.SourcePath)2 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)2 InputStream (java.io.InputStream)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 ExecutionContext (com.facebook.buck.step.ExecutionContext)1 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1