Skip to content

Commit

Permalink
Add support for windows def generation from sigs.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dalecurtis@google.com committed Oct 6, 2012
1 parent 2a625c1 commit 4bfa62a
Showing 1 changed file with 53 additions and 10 deletions.
63 changes: 53 additions & 10 deletions tools/generate_stubs/generate_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def __str__(self):
# 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
Expand Down Expand Up @@ -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',
Expand All @@ -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


Expand All @@ -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


Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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__':
Expand Down

0 comments on commit 4bfa62a

Please sign in to comment.