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()));
}
}
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;
}
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));
}
}
}
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()));
}
}
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()));
}
}
Aggregations