2007-05-22 20:07:17 +00:00
|
|
|
#!/usr/bin/python
|
2012-05-21 11:12:37 +00:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2019-09-11 21:06:34 +00:00
|
|
|
from __future__ import absolute_import, print_function
|
2007-05-22 20:07:17 +00:00
|
|
|
|
2009-09-23 17:57:22 +00:00
|
|
|
LIBFFI_DIRS = (("js/ctypes/libffi", "libffi"),)
|
2013-04-02 00:26:39 +00:00
|
|
|
HG_EXCLUSIONS = [".hg", ".hgignore", ".hgtags"]
|
2009-09-23 17:57:22 +00:00
|
|
|
|
|
|
|
CVSROOT_LIBFFI = ":pserver:anoncvs@sources.redhat.com:/cvs/libffi"
|
2007-05-22 20:07:17 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2008-06-02 22:52:25 +00:00
|
|
|
import datetime
|
2008-06-06 12:34:40 +00:00
|
|
|
import shutil
|
2012-04-12 22:14:10 +00:00
|
|
|
import glob
|
2007-05-22 20:07:17 +00:00
|
|
|
from optparse import OptionParser
|
2011-04-14 13:44:13 +00:00
|
|
|
from subprocess import check_call
|
2007-05-22 20:07:17 +00:00
|
|
|
|
|
|
|
topsrcdir = os.path.dirname(__file__)
|
|
|
|
if topsrcdir == "":
|
|
|
|
topsrcdir = "."
|
|
|
|
|
2020-06-11 18:03:17 +00:00
|
|
|
|
2007-07-13 12:23:32 +00:00
|
|
|
def check_call_noisy(cmd, *args, **kwargs):
|
2019-09-11 21:06:34 +00:00
|
|
|
print("Executing command:", cmd)
|
2007-07-13 12:23:32 +00:00
|
|
|
check_call(cmd, *args, **kwargs)
|
|
|
|
|
2020-06-11 18:03:17 +00:00
|
|
|
|
2007-07-13 12:23:32 +00:00
|
|
|
def do_hg_pull(dir, repository, hg):
|
2007-05-22 20:07:17 +00:00
|
|
|
fulldir = os.path.join(topsrcdir, dir)
|
2007-05-24 04:05:33 +00:00
|
|
|
# clone if the dir doesn't exist, pull if it does
|
|
|
|
if not os.path.exists(fulldir):
|
2007-07-13 12:23:32 +00:00
|
|
|
check_call_noisy([hg, "clone", repository, fulldir])
|
2007-05-24 04:05:33 +00:00
|
|
|
else:
|
2007-07-13 12:23:32 +00:00
|
|
|
cmd = [hg, "pull", "-u", "-R", fulldir]
|
|
|
|
if repository is not None:
|
|
|
|
cmd.append(repository)
|
|
|
|
check_call_noisy(cmd)
|
2008-06-02 22:52:25 +00:00
|
|
|
check_call(
|
|
|
|
[hg, "parent", "-R", fulldir, "--template=Updated to revision {node}.\n"]
|
|
|
|
)
|
2007-05-22 20:07:17 +00:00
|
|
|
|
2020-06-11 18:03:17 +00:00
|
|
|
|
2012-04-12 22:14:10 +00:00
|
|
|
def do_hg_replace(dir, repository, tag, exclusions, hg):
|
|
|
|
"""
|
|
|
|
Replace the contents of dir with the contents of repository, except for
|
|
|
|
files matching exclusions.
|
|
|
|
"""
|
|
|
|
fulldir = os.path.join(topsrcdir, dir)
|
|
|
|
if os.path.exists(fulldir):
|
|
|
|
shutil.rmtree(fulldir)
|
|
|
|
|
|
|
|
assert not os.path.exists(fulldir)
|
|
|
|
check_call_noisy([hg, "clone", "-u", tag, repository, fulldir])
|
|
|
|
|
|
|
|
for thing in exclusions:
|
|
|
|
for excluded in glob.iglob(os.path.join(fulldir, thing)):
|
|
|
|
if os.path.isdir(excluded):
|
|
|
|
shutil.rmtree(excluded)
|
|
|
|
else:
|
|
|
|
os.remove(excluded)
|
|
|
|
|
2020-06-11 18:03:17 +00:00
|
|
|
|
2008-06-06 12:34:40 +00:00
|
|
|
def do_cvs_export(modules, tag, cvsroot, cvs):
|
|
|
|
"""Check out a CVS directory without CVS metadata, using "export"
|
2009-09-23 17:57:22 +00:00
|
|
|
modules is a list of directories to check out and the corresponding
|
2013-04-02 00:26:39 +00:00
|
|
|
cvs module, e.g. (('js/ctypes/libffi', 'libffi'),)
|
2007-05-22 20:07:17 +00:00
|
|
|
"""
|
2009-09-23 17:57:22 +00:00
|
|
|
for module_tuple in modules:
|
|
|
|
module = module_tuple[0]
|
|
|
|
cvs_module = module_tuple[1]
|
2008-06-06 12:34:40 +00:00
|
|
|
fullpath = os.path.join(topsrcdir, module)
|
|
|
|
if os.path.exists(fullpath):
|
2019-09-11 21:06:34 +00:00
|
|
|
print("Removing '%s'" % fullpath)
|
2008-06-06 12:34:40 +00:00
|
|
|
shutil.rmtree(fullpath)
|
|
|
|
|
2007-05-22 20:07:17 +00:00
|
|
|
(parent, leaf) = os.path.split(module)
|
2019-09-11 21:06:34 +00:00
|
|
|
print(
|
|
|
|
"CVS export begin: "
|
|
|
|
+ datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
|
2020-10-26 18:34:53 +00:00
|
|
|
)
|
2007-07-13 12:23:32 +00:00
|
|
|
check_call_noisy(
|
2009-09-23 17:57:22 +00:00
|
|
|
[cvs, "-d", cvsroot, "export", "-r", tag, "-d", leaf, cvs_module],
|
2007-07-13 12:23:32 +00:00
|
|
|
cwd=os.path.join(topsrcdir, parent),
|
|
|
|
)
|
2019-09-11 21:06:34 +00:00
|
|
|
print(
|
|
|
|
"CVS export end: "
|
|
|
|
+ datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
|
2020-10-26 18:34:53 +00:00
|
|
|
)
|
2007-05-22 20:07:17 +00:00
|
|
|
|
2020-06-11 18:03:17 +00:00
|
|
|
|
2012-08-16 06:28:57 +00:00
|
|
|
def toggle_trailing_blank_line(depname):
|
2020-06-11 18:03:17 +00:00
|
|
|
"""If the trailing line is empty, then we'll delete it.
|
|
|
|
Otherwise we'll add a blank line."""
|
|
|
|
lines = open(depname, "r").readlines()
|
|
|
|
if not lines:
|
|
|
|
print("unexpected short file", file=sys.stderr)
|
|
|
|
return
|
|
|
|
|
|
|
|
if not lines[-1].strip():
|
|
|
|
# trailing line is blank, removing it
|
|
|
|
open(depname, "wb").writelines(lines[:-1])
|
|
|
|
else:
|
|
|
|
# adding blank line
|
2020-06-30 03:43:22 +00:00
|
|
|
open(depname, "ab").write(b"\n")
|
2020-06-11 18:03:17 +00:00
|
|
|
|
2012-08-16 06:28:57 +00:00
|
|
|
|
2013-06-24 14:39:22 +00:00
|
|
|
def get_trailing_blank_line_state(depname):
|
2020-06-11 18:03:17 +00:00
|
|
|
lines = open(depname, "r").readlines()
|
|
|
|
if not lines:
|
|
|
|
print("unexpected short file", file=sys.stderr)
|
|
|
|
return "no blank line"
|
|
|
|
|
|
|
|
if not lines[-1].strip():
|
|
|
|
return "has blank line"
|
2020-07-08 09:24:49 +00:00
|
|
|
return "no blank line"
|
2013-06-24 14:39:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def update_nspr_or_nss(tag, depfile, destination, hgpath):
|
2020-06-11 18:03:17 +00:00
|
|
|
destination = destination.rstrip("/")
|
|
|
|
permanent_patch_dir = destination + "/patches"
|
|
|
|
temporary_patch_dir = destination + ".patches"
|
|
|
|
if os.path.exists(temporary_patch_dir):
|
|
|
|
print("please clean up leftover directory " + temporary_patch_dir)
|
|
|
|
sys.exit(2)
|
|
|
|
warn_if_patch_exists(permanent_patch_dir)
|
|
|
|
# protect patch directory from being removed by do_hg_replace
|
|
|
|
if os.path.exists(permanent_patch_dir):
|
|
|
|
shutil.move(permanent_patch_dir, temporary_patch_dir)
|
|
|
|
# now update the destination
|
|
|
|
print("reverting to HG version of %s to get its blank line state" % depfile)
|
|
|
|
check_call_noisy([options.hg, "revert", depfile])
|
|
|
|
old_state = get_trailing_blank_line_state(depfile)
|
|
|
|
print("old state of %s is: %s" % (depfile, old_state))
|
|
|
|
do_hg_replace(destination, hgpath, tag, HG_EXCLUSIONS, options.hg)
|
|
|
|
new_state = get_trailing_blank_line_state(depfile)
|
|
|
|
print("new state of %s is: %s" % (depfile, new_state))
|
|
|
|
if old_state == new_state:
|
|
|
|
print("toggling blank line in: ", depfile)
|
|
|
|
toggle_trailing_blank_line(depfile)
|
|
|
|
tag_file = destination + "/TAG-INFO"
|
|
|
|
with open(tag_file, "w") as f:
|
|
|
|
f.write(tag)
|
|
|
|
# move patch directory back to a subdirectory
|
|
|
|
if os.path.exists(temporary_patch_dir):
|
|
|
|
shutil.move(temporary_patch_dir, permanent_patch_dir)
|
|
|
|
|
2017-09-18 17:05:45 +00:00
|
|
|
|
|
|
|
def warn_if_patch_exists(path):
|
2020-06-11 18:03:17 +00:00
|
|
|
# If the given patch directory exists and contains at least one file,
|
|
|
|
# then print warning and wait for the user to acknowledge.
|
|
|
|
if os.path.isdir(path) and os.listdir(path):
|
|
|
|
print("========================================")
|
|
|
|
print("WARNING: At least one patch file exists")
|
|
|
|
print("in directory: " + path)
|
|
|
|
print("You must manually re-apply all patches")
|
|
|
|
print("after this script has completed!")
|
|
|
|
print("========================================")
|
2020-06-11 15:23:10 +00:00
|
|
|
input("Press Enter to continue...")
|
2020-06-11 18:03:17 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
o = OptionParser(
|
|
|
|
usage="client.py [options] update_nspr tagname | update_nss tagname | update_libffi tagname"
|
|
|
|
)
|
2007-12-21 21:49:52 +00:00
|
|
|
o.add_option(
|
|
|
|
"--skip-mozilla",
|
|
|
|
dest="skip_mozilla",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
2008-06-06 12:34:40 +00:00
|
|
|
help="Obsolete",
|
|
|
|
)
|
2020-10-26 18:34:53 +00:00
|
|
|
|
2007-05-22 20:07:17 +00:00
|
|
|
o.add_option(
|
|
|
|
"--cvs",
|
|
|
|
dest="cvs",
|
|
|
|
default=os.environ.get("CVS", "cvs"),
|
|
|
|
help="The location of the cvs binary",
|
|
|
|
)
|
|
|
|
o.add_option(
|
|
|
|
"--cvsroot",
|
|
|
|
dest="cvsroot",
|
2013-04-02 00:26:39 +00:00
|
|
|
help="The CVSROOT for libffi (default : %s)" % CVSROOT_LIBFFI,
|
|
|
|
)
|
2012-04-12 22:14:10 +00:00
|
|
|
o.add_option(
|
|
|
|
"--hg",
|
|
|
|
dest="hg",
|
|
|
|
default=os.environ.get("HG", "hg"),
|
|
|
|
help="The location of the hg binary",
|
|
|
|
)
|
2013-11-17 21:48:30 +00:00
|
|
|
o.add_option(
|
|
|
|
"--repo", dest="repo", help="the repo to update from (default: upstream repo)"
|
|
|
|
)
|
2007-05-22 20:07:17 +00:00
|
|
|
|
|
|
|
try:
|
2008-06-06 12:34:40 +00:00
|
|
|
options, args = o.parse_args()
|
|
|
|
action = args[0]
|
|
|
|
except IndexError:
|
2007-05-22 20:07:17 +00:00
|
|
|
o.print_help()
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
if action in ("checkout", "co"):
|
2020-06-11 15:23:10 +00:00
|
|
|
print("Warning: client.py checkout is obsolete.", file=sys.stderr)
|
2008-06-06 12:34:40 +00:00
|
|
|
pass
|
|
|
|
elif action in ("update_nspr"):
|
|
|
|
(tag,) = args[1:]
|
2013-06-24 14:39:22 +00:00
|
|
|
depfile = "nsprpub/config/prdepend.h"
|
2013-11-17 21:48:30 +00:00
|
|
|
if not options.repo:
|
|
|
|
options.repo = "https://hg.mozilla.org/projects/nspr"
|
|
|
|
update_nspr_or_nss(tag, depfile, "nsprpub", options.repo)
|
2008-06-06 12:34:40 +00:00
|
|
|
elif action in ("update_nss"):
|
|
|
|
(tag,) = args[1:]
|
2013-06-24 14:39:22 +00:00
|
|
|
depfile = "security/nss/coreconf/coreconf.dep"
|
2013-11-17 21:48:30 +00:00
|
|
|
if not options.repo:
|
2020-06-11 18:03:17 +00:00
|
|
|
options.repo = "https://hg.mozilla.org/projects/nss"
|
2013-11-17 21:48:30 +00:00
|
|
|
update_nspr_or_nss(tag, depfile, "security/nss", options.repo)
|
2009-09-23 17:57:22 +00:00
|
|
|
elif action in ("update_libffi"):
|
|
|
|
(tag,) = args[1:]
|
|
|
|
if not options.cvsroot:
|
|
|
|
options.cvsroot = CVSROOT_LIBFFI
|
|
|
|
do_cvs_export(LIBFFI_DIRS, tag, options.cvsroot, options.cvs)
|
2007-05-22 20:07:17 +00:00
|
|
|
else:
|
|
|
|
o.print_help()
|
|
|
|
sys.exit(2)
|