Skip to content

Instantly share code, notes, and snippets.

@plammens
Last active May 18, 2019 10:08
Show Gist options
  • Save plammens/dcd6d4b4a8c3a0f0d49318dead520fbe to your computer and use it in GitHub Desktop.
Save plammens/dcd6d4b4a8c3a0f0d49318dead520fbe to your computer and use it in GitHub Desktop.
Quick throwaway script for temporarily fixing https://github.com/pngwriter/pngwriter/issues/136
import glob
import re
pattern = re.compile(r"-D(?= *-D)")
for filename in glob.glob("CMakeFiles/*.dir/flags.make"):
print("Inspecting '{}'. ".format(filename), end='')
with open(filename, 'r') as file:
lines = file.readlines()
assert "CXX_DEFINES" in lines[6]
found_problems: bool = bool(re.search(pattern, lines[6]))
if found_problems:
print("Editing... ", end='')
lines[6] = re.sub(r"-D(?= *-D)", "", lines[6])
with open(filename, 'w') as file:
file.writelines(lines)
print("Done.")
else:
print("No problems found. ", end='')
print("\nAll done. Try `make install` again.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment