diff options
author | Cassidy Burden <cburden@google.com> | 2016-06-22 17:01:04 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-06-24 10:52:49 -0700 |
commit | 545b947888df1d07f4ad530e1c5eec930fc283c2 (patch) | |
tree | 14ef0fcac7830f13527caf3368668f48faa8fc23 /binary_search_tool/cros_pkg/create_cleanup_script.py | |
parent | 58f24cae7e6dfed8196d0b96713afaa42cd1fdde (diff) | |
download | toolchain-utils-545b947888df1d07f4ad530e1c5eec930fc283c2.tar.gz |
binary search tool: Move root path of cros_pkg execution, rename scripts
Update cros_pkg scripts and bisect.py so that the package bisector needs
to be run from binary_search_tool/ instead of
binary_search_tool/cros_pkg. This fits with how sysroot_wrapper
implements its scripts. Also rename all cros_pkg scripts to remove
cros_pkg prefix and remove undo_eclean.py.
TEST=Run unit tests and run interactive/testing cros_pkg test
Change-Id: I2781319934b704b91346745ae2d4d916fee35d02
Reviewed-on: https://chrome-internal-review.googlesource.com/266365
Commit-Ready: Cassidy Burden <cburden@google.com>
Tested-by: Cassidy Burden <cburden@google.com>
Reviewed-by: Caroline Tice <cmtice@google.com>
Diffstat (limited to 'binary_search_tool/cros_pkg/create_cleanup_script.py')
-rwxr-xr-x | binary_search_tool/cros_pkg/create_cleanup_script.py | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/binary_search_tool/cros_pkg/create_cleanup_script.py b/binary_search_tool/cros_pkg/create_cleanup_script.py new file mode 100755 index 00000000..45a90260 --- /dev/null +++ b/binary_search_tool/cros_pkg/create_cleanup_script.py @@ -0,0 +1,110 @@ +#!/usr/bin/python2 +# +# Copyright 2015 Google Inc. All Rights Reserved +"""The script to generate a cleanup script after setup.sh. + +This script takes a set of flags, telling it what setup.sh changed +during the set up process. Based on the values of the input flags, it +generates a cleanup script, named ${BOARD}_cleanup.sh, which will +undo the changes made by setup.sh, returning everything to its +original state. +""" + +from __future__ import print_function + +import argparse +import sys + + +def Usage(parser, msg): + print('ERROR: ' + msg) + parser.print_help() + sys.exit(1) + + +def Main(argv): + """Generate a script to undo changes done by setup.sh + + The script setup.sh makes a change that needs to be + undone, namely it creates a soft link making /build/${board} point + to /build/${board}.work. To do this, it had to see if + /build/${board} already existed, and if so, whether it was a real + tree or a soft link. If it was soft link, it saved the old value + of the link, then deleted it and created the new link. If it was + a real tree, it renamed the tree to /build/${board}.save, and then + created the new soft link. If the /build/${board} did not + previously exist, then it just created the new soft link. + + This function takes arguments that tell it exactly what setup.sh + actually did, then generates a script to undo those exact changes. + """ + + parser = argparse.ArgumentParser() + parser.add_argument('--board', + dest='board', + required=True, + help='Chromeos board for packages/image.') + + parser.add_argument('--old_tree_missing', + dest='tree_existed', + action='store_false', + help='Did /build/${BOARD} exist.', + default=True) + + parser.add_argument('--renamed_tree', + dest='renamed_tree', + action='store_true', + help='Was /build/${BOARD} saved & renamed.', + default=False) + + parser.add_argument('--old_link', + dest='old_link', + help=('The original build tree soft link.')) + + options = parser.parse_args(argv[1:]) + + if options.old_link or options.renamed_tree: + if not options.tree_existed: + Usage(parser, 'If --tree_existed is False, cannot have ' + '--renamed_tree or --old_link') + + if options.old_link and options.renamed_tree: + Usage(parser, '--old_link and --renamed_tree are incompatible options.') + + if options.tree_existed: + if not options.old_link and not options.renamed_tree: + Usage(parser, 'If --tree_existed is True, then must have either ' + '--old_link or --renamed_tree') + + out_filename = 'cros_pkg/' + options.board + '_cleanup.sh' + + with open(out_filename, 'w') as out_file: + out_file.write('#!/bin/bash\n\n') + # First, remove the 'new' soft link. + out_file.write('sudo rm /build/%s\n' % options.board) + if options.tree_existed: + if options.renamed_tree: + # Old build tree existed and was a real tree, so it got + # renamed. Move the renamed tree back to the original tree. + out_file.write('sudo mv /build/%s.save /build/%s\n' % + (options.board, options.board)) + else: + # Old tree existed and was already a soft link. Re-create the + # original soft link. + original_link = options.old_link + if original_link[0] == "'": + original_link = original_link[1:] + if original_link[-1] == "'": + original_link = original_link[:-1] + out_file.write('sudo ln -s %s /build/%s\n' % (original_link, + options.board)) + out_file.write('\n') + # Remove common.sh file + out_file.write('rm cros_pkg/common.sh\n') + + return 0 + + +if __name__ == '__main__': + retval = Main(sys.argv) + sys.exit(retval) |