blob: cdcd9bc3f1587dd34b339685a481a66e8cee5c2f [file]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2015 WebAssembly Community Group participants
#
# 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.
import argparse
import os
import subprocess
import sys
script_dir = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.dirname(script_dir)
top_comment = '''\
#
# IMPORTANT: This file is a copy the DEPS file that exists in order to trigger
# the release builds to produce an official LTO build to be part of a release.
# Each time this file changes the builders will produce an LTO SDK build.
#
# IMPORTANT: This file is (mostly) updated by running the
# src/create_release_candidate.py script which will overwrite with a copy of the
# DEPS file from a particular point in time. See src/create_release_candidate.py
# for more on this.
'''
def run(cmd, capture_output=False):
try:
return subprocess.run(cmd, cwd=root_dir, capture_output=capture_output,
text=True, check=True).stdout
except subprocess.CalledProcessError as e:
print('Command failed: ' + ' '.join(cmd))
print(e.stdout)
print(e.stderr)
raise e
def modify_deps_file(content):
# Insert `top_comment` after the initial copyright comment
pos = content.find('\n\n')
assert pos != -1
pos += 1
return content[:pos] + top_comment + content[pos:]
def create_cl(source_rev, tag, dry_run):
if run(['git', 'status', '--porcelain', '--untracked-files=no']):
print('tree is not clean')
return 1
# Copy DEPS from source_rev to DEPS.tagged_release
deps = run(['git', 'show', f'{source_rev}:DEPS'], capture_output=True)
deps = modify_deps_file(deps)
with open(os.path.join(root_dir, 'DEPS.tagged-release'), 'w') as f:
f.write(deps)
if dry_run:
return
# Create a new git branch
branch_name = f'version_{tag}_rc'
run(['git', 'checkout', '-b', branch_name])
run(['git', 'add', '-u', 'DEPS.tagged-release'])
message = f'Version {tag} RC\n\nDEPS from revision {source_rev}\n'
message += 'This CL was created by src/create_release_candidate.py'
run(['git', 'commit', '-m', message])
reviewers = 'dschuff@chromium.org,sbc@chromium.org,azakai@google.com'
run(['git', 'cl', 'upload', '--send-mail', '-r', reviewers])
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument('-r', '--revision', help='git revision to use for release')
parser.add_argument('-n', '--dry-run', action='store_true', help='update DEPS.tagged_release but do not commit changes or upload them')
parser.add_argument('version', help='emscripten version (e.g. 3.1.66)')
args = parser.parse_args(argv)
tag = args.version
source_rev = args.revision
if not source_rev:
source_rev = run(['git', 'rev-parse', 'HEAD'], True).strip()
create_cl(source_rev, tag, args.dry_run)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))