[iOS/GN] Replace the last to gyp-mac-tool commands with standalone scripts.
This adds write_framework_hmap.py and write_framework_modulemap.py under //build/config/ios/. BUG=616813 R=sdefresne@chromium.org Review-Url: https://codereview.chromium.org/2082573006 Cr-Original-Commit-Position: refs/heads/master@{#401228} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: fc86361978c030bac431d9745c2de6a8eed6d014
This commit is contained in:
Родитель
5ac3908296
Коммит
dc110545f2
|
@ -428,7 +428,7 @@ template("ios_framework_bundle") {
|
|||
_compile_headers_map_target = _target_name + "_compile_headers_map"
|
||||
action(_compile_headers_map_target) {
|
||||
visibility = [ ":$_framework_headers_target" ]
|
||||
script = "$root_out_dir/gyp-mac-tool"
|
||||
script = "//build/config/ios/write_framework_hmap.py"
|
||||
outputs = [
|
||||
_header_map_filename,
|
||||
]
|
||||
|
@ -448,7 +448,6 @@ template("ios_framework_bundle") {
|
|||
set_sources_assignment_filter([])
|
||||
|
||||
args = [
|
||||
"compile-ios-framework-header-map",
|
||||
rebase_path(_header_map_filename),
|
||||
rebase_path(_framework_root, root_out_dir),
|
||||
] + rebase_path(sources, root_out_dir)
|
||||
|
@ -457,14 +456,11 @@ template("ios_framework_bundle") {
|
|||
_create_module_map_target = _target_name + "_module_map"
|
||||
action(_create_module_map_target) {
|
||||
visibility = [ ":$_framework_headers_target" ]
|
||||
script = "$root_out_dir/gyp-mac-tool"
|
||||
script = "//build/config/ios/write_framework_modulemap.py"
|
||||
outputs = [
|
||||
"$_framework_root/Modules/module.modulemap",
|
||||
]
|
||||
args = [
|
||||
"package-ios-framework",
|
||||
rebase_path("$_framework_root", root_out_dir),
|
||||
]
|
||||
args = [ rebase_path("$_framework_root", root_out_dir) ]
|
||||
}
|
||||
|
||||
_copy_public_headers_target = _target_name + "_copy_public_headers"
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
# 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.
|
||||
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
def Main(args):
|
||||
if len(args) < 4:
|
||||
print >> sys.stderr, "Usage: %s output.hmap Foo.framework header1.h..." %\
|
||||
(args[0])
|
||||
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.items(), key=lambda (k,v):len(v))[1])
|
||||
|
||||
out = open(output_name, 'wb')
|
||||
out.write(struct.pack('<LHHLLLL', magic, version, _reserved, strings_offset,
|
||||
count, capacity, max_value_length))
|
||||
|
||||
# Create empty hashmap buckets.
|
||||
buckets = [None] * capacity
|
||||
for file, path in filelist.items():
|
||||
key = 0
|
||||
for c in file:
|
||||
key += ord(c.lower()) * 13
|
||||
|
||||
# Fill next empty bucket.
|
||||
while buckets[key & capacity - 1] is not None:
|
||||
key = key + 1
|
||||
buckets[key & capacity - 1] = (file, path)
|
||||
|
||||
next_offset = 1
|
||||
for bucket in buckets:
|
||||
if bucket is None:
|
||||
out.write(struct.pack('<LLL', 0, 0, 0))
|
||||
else:
|
||||
(file, path) = bucket
|
||||
key_offset = next_offset
|
||||
prefix_offset = key_offset + len(file) + 1
|
||||
suffix_offset = prefix_offset + len(os.path.dirname(path) + os.sep) + 1
|
||||
next_offset = suffix_offset + len(os.path.basename(path)) + 1
|
||||
out.write(struct.pack('<LLL', key_offset, prefix_offset, suffix_offset))
|
||||
|
||||
# Pad byte since next offset starts at 1.
|
||||
out.write(struct.pack('<x'))
|
||||
|
||||
for bucket in buckets:
|
||||
if bucket is not None:
|
||||
(file, path) = bucket
|
||||
out.write(struct.pack('<%ds' % len(file), file))
|
||||
out.write(struct.pack('<s', '\0'))
|
||||
base = os.path.dirname(path) + os.sep
|
||||
out.write(struct.pack('<%ds' % len(base), base))
|
||||
out.write(struct.pack('<s', '\0'))
|
||||
path = os.path.basename(path)
|
||||
out.write(struct.pack('<%ds' % len(path), path))
|
||||
out.write(struct.pack('<s', '\0'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(Main(sys.argv))
|
|
@ -0,0 +1,26 @@
|
|||
# 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.
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
def Main(framework):
|
||||
# Find the name of the binary based on the part before the ".framework".
|
||||
binary = os.path.basename(framework).split('.')[0]
|
||||
module_path = os.path.join(framework, 'Modules');
|
||||
if not os.path.exists(module_path):
|
||||
os.mkdir(module_path)
|
||||
module_template = 'framework module %s {\n' \
|
||||
' umbrella header "%s.h"\n' \
|
||||
'\n' \
|
||||
' export *\n' \
|
||||
' module * { export * }\n' \
|
||||
'}\n' % (binary, binary)
|
||||
|
||||
module_file = open(os.path.join(module_path, 'module.modulemap'), 'w')
|
||||
module_file.write(module_template)
|
||||
module_file.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
Main(sys.argv[1])
|
Загрузка…
Ссылка в новой задаче