ac2ca1dbba
The brp-llvm-compile-lto-elf script uses PCRE in grep to match for the -flto flag in bitcode object dumps, using negative lookahead to exclude the case where -fno-lto is specified after. When lines in the bitcode dump exceed the length that PCRE can match against, grep will error out causing brp-llvm-compile-lto-elf to fail. This script implements an equivalent regex match in python to avoid the limit in PCRE grep. Resolves: rhbz#2017193
40 lines
846 B
Python
Executable File
40 lines
846 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
# Check an llvm bcanalyzer dump for -flto
|
|
|
|
# This script implements the following command in python
|
|
# to avoid PCRE backtrace limits in grep.
|
|
# grep -xP '.*\-flto((?!-fno-lto).)*' <input file>
|
|
|
|
import re
|
|
import sys
|
|
|
|
def open_input_file():
|
|
if len(sys.argv) > 1:
|
|
f = open(sys.argv[1], "r")
|
|
else:
|
|
f = sys.stdin
|
|
if not f:
|
|
raise Exception("Could not open input file")
|
|
return f
|
|
|
|
def match_lto(input_lines):
|
|
match_found = False
|
|
for line in input_lines:
|
|
match = re.match(r"^.*\-flto((?!-fno-lto).)*$", line)
|
|
if match:
|
|
match_found = True
|
|
print(f"{match.group(0)}")
|
|
return match_found
|
|
|
|
def main():
|
|
input_file = open_input_file()
|
|
input_lines = input_file.readlines()
|
|
if input_file != sys.stdin:
|
|
input_file.close()
|
|
if match_lto(input_lines):
|
|
sys.exit(0)
|
|
sys.exit(1)
|
|
|
|
main()
|