diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /build/scripts/f2c.py | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'build/scripts/f2c.py')
-rw-r--r-- | build/scripts/f2c.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/build/scripts/f2c.py b/build/scripts/f2c.py new file mode 100644 index 00000000000..7021e1391f1 --- /dev/null +++ b/build/scripts/f2c.py @@ -0,0 +1,58 @@ +import sys +import subprocess +import argparse +import os + + +header = '''\ +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wmissing-braces" +#pragma GCC diagnostic ignored "-Wuninitialized" +#pragma GCC diagnostic ignored "-Wreturn-type" +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +''' + +footer = ''' +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif +''' + + +def mkdir_p(directory): + if not os.path.exists(directory): + os.makedirs(directory) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + + parser.add_argument('-t', '--tool') + parser.add_argument('-c', '--input') + parser.add_argument('-o', '--output') + + args = parser.parse_args() + tmpdir = args.output + '.f2c' + mkdir_p(tmpdir) + # should parse includes, really + p = subprocess.Popen( + [args.tool, '-w', '-R', '-a', '-I' + os.path.dirname(args.input), '-T' + tmpdir], + stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) + stdout, stderr = p.communicate(input=open(args.input).read()) + ret = p.wait() + + if ret: + print >>sys.stderr, 'f2c failed: %s, %s' % (stderr, ret) + sys.exit(ret) + + if 'Error' in stderr: + print >>sys.stderr, stderr + + with open(args.output, 'w') as f: + f.write(header) + f.write(stdout) + f.write(footer) |