diff options
Diffstat (limited to 'chromium/third_party/ffmpeg/chromium/scripts/generate_gyp.py')
-rwxr-xr-x | chromium/third_party/ffmpeg/chromium/scripts/generate_gyp.py | 210 |
1 files changed, 165 insertions, 45 deletions
diff --git a/chromium/third_party/ffmpeg/chromium/scripts/generate_gyp.py b/chromium/third_party/ffmpeg/chromium/scripts/generate_gyp.py index e806c924c22..16cf8ec989c 100755 --- a/chromium/third_party/ffmpeg/chromium/scripts/generate_gyp.py +++ b/chromium/third_party/ffmpeg/chromium/scripts/generate_gyp.py @@ -67,15 +67,18 @@ import optparse import os import string -GYP_HEADER = """# Copyright (c) %d The Chromium Authors. All rights reserved. +COPYRIGHT = """# Copyright %d 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. # NOTE: this file is autogenerated by ffmpeg/chromium/scripts/generate_gyp.py +""" % (datetime.datetime.now().year) + +GYP_HEADER = """ { 'variables': { -""" % (datetime.datetime.now().year) +""" GYP_FOOTER = """ }, } @@ -99,16 +102,32 @@ GYP_CONDITIONAL_C_SOURCE_STANZA_BEGIN = """ 'c_sources': [ """ GYP_CONDITIONAL_ASM_SOURCE_STANZA_BEGIN = """ 'asm_sources': [ """ -GYP_CONDITIONAL_MSVC_OUTPUT_STANZA_BEGIN = """ 'converter_outputs': [ -""" GYP_CONDITIONAL_ITEM_STANZA_END = """ ], """ -GYP_HEADERS_STANZA_BEGIN = """ 'c_headers': [ +GN_HEADER = """import("//build/config/arm.gni") +import("ffmpeg_options.gni") + +# Declare empty versions of each variable for easier +=ing later. +ffmpeg_c_sources = [] +ffmpeg_gas_sources = [] +ffmpeg_yasm_sources = [] + +""" +GN_CONDITION_BEGIN = """if (%s) { +""" +GN_CONDITION_END = """} + """ -GYP_HEADERS_STANZA_END = """ ], # c_headers +GN_C_SOURCES_BEGIN = """ffmpeg_c_sources += [ """ -GYP_HEADERS_STANZA_ITEM = """ '%s', +GN_GAS_SOURCES_BEGIN = """ffmpeg_gas_sources += [ +""" +GN_YASM_SOURCES_BEGIN = """ffmpeg_yasm_sources += [ +""" +GN_SOURCE_ITEM = """ "%s", +""" +GN_SOURCE_END = """] """ # Controls GYP conditional stanza generation. @@ -133,6 +152,7 @@ def CleanObjectFiles(object_files): 'libavcodec/inverse.o', # Includes libavutil/inverse.c 'libavcodec/file_open.o', # Includes libavutil/file_open.c 'libavcodec/log2_tab.o', # Includes libavutil/log2_tab.c + 'libavformat/golomb_tab.o', # Includes libavcodec/golomb.c 'libavformat/log2_tab.o', # Includes libavutil/log2_tab.c 'libavformat/file_open.o', # Includes libavutil/file_open.c @@ -172,6 +192,14 @@ def IsAssemblyFile(f): _, ext = os.path.splitext(f) return ext in ['.S', '.asm'] +def IsGasFile(f): + _, ext = os.path.splitext(f) + return ext in ['.S'] + +def IsYasmFile(f): + _, ext = os.path.splitext(f) + return ext in ['.asm'] + def IsCFile(f): _, ext = os.path.splitext(f) return ext in ['.c'] @@ -387,17 +415,98 @@ class SourceSet(object): stanza += GYP_CONDITIONAL_STANZA_ITEM % (name) stanza += GYP_CONDITIONAL_ITEM_STANZA_END - # Write out all MSVC outputs. - msvc_outputs = filter(IsCFile, self.sources) - if msvc_outputs: - stanza += GYP_CONDITIONAL_MSVC_OUTPUT_STANZA_BEGIN - for name in msvc_outputs: - stanza += GYP_CONDITIONAL_STANZA_OUTPUT_ITEM % (name) - stanza += GYP_CONDITIONAL_ITEM_STANZA_END - stanza += GYP_CONDITIONAL_STANZA_END % (conditions) return ''.join(stanza) + def WriteGnStanza(self, fd): + """Generates a gyp conditional stanza representing this source set. + + TODO(scherkus): Having all this special case condition optimizing logic in + here feels a bit dirty, but hey it works. Perhaps refactor if it starts + getting out of hand. + + Args: + fd: File object to write the stanza into. + """ + + # Only build a non-trivial conditional if it's a subset of all supported + # architectures. targets. Arch conditions look like: + # (cpu_arch == "arm" || (cpu_arch == "arm" && arm_use_neon)) + arch_conditions = [] + if self.architectures != set(SUPPORTED_ARCHITECTURES + ['x64']): + for arch in self.architectures: + if arch == 'arm-neon': + arch_conditions.append('(cpu_arch == "arm" && arm_use_neon)') + else: + arch_conditions.append('cpu_arch == "%s"' % arch) + + # Only build a non-trivial conditional if it's a subset of all supported + # targets. Branding conditions look like: + # (ffmpeg_branding == "Chrome" || ffmpeg_branding == "ChromeOS") + branding_conditions = [] + if self.targets != set(SUPPORTED_TARGETS): + for branding in self.targets: + branding_conditions.append('ffmpeg_branding == "%s"' % branding) + + # Platform conditions look like: + # (os == "mac" || os == "linux") + platform_conditions = [] + if (self.platforms != set(SUPPORTED_PLATFORMS) and + self.platforms != set(['linux'])): + for platform in self.platforms: + platform_conditions.append('os == "%s"' % platform) + + # Remove 0-lengthed lists. + conditions = filter(None, [' || '.join(arch_conditions), + ' || '.join(branding_conditions), + ' || '.join(platform_conditions)]) + + # If there is more that one clause, wrap various conditions in parens + # before joining. + if len(conditions) > 1: + conditions = [ '(%s)' % x for x in conditions ] + + # Output a conditional wrapper around stanzas if necessary. + if conditions: + fd.write(GN_CONDITION_BEGIN % ' && '.join(conditions)) + def indent_write(s): + fd.write(' %s' % s) + else: + def indent_write(s): + fd.write(s) + + sources = sorted(n.replace('\\', '/') for n in self.sources) + + # Write out all C sources. + c_sources = filter(IsCFile, sources) + if c_sources: + indent_write(GN_C_SOURCES_BEGIN) + for name in c_sources: + indent_write(GN_SOURCE_ITEM % (name)) + indent_write(GN_SOURCE_END) + + # Write out all assembly sources. + gas_sources = filter(IsGasFile, sources) + if gas_sources: + indent_write(GN_GAS_SOURCES_BEGIN) + for name in gas_sources: + indent_write(GN_SOURCE_ITEM % (name)) + indent_write(GN_SOURCE_END) + + # Write out all assembly sources. + yasm_sources = filter(IsYasmFile, sources) + if yasm_sources: + indent_write(GN_YASM_SOURCES_BEGIN) + for name in yasm_sources: + indent_write(GN_SOURCE_ITEM % (name)) + indent_write(GN_SOURCE_END) + + # Close the conditional if necessary. + if conditions: + fd.write(GN_CONDITION_END) + else: + fd.write('\n') # Makeup the spacing for the remove conditional. + def CreatePairwiseDisjointSets(sets): """ Given a list of SourceSet objects, returns the pairwise disjoint sets. @@ -464,6 +573,13 @@ def ParseOptions(): metavar='DIR', help='Build root containing build.x64.linux, etc...') + parser.add_option('-g', + '--output_gn', + dest='output_gn', + action="store_true", + default=False, + help='Output a GN file instead of a gyp file.') + options, args = parser.parse_args() if not options.source_dir: @@ -478,6 +594,28 @@ def ParseOptions(): return options, args +def WriteGyp(fd, build_dir, disjoint_sets): + fd.write(COPYRIGHT) + fd.write(GYP_HEADER) + + # Generate conditional stanza for each disjoint source set. + fd.write(GYP_CONDITIONAL_BEGIN) + for s in disjoint_sets: + fd.write(s.GenerateGypStanza()) + fd.write(GYP_CONDITIONAL_END) + + fd.write(GYP_FOOTER) + + +def WriteGn(fd, build_dir, disjoint_sets): + fd.write(COPYRIGHT) + fd.write(GN_HEADER) + + # Generate conditional stanza for each disjoint source set. + for s in reversed(disjoint_sets): + s.WriteGnStanza(fd) + + def main(): options, args = ParseOptions() @@ -486,11 +624,6 @@ def main(): source_files = GetSourceFiles(source_dir) object_to_sources = GetObjectToSourceMapping(source_files) - # Open for writing. - output_name = os.path.join(options.source_dir, 'ffmpeg_generated.gypi') - fd = open(output_name, 'w') - fd.write(GYP_HEADER) - sets = [] for arch in SUPPORTED_ARCHITECTURES: @@ -514,31 +647,18 @@ def main(): sets.append(SourceSet(s, set(['x64']), set([target]), set([platform]))) - # Generate conditional stanza for each disjoint source set. - fd.write(GYP_CONDITIONAL_BEGIN) - for s in CreatePairwiseDisjointSets(sets): - fd.write(s.GenerateGypStanza()) - fd.write(GYP_CONDITIONAL_END) - - # Generate sorted list of .h files in source tree and write headers stanza. - header_files = [] - for root, dirnames, filenames in os.walk('.'): - # Strip './' and other cruft from path. - root = os.path.normpath(root) - # Only process headers in code we use. There should be no dependencies on - # headers from libraries we don't use. - if not root.startswith( - ('libavcodec', 'libavutil', 'libavformat', 'compat')): - continue - for fn in fnmatch.filter(filenames, '*.h'): - header_files.append(os.path.join(root,fn)) - fd.write(GYP_HEADERS_STANZA_BEGIN) - for header in sorted(header_files): - fd.write(GYP_HEADERS_STANZA_ITEM % header) - fd.write(GYP_HEADERS_STANZA_END) - - fd.write(GYP_FOOTER) - fd.close() + sets = CreatePairwiseDisjointSets(sets) + # Open for writing. + if options.output_gn: + outfile = 'ffmpeg_generated.gni' + else: + outfile = 'ffmpeg_generated.gypi' + output_name = os.path.join(options.source_dir, outfile) + with open(output_name, 'w') as fd: + if options.output_gn: + WriteGn(fd, options.build_dir, sets) + else: + WriteGyp(fd, options.build_dir, sets) if __name__ == '__main__': main() |