summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authordalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-06 00:00:36 +0000
committerdalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-06 00:00:36 +0000
commit4bfa62a2df740e2dffd771604de821b003d4ba46 (patch)
tree188d52ba5f382f626a65a7c852f9c9d8cd7a115d /tools
parent2a625c1ff05e9dd4a2afab36f718475d2145b682 (diff)
downloadchromium_src-4bfa62a2df740e2dffd771604de821b003d4ba46.zip
chromium_src-4bfa62a2df740e2dffd771604de821b003d4ba46.tar.gz
chromium_src-4bfa62a2df740e2dffd771604de821b003d4ba46.tar.bz2
Add support for windows def generation from sigs.
Used to generate the export table for the MSVC build of ffmpeg. Necessary since we don't want to decorate all the ffmpeg methods we use with __declspec(dllexport) a la MEDIA_EXPORT. Doing things this way allows us to keep the security of having an explicit whitelist for ffmpeg symbols. BUG=39887 TEST=MSVC version of ffmpeg builds and runs. Unittests. Review URL: https://codereview.chromium.org/11027054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160524 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rwxr-xr-xtools/generate_stubs/generate_stubs.py63
1 files changed, 53 insertions, 10 deletions
diff --git a/tools/generate_stubs/generate_stubs.py b/tools/generate_stubs/generate_stubs.py
index 424d24f..1c97c25 100755
--- a/tools/generate_stubs/generate_stubs.py
+++ b/tools/generate_stubs/generate_stubs.py
@@ -78,6 +78,7 @@ INVALID_C_IDENT_CHARS = re.compile('[^_a-zA-Z0-9]')
# Constants defning the supported file types options.
FILE_TYPE_WIN = 'windows_lib'
FILE_TYPE_POSIX_STUB = 'posix_stubs'
+FILE_TYPE_WIN_DEF = 'windows_def'
# Template for generating a stub function definition. Includes a forward
# declaration marking the symbol as weak. This template takes the following
@@ -875,19 +876,21 @@ def CreateOptionParser():
'--intermediate_dir',
dest='intermediate_dir',
default=None,
- help='Locaiton of intermediate files.')
+ help=('Location of intermediate files. Ignored for %s type'
+ % FILE_TYPE_WIN_DEF))
parser.add_option('-t',
'--type',
dest='type',
default=None,
- help=('Type of file. Either "%s" or "%s"' %
- (FILE_TYPE_POSIX_STUB, FILE_TYPE_WIN)))
+ help=('Type of file. Valid types are "%s" or "%s" or "%s"' %
+ (FILE_TYPE_POSIX_STUB, FILE_TYPE_WIN,
+ FILE_TYPE_WIN_DEF)))
parser.add_option('-s',
'--stubfile_name',
dest='stubfile_name',
default=None,
- help=('Name of posix_stubs output file. Ignored for '
- '%s type.' % FILE_TYPE_WIN))
+ help=('Name of posix_stubs output file. Only valid with '
+ '%s type.' % FILE_TYPE_POSIX_STUB))
parser.add_option('-p',
'--path_from_source',
dest='path_from_source',
@@ -906,6 +909,13 @@ def CreateOptionParser():
help=('File to insert after the system includes in the '
'generated stub implemenation file. Ignored for '
'%s type.' % FILE_TYPE_WIN))
+ parser.add_option('-m',
+ '--module_name',
+ dest='module_name',
+ default=None,
+ help=('Name of output DLL or LIB for DEF creation using '
+ '%s type.' % FILE_TYPE_WIN_DEF))
+
return parser
@@ -925,15 +935,20 @@ def ParseOptions():
if options.out_dir is None:
parser.error('Output location not specified')
- if options.type not in [FILE_TYPE_WIN, FILE_TYPE_POSIX_STUB]:
- parser.error('Invalid output file type')
+ if (options.type not in
+ [FILE_TYPE_WIN, FILE_TYPE_POSIX_STUB, FILE_TYPE_WIN_DEF]):
+ parser.error('Invalid output file type: %s' % options.type)
if options.type == FILE_TYPE_POSIX_STUB:
if options.stubfile_name is None:
- parser.error('Output file name need for %s' % FILE_TYPE_POSIX_STUB)
+ parser.error('Output file name needed for %s' % FILE_TYPE_POSIX_STUB)
if options.path_from_source is None:
parser.error('Path from source needed for %s' % FILE_TYPE_POSIX_STUB)
+ if options.type == FILE_TYPE_WIN_DEF:
+ if options.module_name is None:
+ parser.error('Module name needed for %s' % FILE_TYPE_WIN_DEF)
+
return options, args
@@ -977,7 +992,7 @@ def CreateWindowsLibForSigFiles(sig_files, out_dir, intermediate_dir):
"""For each signature file, create a windows lib.
Args:
- sig_files: Array of Strings with the paths to each signature file.
+ sig_files: Array of strings with the paths to each signature file.
out_dir: String holding path to directory where the generated libs go.
intermediate_dir: String holding path to directory generated intermdiate
artifacts.
@@ -992,13 +1007,39 @@ def CreateWindowsLibForSigFiles(sig_files, out_dir, intermediate_dir):
infile.close()
+def CreateWindowsDefForSigFiles(sig_files, out_dir, module_name):
+ """For all signature files, create a single windows def file.
+
+ Args:
+ sig_files: Array of strings with the paths to each signature file.
+ out_dir: String holding path to directory where the generated def goes.
+ module_name: Name of the output DLL or LIB which will link in the def file.
+ """
+ signatures = []
+ for input_path in sig_files:
+ infile = open(input_path, 'r')
+ try:
+ signatures += ParseSignatures(infile)
+ finally:
+ infile.close()
+
+ def_file_path = os.path.join(
+ out_dir, os.path.splitext(os.path.basename(module_name))[0] + '.def')
+ outfile = open(def_file_path, 'w')
+
+ try:
+ WriteWindowsDefFile(module_name, signatures, outfile)
+ finally:
+ outfile.close()
+
+
def CreatePosixStubsForSigFiles(sig_files, stub_name, out_dir,
intermediate_dir, path_from_source,
extra_stub_header):
"""Create a posix stub library with a module for each signature file.
Args:
- sig_files: Array of Strings with the paths to each signature file.
+ sig_files: Array of strings with the paths to each signature file.
stub_name: String with the basename of the generated stub file.
out_dir: String holding path to directory for the .h files.
intermediate_dir: String holding path to directory for the .cc files.
@@ -1070,6 +1111,8 @@ def main():
CreatePosixStubsForSigFiles(args, options.stubfile_name, out_dir,
intermediate_dir, options.path_from_source,
options.extra_stub_header)
+ elif options.type == FILE_TYPE_WIN_DEF:
+ CreateWindowsDefForSigFiles(args, out_dir, options.module_name)
if __name__ == '__main__':