This is an archive of the discontinued LLVM Phabricator instance.

Add python tool to dump and construct header maps
ClosedPublic

Authored by bruno on May 4 2018, 5:45 PM.

Details

Summary

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 written by Daniel Dunbar.

rdar://problem/39994722

Diff Detail

Repository
rC Clang

Event Timeline

bruno created this revision.May 4 2018, 5:45 PM

Hi Bruno, I just noticed couple of implementation details.

utils/hmaptool/hmaptool
56

Wouldn't it be simpler to use modulo 2?

if num_buckets % 2 == 0
154

This is probably not critically important but maybe we could use math functions instead of iteration here:

from math import *
return ceil( log( value + 1, 2) )

...or if we want to support values <1:

if value <= 0
    raise ArgumentError
if value < 1
    return 0

return ceil( log( value, 2) ) + 1
235

Aren't we expecting just single argument (<headermap path>) here?

bruno added a comment.May 15 2018, 1:46 PM

@jkorous, thanks for taking a look. This is an old python script which I haven't touched before, maybe there were answers to your questions but they are now lost in time. I'll address the review though and upload a new version.

bruno marked an inline comment as done.May 15 2018, 9:48 PM
bruno added inline comments.
utils/hmaptool/hmaptool
56

We want it to be a power of two, not just a multiple.

235

We also need the <dir> from --build-path <dir>

bruno updated this revision to Diff 146992.May 15 2018, 9:49 PM

Update after Jan review.

LGTM but my review was fairly superficial.

utils/hmaptool/hmaptool
56

Of course! Sorry, my mistake.

156

Thanks for teaching me bit_length()!

dexonsmith added inline comments.
test/Preprocessor/headermap-rel.c
0–1

Should we delete this comment now that the header map is human-readable?

2

Should there be some sort of REQUIRES: clause for using hmaptool?

bruno added inline comments.May 18 2018, 4:31 PM
test/Preprocessor/headermap-rel.c
0–1

Sure!

2

Not really needed, hmaptool is setup to work just like clang-rename and others, it will always be available to be used by lit. Additionally, it's not importing any module that isn't in the python standard library.

bruno updated this revision to Diff 147829.May 21 2018, 11:51 AM

Update testcases (and fixed a missing one) after Duncan's review.

Removing the binary header map files is a clear win, but I'd like someone else to approve this.

test/Preprocessor/headermap-rel2.c
0–1

This comment also seems unnecessary.

bruno updated this revision to Diff 147901.May 21 2018, 4:28 PM

Remove more outdated comments

bruno added a comment.May 31 2018, 5:18 PM

Ping.

Without this patch, we would have to add binary header maps for tests in D47157 and D47301, which I would like to avoid.

rsmith accepted this revision.Jun 19 2018, 11:40 AM
rsmith added inline comments.
utils/hmaptool/hmaptool
2

Have you checked this works with both python2 and python3?

82

You'll get an IndexError here if strtable_size is 0.

This revision is now accepted and ready to land.Jun 19 2018, 11:40 AM
bruno updated this revision to Diff 152142.Jun 20 2018, 1:14 PM

Update after Richard's review, fix python3 compatibility and check for zero sized string table

This revision was automatically updated to reflect the committed changes.

This breaks the clang tests on Windows when building using Visual Studio as none of the updated tests can find hmaptool.

Visual Studio as a generator supports multiple configurations, so its bin folder varies depending on the build configuration. The generalized version of the bin directory is: ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin. This is actually the proper bin directory to use for any generator because ${CMAKE_CFG_INTDIR} is simply '.' when the generator (such as ninja) doesn't support multiple configurations.

I can look into a fix and submit a change for review tomorrow if you can't, but in the future please make sure to use the full path to the bin directory (${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) to avoid missing a generator.

bruno added a subscriber: rsmith.Jun 20 2018, 3:53 PM

Hi Stella,

dyung added a subscriber: dyung.Jun 20 2018, 6:26 PM