mirror of
https://github.com/material-components/material-components-ios.git
synced 2026-02-20 08:27:32 +08:00
* Added VERSION, scripts/print_version, and updated docs. * Updating script. * Stop invoking `pod install` after the first time. * Remove unneeded `pod install` steps. * Added ref to print_version. * Updated instructions in contributing/releasing.md.
200 lines
5.6 KiB
Python
Executable File
200 lines
5.6 KiB
Python
Executable File
#!/usr/bin/python
|
|
#
|
|
# Copyright 2016-present the Material Components for iOS authors. All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
"""Sets version numbers and updates version-dependent metadata.
|
|
"""
|
|
|
|
from __future__ import print_function
|
|
|
|
import argparse
|
|
import manage_pods
|
|
import re
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
VERSION_FILE_NAME = "VERSION"
|
|
|
|
def find_podspecs(directory):
|
|
"""Return a list of *.podspec files on disk.
|
|
|
|
Args:
|
|
directory: Path to the directory to recursively search.
|
|
|
|
Returns:
|
|
A list of file paths.
|
|
"""
|
|
paths = []
|
|
for dirpath, unused_dirnames, filenames in os.walk(directory):
|
|
podspecs = [f for f in filenames if f.endswith('.podspec')]
|
|
paths += [os.path.join(dirpath, f) for f in podspecs]
|
|
|
|
return paths
|
|
|
|
|
|
def find_version_file(directory):
|
|
"""Return the source-of-truth version file.
|
|
|
|
Args:
|
|
directory: Path to the directory to examine for the file.
|
|
|
|
Returns:
|
|
A path to the version file.
|
|
"""
|
|
return os.path.join(directory, VERSION_FILE_NAME)
|
|
|
|
|
|
def update_podspec_contents(verbose_printer, contents, version):
|
|
"""Update the contents of a podspec with a new version.
|
|
|
|
Args:
|
|
verbose_printer: A printing function for verbose messages.
|
|
contents: The contents of a podspec as a string.
|
|
version: The new version.
|
|
|
|
Returns:
|
|
The updated contents string.
|
|
"""
|
|
# Strings like
|
|
# .version = "2.0.0"
|
|
# .version = "1.2.3.absc"
|
|
# .version="my dog has fleas"
|
|
contents = re.sub(r'\.version([\s]*)=([\s]*)"[^"]+"',
|
|
r'.version\1=\2"%s"' % version,
|
|
contents)
|
|
return contents
|
|
|
|
|
|
def set_version(verbose_printer, path, version):
|
|
"""Update the version file on disk with a new version.
|
|
|
|
Args:
|
|
verbose_printer: A printing function for verbose messages.
|
|
path: The path to the version file.
|
|
version: The new version.
|
|
"""
|
|
verbose_printer('Updating %s to version %s.' % (path, version))
|
|
|
|
try:
|
|
with open(path, 'w') as f:
|
|
f.write(version)
|
|
except:
|
|
print('Could not write version file "%s", aborting.' % path, file=sys.stderr)
|
|
raise
|
|
|
|
|
|
def update_podspec_file(verbose_printer, path, version):
|
|
"""Update a podspec file on disk with a new version.
|
|
|
|
Args:
|
|
verbose_printer: A printing function for verbose messages.
|
|
path: The path to the podspec file.
|
|
version: The new version.
|
|
"""
|
|
verbose_printer('Updating %s to version %s.' % (path, version))
|
|
|
|
try:
|
|
with open(path, 'r') as f:
|
|
contents = f.read();
|
|
except:
|
|
print('Could not read podspec "%s", aborting.' % path, file=sys.stderr)
|
|
raise
|
|
|
|
new_contents = update_podspec_contents(verbose_printer, contents, version)
|
|
|
|
try:
|
|
with open(path, 'w') as f:
|
|
f.write(new_contents)
|
|
except:
|
|
print('Could not write podspec "%s", aborting.' % path, file=sys.stderr)
|
|
raise
|
|
|
|
|
|
def create_argument_parser():
|
|
"""Create an ArgumentParser for this script.
|
|
|
|
Returns:
|
|
An ArgumentParser object.
|
|
"""
|
|
parser = argparse.ArgumentParser(description=('Sets version numbers and '
|
|
'updates version-dependent '
|
|
'metadata.'))
|
|
parser.add_argument('version', help='the new version number.')
|
|
|
|
parser.add_argument('--verbose', '-v', dest='verbose', action='store_true',
|
|
help='print more information about actions being taken.',
|
|
default=False)
|
|
|
|
parser.add_argument('--dir', dest='directory',
|
|
help='do all work in this directory.',
|
|
default='.')
|
|
|
|
parser.add_argument('--skip_pod_install', action='store_true',
|
|
help=('skip running `pod install` on all Podfiles.'),
|
|
default=False)
|
|
parser.add_argument('--fast_pod_install', action='store_true',
|
|
help=('skip updating the pod repos when running `pod '
|
|
'install`.'),
|
|
default=False)
|
|
return parser
|
|
|
|
|
|
def print_nothing(unused_message):
|
|
"""Prints nothing.
|
|
|
|
Args:
|
|
unused_message: A message to not print.
|
|
"""
|
|
pass
|
|
|
|
|
|
def main():
|
|
parser = create_argument_parser()
|
|
args = parser.parse_args()
|
|
|
|
# Set up print functions for messages to the user.
|
|
if args.verbose:
|
|
verbose_printer = lambda x: print(x, file=sys.stdout)
|
|
else:
|
|
verbose_printer = print_nothing
|
|
|
|
stderr_printer = lambda x: print(x, file=sys.stderr)
|
|
|
|
# Find the VERSION file.
|
|
version_file = find_version_file(args.directory)
|
|
if not version_file:
|
|
stderr_printer('Could not find "%s" in directory "%s", aborting.' %
|
|
(VERSION_FILE_NAME, args.directory))
|
|
sys.exit(-1)
|
|
|
|
# Set the official version.
|
|
set_version(verbose_printer, version_file, args.version)
|
|
|
|
# Find all podspecs files.
|
|
podspecs = find_podspecs(args.directory)
|
|
if not podspecs:
|
|
stderr_printer('Could not find any .podspec files starting from directory '
|
|
'"%s", aborting.' % args.directory)
|
|
sys.exit(-1)
|
|
|
|
# Update the version numbers in each podspec.
|
|
for p in podspecs:
|
|
update_podspec_file(verbose_printer, p, args.version)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|