Skip to content

Commit

Permalink
Re-apply: Add python tool to dump and construct header maps
Browse files Browse the repository at this point in the history
Header maps are binary files used by Xcode, which are used to map
header names or paths to other locations. Clang has support for
those since its inception, but there's not a lot of header map
testing around.

Since it's a binary format, testing becomes pretty much brittle
and its hard to even know what's inside if you don't have the
appropriate tools.

Add a python based tool that allows creating and dumping header
maps based on a json description of those. While here, rewrite
tests to use the tool and remove the binary files from the tree.

This tool was initially written by Daniel Dunbar.

Thanks to Stella Stamenova for helping make this work on Windows.

Differential Revision: https://reviews.llvm.org/D46485

rdar://problem/39994722

llvm-svn: 335295
  • Loading branch information
bcardosolopes committed Jun 21, 2018
1 parent 30648ab commit dc3f88a
Show file tree
Hide file tree
Showing 15 changed files with 345 additions and 20 deletions.
1 change: 1 addition & 0 deletions clang/CMakeLists.txt
Expand Up @@ -753,6 +753,7 @@ endif()
if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
add_subdirectory(utils/ClangVisualizers)
endif()
add_subdirectory(utils/hmaptool)

configure_file(
${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
Expand Down
1 change: 1 addition & 0 deletions clang/test/CMakeLists.txt
Expand Up @@ -54,6 +54,7 @@ list(APPEND CLANG_TEST_DEPS
clang-rename
clang-refactor
clang-diff
hmaptool
)

if(CLANG_ENABLE_STATIC_ANALYZER)
Expand Down
10 changes: 2 additions & 8 deletions clang/test/Modules/crash-vfs-headermaps.m
@@ -1,15 +1,9 @@
// REQUIRES: crash-recovery, shell, system-darwin

// This uses a headermap with this entry:
// Foo.h -> Foo/Foo.h

// Copy out the headermap from test/Preprocessor/Inputs/headermap-rel and avoid
// adding another binary format to the repository.

// RUN: rm -rf %t
// RUN: mkdir -p %t/m
// RUN: cp -a %S/../Preprocessor/Inputs/headermap-rel %t/i
// RUN: mkdir -p %t/m %t/i/Foo.framework/Headers
// RUN: echo '// Foo.h' > %t/i/Foo.framework/Headers/Foo.h
// RUN: '%python' hmaptool write %S/../Preprocessor/Inputs/headermap-rel/foo.hmap.json %t/i/foo.hmap

// RUN: not env FORCE_CLANG_DIAGNOSTICS_CRASH= TMPDIR=%t TEMP=%t TMP=%t \
// RUN: %clang -fsyntax-only -fmodules -fmodules-cache-path=%t/m %s \
Expand Down
Binary file removed clang/test/Preprocessor/Inputs/headermap-rel/foo.hmap
Binary file not shown.
6 changes: 6 additions & 0 deletions clang/test/Preprocessor/Inputs/headermap-rel/foo.hmap.json
@@ -0,0 +1,6 @@
{
"mappings" :
{
"Foo.h" : "Foo/Foo.h"
}
}
Binary file not shown.
@@ -0,0 +1,6 @@
{
"mappings" :
{
"someheader.h" : "Product/someheader.h"
}
}
Binary file not shown.
@@ -0,0 +1,6 @@
{
"mappings" :
{
"Foo/Foo.h" : "headers/foo/Foo.h"
}
}
8 changes: 3 additions & 5 deletions clang/test/Preprocessor/headermap-rel.c
@@ -1,8 +1,6 @@

// This uses a headermap with this entry:
// Foo.h -> Foo/Foo.h

// RUN: %clang_cc1 -E %s -o %t.i -I %S/Inputs/headermap-rel/foo.hmap -F %S/Inputs/headermap-rel
// RUN: rm -f %t.hmap
// RUN: '%python' hmaptool write %S/Inputs/headermap-rel/foo.hmap.json %t.hmap
// RUN: %clang_cc1 -E %s -o %t.i -I %t.hmap -F %S/Inputs/headermap-rel
// RUN: FileCheck %s -input-file %t.i

// CHECK: Foo.h is parsed
Expand Down
9 changes: 4 additions & 5 deletions clang/test/Preprocessor/headermap-rel2.c
@@ -1,8 +1,7 @@
// This uses a headermap with this entry:
// someheader.h -> Product/someheader.h

// RUN: %clang_cc1 -v -fsyntax-only %s -iquote %S/Inputs/headermap-rel2/project-headers.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 -H
// RUN: %clang_cc1 -fsyntax-only %s -iquote %S/Inputs/headermap-rel2/project-headers.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 -H 2> %t.out
// RUN: rm -f %t.hmap
// RUN: '%python' hmaptool write %S/Inputs/headermap-rel2/project-headers.hmap.json %t.hmap
// RUN: %clang_cc1 -v -fsyntax-only %s -iquote %t.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 -H
// RUN: %clang_cc1 -fsyntax-only %s -iquote %t.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 -H 2> %t.out
// RUN: FileCheck %s -input-file %t.out

// CHECK: Product/someheader.h
Expand Down
4 changes: 3 additions & 1 deletion clang/test/Preprocessor/nonportable-include-with-hmap.c
@@ -1,5 +1,7 @@
// RUN: rm -f %t.hmap
// RUN: '%python' hmaptool write %S/Inputs/nonportable-hmaps/foo.hmap.json %t.hmap
// RUN: %clang_cc1 -Eonly \
// RUN: -I%S/Inputs/nonportable-hmaps/foo.hmap \
// RUN: -I%t.hmap \
// RUN: -I%S/Inputs/nonportable-hmaps \
// RUN: %s -verify
//
Expand Down
2 changes: 1 addition & 1 deletion clang/test/lit.cfg.py
Expand Up @@ -58,7 +58,7 @@

tools = [
'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'clang-tblgen',
'opt',
'opt', 'hmaptool',
ToolSubst('%clang_func_map', command=FindTool(
'clang-func-mapping'), unresolved='ignore'),
]
Expand Down
16 changes: 16 additions & 0 deletions clang/utils/hmaptool/CMakeLists.txt
@@ -0,0 +1,16 @@
set(CLANG_HMAPTOOL hmaptool)

add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}
COMMAND ${CMAKE_COMMAND} -E make_directory
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL})

list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL})
install(PROGRAMS ${CLANG_HMAPTOOL} DESTINATION bin)

add_custom_target(hmaptool ALL DEPENDS ${Depends})
set_target_properties(hmaptool PROPERTIES FOLDER "Utils")

0 comments on commit dc3f88a

Please sign in to comment.