Blame get_free_ffmpeg_source_files.py

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