def DoMain(argv):
    my_dirname = os.path.dirname(__file__)
    source_tree_root = os.path.abspath(os.path.join(my_dirname, '..', '..', '..'))
    parser = argparse.ArgumentParser()
    parser.add_argument('--system-libraries', nargs='*', default=[])
    parser.add_argument('--undo', action='store_true')
    args = parser.parse_args(argv)
    handled_libraries = set()
    for (lib, path) in REPLACEMENTS.items():
        if (lib not in args.system_libraries):
            continue
        handled_libraries.add(lib)
        if args.undo:
            os.rename(os.path.join(source_tree_root, (path + '.orig')), os.path.join(source_tree_root, path))
        else:
            shutil.copyfile(os.path.join(source_tree_root, path), os.path.join(source_tree_root, (path + '.orig')))
            shutil.copyfile(os.path.join(my_dirname, ('%s.gn' % lib)), os.path.join(source_tree_root, path))
    unhandled_libraries = (set(args.system_libraries) - handled_libraries)
    if unhandled_libraries:
        print(('Unrecognized system libraries requested: %s' % ', '.join(sorted(unhandled_libraries))), file=sys.stderr)
        return 1
    return 0
def DoMain(argv):
    my_dirname = os.path.dirname(__file__)
    source_tree_root = os.path.abspath(os.path.join(my_dirname, '..', '..', '..'))
    parser = argparse.ArgumentParser()
    parser.add_argument('--system-libraries', nargs='*', default=[])
    parser.add_argument('--undo', action='store_true')
    args = parser.parse_args(argv)
    handled_libraries = set()
    for (lib, path) in REPLACEMENTS.items():
        if (lib not in args.system_libraries):
            continue
        handled_libraries.add(lib)
        if args.undo:
            os.rename(os.path.join(source_tree_root, (path + '.orig')), os.path.join(source_tree_root, path))
        else:
            shutil.copyfile(os.path.join(source_tree_root, path), os.path.join(source_tree_root, (path + '.orig')))
            shutil.copyfile(os.path.join(my_dirname, ('%s.gn' % lib)), os.path.join(source_tree_root, path))
    unhandled_libraries = (set(args.system_libraries) - handled_libraries)
    if unhandled_libraries:
        print(('Unrecognized system libraries requested: %s' % ', '.join(sorted(unhandled_libraries))), file=sys.stderr)
        return 1
    return 0