Blame get_free_ffmpeg_source_files.py

Kevin Kofler 778be1
#!/usr/bin/python
Kevin Kofler 778be1
# Copyright 2015 Tomas Popela <tpopela@redhat.com>
Kevin Kofler 778be1
# Permission is hereby granted, free of charge, to any person obtaining
Kevin Kofler 778be1
# a copy of this software and associated documentation files (the
Kevin Kofler 778be1
# "Software"), to deal in the Software without restriction, including
Kevin Kofler 778be1
# without limitation the rights to use, copy, modify, merge, publish,
Kevin Kofler 778be1
# distribute, sublicense, and/or sell copies of the Software, and to
Kevin Kofler 778be1
# permit persons to whom the Software is furnished to do so, subject to
Kevin Kofler 778be1
# the following conditions:
Kevin Kofler 778be1
#
Kevin Kofler 778be1
# The above copyright notice and this permission notice shall be included
Kevin Kofler 778be1
# in all copies or substantial portions of the Software.
Kevin Kofler 778be1
#
Kevin Kofler 778be1
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Kevin Kofler 778be1
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Kevin Kofler 778be1
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Kevin Kofler 778be1
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
Kevin Kofler 778be1
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
Kevin Kofler 778be1
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
Kevin Kofler 778be1
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Kevin Kofler 778be1
Kevin Kofler 778be1
import sys
Kevin Kofler 778be1
import re
Kevin Kofler 778be1
Kevin Kofler 778be1
def append_sources (input_sources, output_sources):
Kevin Kofler 778be1
Kevin Kofler 778be1
  # Get the source files.
Kevin Kofler 778be1
  source_files = re.findall(r"\"(.*?)\"", input_sources)
Kevin Kofler 778be1
  output_sources += source_files
Kevin Kofler 778be1
Kevin Kofler 778be1
Kevin Kofler 778be1
def parse_sources(input_sources, output_sources, arch_not_arm):
Kevin Kofler 778be1
Kevin Kofler 778be1
  # Get the type of sources in one group and sources itself in the other one.
Kevin Kofler 778be1
  blocks = re.findall(r"(ffmpeg[^\s]*).*?\[(.*?)]", input_sources, re.DOTALL)
Kevin Kofler 778be1
  for block in blocks:
Kevin Kofler 778be1
    if (arch_not_arm):
Kevin Kofler 778be1
      if not 'ffmpeg_gas_sources' in block[0]:
Kevin Kofler 778be1
        append_sources (block[1], output_sources)
Kevin Kofler 778be1
    else:
Kevin Kofler 778be1
      append_sources (block[1], output_sources)
Kevin Kofler 778be1
Kevin Kofler 778be1
Kevin Kofler 778be1
def parse_ffmpeg_gyni_file(gyni_path, arch_not_arm):
Kevin Kofler 778be1
Kevin Kofler 778be1
  with open(gyni_path, "r") as input_file:
Kevin Kofler 778be1
    content = input_file.read().replace('\n', '')
Kevin Kofler 778be1
Kevin Kofler 778be1
  output_sources = []
Kevin Kofler 778be1
  # Get all the sections.
Kevin Kofler 778be1
  sections = re.findall(r"if (.*?})", content, re.DOTALL)
Kevin Kofler 778be1
  for section in sections:
Kevin Kofler be68fd
    # Get all the conditions (first group) and sources (second group) for the
Kevin Kofler 778be1
    # current section.
Kevin Kofler 778be1
    blocks = re.findall(r"(\(.*?\))\s\{(.*?)\}", section, re.DOTALL)
Kevin Kofler 778be1
    for block in blocks:
Kevin Kofler 778be1
      conditions = re.findall(r"\(?\((.*?)\)", block[0])
Kevin Kofler be68fd
      inserted = False
Kevin Kofler 778be1
      for condition in conditions:
Kevin Kofler be68fd
        if inserted:
Kevin Kofler be68fd
          break
Kevin Kofler be68fd
        limitations = ['ffmpeg_branding == "Chrome"', 'ffmpeg_branding == "ChromeOS"']
Kevin Kofler be68fd
        if ('is_linux' in condition) and not any(limitation in condition for limitation in limitations):
Kevin Kofler 778be1
          if (arch_not_arm):
Kevin Kofler 778be1
            if ('x64' in condition) or ('x86' in condition):
Kevin Kofler 778be1
              parse_sources (block[1], output_sources, arch_not_arm)
Kevin Kofler be68fd
              inserted = True
Kevin Kofler 778be1
          else:
Kevin Kofler 778be1
            parse_sources (block[1], output_sources, arch_not_arm)
Kevin Kofler be68fd
            inserted = True
Kevin Kofler 778be1
Kevin Kofler 778be1
  print ' '.join(output_sources)
Kevin Kofler 778be1
Kevin Kofler 778be1
Kevin Kofler 778be1
if __name__ == "__main__":
Kevin Kofler 778be1
Kevin Kofler 778be1
  path = "%s/third_party/ffmpeg/ffmpeg_generated.gni" % sys.argv[1]
Kevin Kofler 778be1
  parse_ffmpeg_gyni_file (path, False if sys.argv[2] == "0" else True)