# Copyright 2016 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. from __future__ import print_function import os import struct import sys def Main(args): if len(args) < 4: print( "Usage: %s output.hmap Foo.framework header1.h..." % args[0], file=sys.stderr) return 1 (out, framework, all_headers) = args[1], args[2], args[3:] framework_name = os.path.basename(framework).split('.')[0] all_headers = map(os.path.abspath, all_headers) filelist = {} for header in all_headers: filename = os.path.basename(header) filelist[filename] = header filelist[os.path.join(framework_name, filename)] = header WriteHmap(out, filelist) return 0 def NextGreaterPowerOf2(x): return 2**(x).bit_length() def WriteHmap(output_name, filelist): """Generates a header map based on |filelist|. Per Mark Mentovai: A header map is structured essentially as a hash table, keyed by names used in #includes, and providing pathnames to the actual files. The implementation below and the comment above comes from inspecting: http://www.opensource.apple.com/source/distcc/distcc-2503/distcc_dist/include_server/headermap.py?txt while also looking at the implementation in clang in: https://llvm.org/svn/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp """ magic = 1751998832 version = 1 _reserved = 0 count = len(filelist) capacity = NextGreaterPowerOf2(count) strings_offset = 24 + (12 * capacity) max_value_length = len(max(filelist.values(), key=lambda v: len(v))) out = open(output_name, 'wb') out.write(struct.pack('