Blame get_free_ffmpeg_source_files.py

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