Commit 6b121e47 authored by sdefresne's avatar sdefresne Committed by Commit bot

Add BUILD.gn rules to compile third_party/class-dump.

Add third_party/class-dump/BUILD.gn to build class-dump as a host tool as
part of the iOS build.

Create a template "class_dump" (in third_party/class-dump/class-dump.gni)
to simplify the execution of the class-dump tool on given framework. This
required converting testing/iossim/redirect-stdout.sh to a python script
as gn can only invokes python script.

TBR=rohitrao@chromium.org
BUG=594519

Review URL: https://codereview.chromium.org/1806523002

Cr-Commit-Position: refs/heads/master@{#381687}
parent 2461a73b
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
'variables': { 'variables': {
'mac_deployment_target': '10.9', 'mac_deployment_target': '10.9',
'mac_sdk_min': '10.9', 'mac_sdk_min': '10.9',
'class_dump_bin': '<(PRODUCT_DIR)/class-dump',
'class_dump_py': '<(DEPTH)/third_party/class-dump/class-dump.py',
}, },
'conditions': [ 'conditions': [
['OS!="ios" or "<(GENERATOR)"!="xcode" or "<(GENERATOR_FLAVOR)"=="ninja"', { ['OS!="ios" or "<(GENERATOR)"!="xcode" or "<(GENERATOR_FLAVOR)"=="ninja"', {
...@@ -33,65 +35,66 @@ ...@@ -33,65 +35,66 @@
], ],
'actions': [ 'actions': [
{ {
'action_name': 'generate_dvt_foundation_header', 'action_name': 'generate_dvt_core_simulator',
'inputs': [ 'inputs': [
'<(iphone_sim_path)/DVTFoundation.framework/Versions/Current/DVTFoundation', '<(class_dump_bin)',
'<(PRODUCT_DIR)/class-dump', '<(class_dump_py)',
'<(developer_dir)/Library/PrivateFrameworks/CoreSimulator.framework/Versions/Current/CoreSimulator',
], ],
'outputs': [ 'outputs': [
'<(INTERMEDIATE_DIR)/iossim/DVTFoundation.h' '<(INTERMEDIATE_DIR)/iossim/CoreSimulator.h'
], ],
'action': [ 'action': [
# Actions don't provide a way to redirect stdout, so a custom 'python',
# script is invoked that will execute the first argument and '<(class_dump_py)',
# write the output to the file specified as the second argument. '-t', '<(class_dump_bin)',
# -I sorts classes, categories, and protocols by inheritance. '-o', '<(INTERMEDIATE_DIR)/iossim/CoreSimulator.h',
# -C <regex> only displays classes matching regular expression. '--',
'./redirect-stdout.sh', '-CSim',
'<(PRODUCT_DIR)/class-dump -CDVTStackBacktrace|DVTInvalidation|DVTMixIn <(iphone_sim_path)/DVTFoundation.framework', '<(developer_dir)/Library/PrivateFrameworks/CoreSimulator.framework',
'<(INTERMEDIATE_DIR)/iossim/DVTFoundation.h',
], ],
'message': 'Generating DVTFoundation.h', 'message': 'Generating CoreSimulator.h',
}, },
{ {
'action_name': 'generate_dvt_core_simulator', 'action_name': 'generate_dvt_foundation_header',
'inputs': [ 'inputs': [
'<(developer_dir)/Library/PrivateFrameworks/CoreSimulator.framework/Versions/Current/CoreSimulator', '<(class_dump_bin)',
'<(PRODUCT_DIR)/class-dump', '<(class_dump_py)',
'<(iphone_sim_path)/DVTFoundation.framework/Versions/Current/DVTFoundation',
], ],
'outputs': [ 'outputs': [
'<(INTERMEDIATE_DIR)/iossim/CoreSimulator.h' '<(INTERMEDIATE_DIR)/iossim/DVTFoundation.h'
], ],
'action': [ 'action': [
# Actions don't provide a way to redirect stdout, so a custom 'python',
# script is invoked that will execute the first argument and '<(class_dump_py)',
# write the output to the file specified as the second argument. '-t', '<(class_dump_bin)',
# -I sorts classes, categories, and protocols by inheritance. '-o', '<(INTERMEDIATE_DIR)/iossim/DVTFoundation.h',
# -C <regex> only displays classes matching regular expression. '--',
'./redirect-stdout.sh', '-CDVTStackBacktrace|DVTInvalidation|DVTMixIn',
'<(PRODUCT_DIR)/class-dump -CSim <(developer_dir)/Library/PrivateFrameworks/CoreSimulator.framework', '<(iphone_sim_path)/DVTFoundation.framework',
'<(INTERMEDIATE_DIR)/iossim/CoreSimulator.h',
], ],
'message': 'Generating CoreSimulator.h', 'message': 'Generating DVTFoundation.h',
}, },
{ {
'action_name': 'generate_dvt_iphone_sim_header', 'action_name': 'generate_dvt_iphone_sim_header',
'inputs': [ 'inputs': [
'<(class_dump_bin)',
'<(class_dump_py)',
'<(iphone_sim_path)/DVTiPhoneSimulatorRemoteClient.framework/Versions/Current/DVTiPhoneSimulatorRemoteClient', '<(iphone_sim_path)/DVTiPhoneSimulatorRemoteClient.framework/Versions/Current/DVTiPhoneSimulatorRemoteClient',
'<(PRODUCT_DIR)/class-dump',
], ],
'outputs': [ 'outputs': [
'<(INTERMEDIATE_DIR)/iossim/DVTiPhoneSimulatorRemoteClient.h' '<(INTERMEDIATE_DIR)/iossim/DVTiPhoneSimulatorRemoteClient.h'
], ],
'action': [ 'action': [
# Actions don't provide a way to redirect stdout, so a custom 'python',
# script is invoked that will execute the first argument and '<(class_dump_py)',
# write the output to the file specified as the second argument. '-t', '<(class_dump_bin)',
# -I sorts classes, categories, and protocols by inheritance. '-o', '<(INTERMEDIATE_DIR)/iossim/DVTiPhoneSimulatorRemoteClient.h',
# -C <regex> only displays classes matching regular expression. '--',
'./redirect-stdout.sh', '-I',
'<(PRODUCT_DIR)/class-dump -I -CiPhoneSimulator <(iphone_sim_path)/DVTiPhoneSimulatorRemoteClient.framework', '-CiPhoneSimulator',
'<(INTERMEDIATE_DIR)/iossim/DVTiPhoneSimulatorRemoteClient.h', '<(iphone_sim_path)/DVTiPhoneSimulatorRemoteClient.framework',
], ],
'message': 'Generating DVTiPhoneSimulatorRemoteClient.h', 'message': 'Generating DVTiPhoneSimulatorRemoteClient.h',
}, },
......
#!/bin/sh
# Copyright (c) 2012 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.
#
# This script executes the command given as the first argument, strips
# cxx_destruct from stdout, and redirects the remaining stdout to the file given
# as the second argument.
#
# Example: Write the text 'foo' to a file called out.txt:
# RedirectStdout.sh "echo foo" out.txt
#
# This script is invoked from iossim.gyp in order to redirect the output of
# class-dump to a file (because gyp actions don't support redirecting output).
# This script also removes all lines with cxx_destruct. Perhaps newer versions
# of class-dump will fix this issue. As of 3.5, 'cxx_destruct' still exists.
if [ ${#} -ne 2 ] ; then
echo "usage: ${0} <command> <output file>"
exit 2
fi
echo "// Treat class-dump output as a system header." > $2
echo "#pragma clang system_header" >> $2
$1 | sed /cxx_destruct/d >> $2
# 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.
config("config") {
visibility = [ ":class-dump" ]
libs = [
"Foundation.framework",
"crypto",
]
# TODO(crbug.com/595295): Building class-dump tools requires OS X SDK
# version 10.9 or higher. Remove this override once the global version
# of the SDK is raised.
common_flags = [ "-mmacosx-version-min=10.9" ]
ldflags = common_flags
cflags_objc = common_flags
cflags_objc += [
"-Wno-semicolon-before-method-body",
"-Wno-unused-function",
]
precompiled_header = "src/class-dump-Prefix.pch"
precompiled_source = "src/class-dump-Prefix.pch"
}
executable("class-dump") {
include_dirs = [ "src/Source" ]
sources = [
"src/Source/CDBalanceFormatter.h",
"src/Source/CDBalanceFormatter.m",
"src/Source/CDClassDump.h",
"src/Source/CDClassDump.m",
"src/Source/CDClassDumpVisitor.h",
"src/Source/CDClassDumpVisitor.m",
"src/Source/CDClassFrameworkVisitor.h",
"src/Source/CDClassFrameworkVisitor.m",
"src/Source/CDDataCursor.h",
"src/Source/CDDataCursor.m",
"src/Source/CDExtensions.h",
"src/Source/CDFatArch.h",
"src/Source/CDFatArch.m",
"src/Source/CDFatFile.h",
"src/Source/CDFatFile.m",
"src/Source/CDFile.h",
"src/Source/CDFile.m",
"src/Source/CDFindMethodVisitor.h",
"src/Source/CDFindMethodVisitor.m",
"src/Source/CDLCDataInCode.h",
"src/Source/CDLCDataInCode.m",
"src/Source/CDLCDyldInfo.h",
"src/Source/CDLCDyldInfo.m",
"src/Source/CDLCDylib.h",
"src/Source/CDLCDylib.m",
"src/Source/CDLCDylinker.h",
"src/Source/CDLCDylinker.m",
"src/Source/CDLCDynamicSymbolTable.h",
"src/Source/CDLCDynamicSymbolTable.m",
"src/Source/CDLCEncryptionInfo.h",
"src/Source/CDLCEncryptionInfo.m",
"src/Source/CDLCFunctionStarts.h",
"src/Source/CDLCFunctionStarts.m",
"src/Source/CDLCLinkeditData.h",
"src/Source/CDLCLinkeditData.m",
"src/Source/CDLCMain.h",
"src/Source/CDLCMain.m",
"src/Source/CDLCPrebindChecksum.h",
"src/Source/CDLCPrebindChecksum.m",
"src/Source/CDLCPreboundDylib.h",
"src/Source/CDLCPreboundDylib.m",
"src/Source/CDLCRoutines32.h",
"src/Source/CDLCRoutines32.m",
"src/Source/CDLCRoutines64.h",
"src/Source/CDLCRoutines64.m",
"src/Source/CDLCRunPath.h",
"src/Source/CDLCRunPath.m",
"src/Source/CDLCSegment.h",
"src/Source/CDLCSegment.m",
"src/Source/CDLCSourceVersion.h",
"src/Source/CDLCSourceVersion.m",
"src/Source/CDLCSubClient.h",
"src/Source/CDLCSubClient.m",
"src/Source/CDLCSubFramework.h",
"src/Source/CDLCSubFramework.m",
"src/Source/CDLCSubLibrary.h",
"src/Source/CDLCSubLibrary.m",
"src/Source/CDLCSubUmbrella.h",
"src/Source/CDLCSubUmbrella.m",
"src/Source/CDLCSymbolTable.h",
"src/Source/CDLCSymbolTable.m",
"src/Source/CDLCTwoLevelHints.h",
"src/Source/CDLCTwoLevelHints.m",
"src/Source/CDLCUUID.h",
"src/Source/CDLCUUID.m",
"src/Source/CDLCUnixThread.h",
"src/Source/CDLCUnixThread.m",
"src/Source/CDLCUnknown.h",
"src/Source/CDLCUnknown.m",
"src/Source/CDLCVersionMinimum.h",
"src/Source/CDLCVersionMinimum.m",
"src/Source/CDLoadCommand.h",
"src/Source/CDLoadCommand.m",
"src/Source/CDMachOFile.h",
"src/Source/CDMachOFile.m",
"src/Source/CDMachOFileDataCursor.h",
"src/Source/CDMachOFileDataCursor.m",
"src/Source/CDMethodType.h",
"src/Source/CDMethodType.m",
"src/Source/CDMultiFileVisitor.h",
"src/Source/CDMultiFileVisitor.m",
"src/Source/CDOCCategory.h",
"src/Source/CDOCCategory.m",
"src/Source/CDOCClass.h",
"src/Source/CDOCClass.m",
"src/Source/CDOCClassReference.h",
"src/Source/CDOCClassReference.m",
"src/Source/CDOCInstanceVariable.h",
"src/Source/CDOCInstanceVariable.m",
"src/Source/CDOCMethod.h",
"src/Source/CDOCMethod.m",
"src/Source/CDOCModule.h",
"src/Source/CDOCModule.m",
"src/Source/CDOCProperty.h",
"src/Source/CDOCProperty.m",
"src/Source/CDOCProtocol.h",
"src/Source/CDOCProtocol.m",
"src/Source/CDOCSymtab.h",
"src/Source/CDOCSymtab.m",
"src/Source/CDObjectiveC1Processor.h",
"src/Source/CDObjectiveC1Processor.m",
"src/Source/CDObjectiveC2Processor.h",
"src/Source/CDObjectiveC2Processor.m",
"src/Source/CDObjectiveCProcessor.h",
"src/Source/CDObjectiveCProcessor.m",
"src/Source/CDProtocolUniquer.h",
"src/Source/CDProtocolUniquer.m",
"src/Source/CDRelocationInfo.h",
"src/Source/CDRelocationInfo.m",
"src/Source/CDSearchPathState.h",
"src/Source/CDSearchPathState.m",
"src/Source/CDSection.h",
"src/Source/CDSection.m",
"src/Source/CDStructureInfo.h",
"src/Source/CDStructureInfo.m",
"src/Source/CDStructureTable.h",
"src/Source/CDStructureTable.m",
"src/Source/CDSymbol.h",
"src/Source/CDSymbol.m",
"src/Source/CDTextClassDumpVisitor.h",
"src/Source/CDTextClassDumpVisitor.m",
"src/Source/CDTopoSortNode.h",
"src/Source/CDTopoSortNode.m",
"src/Source/CDTopologicalSortProtocol.h",
"src/Source/CDType.h",
"src/Source/CDType.m",
"src/Source/CDTypeController.h",
"src/Source/CDTypeController.m",
"src/Source/CDTypeFormatter.h",
"src/Source/CDTypeFormatter.m",
"src/Source/CDTypeLexer.h",
"src/Source/CDTypeLexer.m",
"src/Source/CDTypeName.h",
"src/Source/CDTypeName.m",
"src/Source/CDTypeParser.h",
"src/Source/CDTypeParser.m",
"src/Source/CDVisitor.h",
"src/Source/CDVisitor.m",
"src/Source/CDVisitorPropertyState.h",
"src/Source/CDVisitorPropertyState.m",
"src/Source/NSArray-CDExtensions.h",
"src/Source/NSArray-CDExtensions.m",
"src/Source/NSData-CDExtensions.h",
"src/Source/NSData-CDExtensions.m",
"src/Source/NSError-CDExtensions.h",
"src/Source/NSError-CDExtensions.m",
"src/Source/NSScanner-CDExtensions.h",
"src/Source/NSScanner-CDExtensions.m",
"src/Source/NSString-CDExtensions.h",
"src/Source/NSString-CDExtensions.m",
"src/Source/ULEB128.h",
"src/Source/ULEB128.m",
"src/Source/cd_objc2.h",
"src/class-dump.m",
]
configs += [
":config",
"//build/config/compiler:enable_arc",
"//build/config/compiler:no_chromium_code",
]
# TODO(crbug.com/595295): Building class-dump tools requires OS X SDK
# version 10.9 or higher. To prevent mixing code using different value
# of minimum SDK supported, forbids dependencies on any Chromium target.
assert_no_deps = [ "//base/*" ]
}
# 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.
# Given a framework, generates a header file declaring the classes from that
# framework using class-dump tool.
#
# Arguments:
#
# framework_name
# string, short name of the framework.
#
# framework_path
# string, location of the framework, usually a sub-directory of
# Xcode application bundle.
#
# framework_version
# (optional) string, version of the framework to dump class for,
# defaults to "Current" if omitted.
#
# class_dump_filter
# regexp, only display classes matching this regular expression.
#
# topological_sort
# (optional) boolean, sort classes, categories, and protocols by
# inheritance, defaults to false if omitted.
#
# All common target arugments ("visibility", "deps", ...) are forwarded by
# the template.
template("class_dump") {
assert(defined(invoker.framework_name),
"framework_name must be defined for $target_name")
assert(defined(invoker.framework_path),
"framework_path must be defined for $target_name")
assert(defined(invoker.class_dump_filter),
"class_dump_filter must be defined for $target_name")
framework_version = "Current"
if (defined(invoker.framework_version)) {
framework_version = invoker.framework_version
}
sort_args = []
if (defined(invoker.topological_sort) && invoker.topological_sort) {
sort_args = [ "-I" ]
}
class_dump = "//third_party/class-dump(${host_toolchain})"
class_dump_bin = get_label_info(class_dump, "root_out_dir") + "/class-dump"
framework = "${invoker.framework_path}/${invoker.framework_name}.framework"
_config_name = target_name + "_config"
config(_config_name) {
visibility = [ ":$target_name" ]
include_dirs = [ "$target_gen_dir" ]
}
action(target_name) {
forward_variables_from(invoker,
"*",
[
"args",
"class_dump_filter",
"framework_name",
"framework_path",
"framework_version",
"script",
"sources",
])
if (!defined(deps)) {
deps = []
}
deps += [ class_dump ]
public_configs = [ ":$_config_name" ]
script = "//third_party/class-dump/class-dump.py"
inputs = [
class_dump_bin,
]
sources = [
"${framework}/Versions/${framework_version}/${invoker.framework_name}",
]
outputs = [
"$target_gen_dir/${invoker.framework_name}.h",
]
args = [
"-t=" + rebase_path(class_dump_bin, root_build_dir),
"-o=" + rebase_path(outputs[0], root_build_dir),
"--",
"-C${invoker.class_dump_filter}",
"${framework}",
]
args += sort_args
}
}
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
}, },
'targets': [ 'targets': [
{ {
# GN version //third_party/class-dump(//build/toolchain/mac:clang_x64)
'target_name': 'class-dump', 'target_name': 'class-dump',
'toolsets': ['host'], 'toolsets': ['host'],
'type': 'executable', 'type': 'executable',
......
# 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.
# Wrapper around class-dump to allow gn build to run the tool (as action
# target can only run python scripts). Also filters the output to remove
# all cxx_destruct lines that are not understood from class-dump output.
import argparse
import errno
import os
import subprocess
import sys
def Main(args):
parser = argparse.ArgumentParser('wrapper around class-dump')
parser.add_argument(
'-o', '--output', required=True,
help='name of the output file')
parser.add_argument(
'-t', '--class-dump-path', required=True,
help='path to class-dump executable')
parser.add_argument(
'args', nargs='*',
help='arguments to pass to class-dump')
args = parser.parse_args(args)
try:
os.makedirs(os.path.dirname(args.output))
except OSError, e:
if e.errno != errno.EEXIST:
raise
process = subprocess.Popen(
[args.class_dump_path] + args.args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
if process.returncode != 0:
sys.stderr.write(stderr)
sys.exit(process.returncode)
with open(args.output, 'wb') as output:
output.write("// Treat class-dump output as a system header.\n")
output.write("#pragma clang system_header\n")
for line in stdout.splitlines():
if 'cxx_destruct' in line:
continue
output.write(line)
output.write('\n')
if __name__ == '__main__':
Main(sys.argv[1:])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment