mirror of
https://github.com/postgres/postgres.git
synced 2026-02-16 00:57:52 -05:00
This removes all the various workarounds for avoiding compiler warnings with Flex 2.5.35. Several recent patches have added additional warnings that would either need to be fixed along the lines of the existing workarounds, or we decide to no longer care about this, which we do here. Flex 2.5.35 is extremely outdated, and you can't even download it anymore from any of the Flex project sites, so it's nearly impossible to support. After this, using Flex 2.5.35 will still work, but the generated code will produce numerous compiler warnings. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/1a204ccd-7ae6-478c-a431-407b5c48ccc6@eisentraut.org
72 lines
2.4 KiB
Python
Executable file
72 lines
2.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
#
|
|
# Wrapper around flex that:
|
|
# - ensures lex.backup is created in a private directory
|
|
# - can error out if lex.backup is created (--no-backup)
|
|
# - works around concurrency issues with win_flex.exe:
|
|
# https://github.com/lexxmark/winflexbison/issues/86
|
|
|
|
import argparse
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from os.path import abspath
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--flex', type=abspath, required=True)
|
|
parser.add_argument('--perl', type=abspath, required=True)
|
|
parser.add_argument('--builddir', type=abspath, required=True)
|
|
parser.add_argument('--srcdir', type=abspath, required=True)
|
|
parser.add_argument('--privatedir', type=abspath, required=True,
|
|
help='private directory for target')
|
|
|
|
parser.add_argument('-o', dest='output_file', type=abspath, required=True,
|
|
help='output file')
|
|
parser.add_argument('-i', dest='input_file', type=abspath, help='input file')
|
|
|
|
|
|
parser.add_argument('--no-backup', action='store_true',
|
|
help='whether no_backup is enabled or not')
|
|
|
|
parser.add_argument('flex_flags', nargs='*', help='flags passed on to flex')
|
|
|
|
args = parser.parse_args()
|
|
|
|
# Since 'lex.backup' is always named that and ninja uses the top level build
|
|
# directory as current directory for all commands, change directory to
|
|
# temporary directory to avoid conflicts between concurrent flex
|
|
# invocations. Only unreleased versions of flex have an argument to change
|
|
# lex.filename to be named differently.
|
|
if not os.path.isdir(args.privatedir):
|
|
os.mkdir(args.privatedir)
|
|
os.chdir(args.privatedir)
|
|
|
|
# win_flex.exe generates names in a racy way, sometimes leading to random
|
|
# "error deleting file" failures and sometimes to intermingled file
|
|
# contents. Set FLEX_TMP_DIR to the target private directory to avoid
|
|
# that. That environment variable isn't consulted on other platforms, so we
|
|
# don't even need to make this conditional.
|
|
env = {'FLEX_TMP_DIR': args.privatedir}
|
|
|
|
# build flex invocation
|
|
command = [args.flex, '-o', args.output_file]
|
|
if args.no_backup:
|
|
command += ['-b']
|
|
command += args.flex_flags
|
|
command += [args.input_file]
|
|
|
|
# create .c file from .l file
|
|
sp = subprocess.run(command, env=env)
|
|
if sp.returncode != 0:
|
|
sys.exit(sp.returncode)
|
|
|
|
# check lex.backup
|
|
if args.no_backup:
|
|
with open('lex.backup') as lex:
|
|
if len(lex.readlines()) != 1:
|
|
sys.exit('Scanner requires backup; see lex.backup.')
|
|
os.remove('lex.backup')
|
|
|
|
sys.exit(0)
|