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. ...@@ -9,6 +9,7 @@ make the build use system libraries.
""" """
import optparse
import os.path import os.path
import shutil import shutil
import sys import sys
...@@ -44,13 +45,30 @@ def DoMain(argv): ...@@ -44,13 +45,30 @@ def DoMain(argv):
source_tree_root = os.path.abspath( source_tree_root = os.path.abspath(
os.path.join(my_dirname, '..', '..', '..')) 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(): for flag, path in REPLACEMENTS.items():
# Accept arguments in gyp command-line syntax, and ignore other if '%s=1' % flag not in options.defines:
# parameters, so that the caller can re-use command-line for this
# script and gyp.
if '-D%s=1' % flag not in argv:
continue continue
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. # Copy the gyp file from directory of this script to target path.
shutil.copyfile(os.path.join(my_dirname, os.path.basename(path)), shutil.copyfile(os.path.join(my_dirname, os.path.basename(path)),
os.path.join(source_tree_root, path)) os.path.join(source_tree_root, path))
......
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