Linux: make it possible to undo changes made by replace_gyp_files.py

See https://groups.google.com/a/chromium.org/d/msg/chromium-packagers/X1Q6P60JZHM/uol7IsRv0-oJ
for more info.

BUG=none
R=maruel@chromium.org

Review URL: https://codereview.chromium.org/16121002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202616 0039d316-1c4b-4281-b951-d872f2087c98
parent 3d9f9260
......@@ -9,6 +9,7 @@ make the build use system libraries.
"""
import optparse
import os.path
import shutil
import sys
......@@ -44,16 +45,33 @@ def DoMain(argv):
source_tree_root = os.path.abspath(
os.path.join(my_dirname, '..', '..', '..'))
parser = optparse.OptionParser()
# Accept arguments in gyp command-line syntax, so that the caller can re-use
# command-line for this script and gyp.
parser.add_option('-D', dest='defines', action='append')
parser.add_option('--undo', action='store_true')
options, args = parser.parse_args(argv)
for flag, path in REPLACEMENTS.items():
# Accept arguments in gyp command-line syntax, and ignore other
# parameters, so that the caller can re-use command-line for this
# script and gyp.
if '-D%s=1' % flag not in argv:
if '%s=1' % flag not in options.defines:
continue
# Copy the gyp file from directory of this script to target path.
shutil.copyfile(os.path.join(my_dirname, os.path.basename(path)),
os.path.join(source_tree_root, path))
if options.undo:
# Restore original file, and also remove the backup.
# This is meant to restore the source tree to its original state.
os.rename(os.path.join(source_tree_root, path + '.orig'),
os.path.join(source_tree_root, path))
else:
# Create a backup copy for --undo.
shutil.copyfile(os.path.join(source_tree_root, path),
os.path.join(source_tree_root, path + '.orig'))
# Copy the gyp file from directory of this script to target path.
shutil.copyfile(os.path.join(my_dirname, os.path.basename(path)),
os.path.join(source_tree_root, path))
return 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment