MCPcopy Index your code
hub / github.com/nodejs/node / WriteHmap

Function WriteHmap

tools/gyp/pylib/gyp/mac_tool.py:690–761  ·  view source on GitHub ↗

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

(output_name, filelist)

Source from the content-addressed store, hash-verified

688
689
690def WriteHmap(output_name, filelist):
691 """Generates a header map based on |filelist|.
692
693 Per Mark Mentovai:
694 A header map is structured essentially as a hash table, keyed by names used
695 in #includes, and providing pathnames to the actual files.
696
697 The implementation below and the comment above comes from inspecting:
698 http://www.opensource.apple.com/source/distcc/distcc-2503/distcc_dist/include_server/headermap.py?txt
699 while also looking at the implementation in clang in:
700 https://llvm.org/svn/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp
701 """
702 magic = 1751998832
703 version = 1
704 _reserved = 0
705 count = len(filelist)
706 capacity = NextGreaterPowerOf2(count)
707 strings_offset = 24 + (12 * capacity)
708 max_value_length = max(len(value) for value in filelist.values())
709
710 out = open(output_name, "wb")
711 out.write(
712 struct.pack(
713 "<LHHLLLL",
714 magic,
715 version,
716 _reserved,
717 strings_offset,
718 count,
719 capacity,
720 max_value_length,
721 )
722 )
723
724 # Create empty hashmap buckets.
725 buckets = [None] * capacity
726 for file, path in filelist.items():
727 key = 0
728 for c in file:
729 key += ord(c.lower()) * 13
730
731 # Fill next empty bucket.
732 while buckets[key & capacity - 1] is not None:
733 key = key + 1
734 buckets[key & capacity - 1] = (file, path)
735
736 next_offset = 1
737 for bucket in buckets:
738 if bucket is None:
739 out.write(struct.pack("<LLL", 0, 0, 0))
740 else:
741 (file, path) = bucket
742 key_offset = next_offset
743 prefix_offset = key_offset + len(file) + 1
744 suffix_offset = prefix_offset + len(os.path.dirname(path) + os.sep) + 1
745 next_offset = suffix_offset + len(os.path.basename(path)) + 1
746 out.write(struct.pack("<LLL", key_offset, prefix_offset, suffix_offset))
747

Callers 1

Calls 6

NextGreaterPowerOf2Function · 0.85
maxFunction · 0.50
openFunction · 0.50
valuesMethod · 0.45
writeMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…