3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
13 # Path to root FFmpeg directory. Used as the CWD for executing all commands.
14 FFMPEG_ROOT = os.path.abspath(os.path.join(
15 os.path.dirname(__file__), '..', '..'))
17 # Path to the C99 to C89 converter.
18 CONVERTER_EXECUTABLE = os.path.abspath(os.path.join(
19 FFMPEG_ROOT, 'chromium', 'binaries', 'c99conv.exe'))
21 # $CC to use. We use to support GOMA, but by switching to stdout preprocessing
22 # its twice as fast to just preprocess locally (compilation may still be GOMA).
25 # Disable spammy warning related to av_restrict, upstream needs to fix.
26 DISABLED_WARNINGS = ['-wd4005']
31 print 'C99 to C89 Converter Wrapper'
32 print ' usage: c99conv.py <input file> <output file> [-I <include> ...]'
35 input_file = os.path.abspath(sys.argv[1])
36 # Keep the preprocessed output file in the same directory so GOMA will work
37 # without complaining about unknown paths.
38 preprocessed_output_file = input_file + '_preprocessed.c'
39 output_file = os.path.abspath(sys.argv[2])
41 # Run the preprocessor command. All of these settings are pulled from the
42 # CFLAGS section of the "config.mak" created after running build_ffmpeg.sh.
44 # cl.exe is extremely inefficient (upwards of 30k writes) when asked to
45 # preprocess to file (-P) so instead ask for output to go to stdout (-E) and
46 # write it out ourselves afterward. See http://crbug.com/172368.
48 [DEFAULT_CC, '-E', '-nologo', '-DCOMPILING_avcodec=1',
49 '-DCOMPILING_avutil=1', '-DCOMPILING_avformat=1', '-D_USE_MATH_DEFINES',
50 '-Dinline=__inline', '-Dstrtoll=_strtoi64', '-U__STRICT_ANSI__',
51 '-D_ISOC99_SOURCE', '-D_LARGEFILE_SOURCE', '-DHAVE_AV_CONFIG_H',
52 '-Dstrtod=avpriv_strtod', '-Dsnprintf=avpriv_snprintf',
53 '-D_snprintf=avpriv_snprintf', '-Dvsnprintf=avpriv_vsnprintf',
57 ['-I', '.', '-I', FFMPEG_ROOT, '-I', 'chromium/config',
58 '-I', 'chromium/include/win', input_file],
59 cwd=FFMPEG_ROOT, stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
60 # universal_newlines ensures whitespace is correct for #line directives.
61 universal_newlines=True)
62 stdout, stderr = p.communicate()
64 # Abort if any error occurred.
67 if os.path.isfile(preprocessed_output_file):
68 os.unlink(preprocessed_output_file)
69 sys.exit(p.returncode)
71 with open(preprocessed_output_file, 'w') as f:
72 # Write out stdout but skip the filename print out that MSVC forces for
73 # every cl.exe execution as well as ridiculous amounts of white space; saves
74 # ~64mb of output over the entire conversion! Care must be taken while
75 # trimming whitespace to keep #line directives accurate or stack traces will
77 f.write(re.sub('\s+\n(#line|#pragma)', r'\n\1',
78 stdout[len(os.path.basename(input_file)):]))
80 # Run the converter command. Note: the input file must have a '.c' extension
81 # or the converter will crash. libclang does some funky detection based on
84 [CONVERTER_EXECUTABLE, preprocessed_output_file, output_file],
87 os.unlink(preprocessed_output_file)
88 sys.exit(p.returncode)
91 if __name__ == '__main__':