aboutsummaryrefslogtreecommitdiff
path: root/contrib/devtools
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/devtools')
-rw-r--r--contrib/devtools/README.md8
-rwxr-xr-xcontrib/devtools/check-doc.py2
-rwxr-xr-xcontrib/devtools/clang-format-diff.py4
-rwxr-xr-xcontrib/devtools/clang-format.py62
-rwxr-xr-xcontrib/devtools/github-merge.py63
-rwxr-xr-xcontrib/devtools/optimize-pngs.py2
-rwxr-xr-xcontrib/devtools/test-security-check.py1
-rwxr-xr-xcontrib/devtools/update-translations.py8
8 files changed, 73 insertions, 77 deletions
diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md
index 6c0047833f..67c5e15a15 100644
--- a/contrib/devtools/README.md
+++ b/contrib/devtools/README.md
@@ -8,11 +8,6 @@ check-doc.py
Check if all command line args are documented. The return value indicates the
number of undocumented args.
-clang-format.py
-===============
-
-A script to format cpp source code according to [.clang-format](../../src/.clang-format). This should only be applied to new files or files which are currently not actively developed on. Also, git subtrees are not subject to formatting.
-
clang-format-diff.py
===================
@@ -24,6 +19,7 @@ the script should be called from the git root folder as follows.
```
git diff -U0 HEAD~1.. | ./contrib/devtools/clang-format-diff.py -p1 -i -v
```
+
copyright\_header.py
====================
@@ -129,7 +125,7 @@ check or whatever).
This means that there are no potential race conditions (where a
pullreq gets updated while you're reviewing it, but before you click
-merge), and when using GPG signatures, that even a compromised github
+merge), and when using GPG signatures, that even a compromised GitHub
couldn't mess with the sources.
Setup
diff --git a/contrib/devtools/check-doc.py b/contrib/devtools/check-doc.py
index 249214e931..445175ec2b 100755
--- a/contrib/devtools/check-doc.py
+++ b/contrib/devtools/check-doc.py
@@ -21,7 +21,7 @@ CMD_GREP_DOCS = r"egrep -r -I 'HelpMessageOpt\(\"\-[^\"=]+?(=|\")' %s" % (CMD_RO
REGEX_ARG = re.compile(r'(?:map(?:Multi)?Args(?:\.count\(|\[)|Get(?:Bool)?Arg\()\"(\-[^\"]+?)\"')
REGEX_DOC = re.compile(r'HelpMessageOpt\(\"(\-[^\"=]+?)(?:=|\")')
# list unsupported, deprecated and duplicate args as they need no documentation
-SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay', '-prematurewitness', '-walletprematurewitness', '-promiscuousmempoolflags', '-blockminsize'])
+SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay', '-prematurewitness', '-walletprematurewitness', '-promiscuousmempoolflags', '-blockminsize', '-sendfreetransactions'])
def main():
used = check_output(CMD_GREP_ARGS, shell=True)
diff --git a/contrib/devtools/clang-format-diff.py b/contrib/devtools/clang-format-diff.py
index 13d2573b9f..7ea49b65e1 100755
--- a/contrib/devtools/clang-format-diff.py
+++ b/contrib/devtools/clang-format-diff.py
@@ -128,7 +128,7 @@ def main():
line_count = int(match.group(3))
if line_count == 0:
continue
- end_line = start_line + line_count - 1;
+ end_line = start_line + line_count - 1
lines_by_file.setdefault(filename, []).extend(
['-lines', str(start_line) + ':' + str(end_line)])
@@ -147,7 +147,7 @@ def main():
stderr=None, stdin=subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
- sys.exit(p.returncode);
+ sys.exit(p.returncode)
if not args.i:
with open(filename) as f:
diff --git a/contrib/devtools/clang-format.py b/contrib/devtools/clang-format.py
deleted file mode 100755
index cee99047ac..0000000000
--- a/contrib/devtools/clang-format.py
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python
-'''
-Wrapper script for clang-format
-
-Copyright (c) 2015 MarcoFalke
-Copyright (c) 2015 The Bitcoin Core developers
-Distributed under the MIT software license, see the accompanying
-file COPYING or http://www.opensource.org/licenses/mit-license.php.
-'''
-
-import os
-import sys
-import subprocess
-
-tested_versions = ['3.6.0', '3.6.1', '3.6.2'] # A set of versions known to produce the same output
-accepted_file_extensions = ('.h', '.cpp') # Files to format
-
-def check_clang_format_version(clang_format_exe):
- try:
- output = subprocess.check_output([clang_format_exe, '-version'])
- for ver in tested_versions:
- if ver in output:
- print "Detected clang-format version " + ver
- return
- raise RuntimeError("Untested version: " + output)
- except Exception as e:
- print 'Could not verify version of ' + clang_format_exe + '.'
- raise e
-
-def check_command_line_args(argv):
- required_args = ['{clang-format-exe}', '{files}']
- example_args = ['clang-format-3.x', 'src/main.cpp', 'src/wallet/*']
-
- if(len(argv) < len(required_args) + 1):
- for word in (['Usage:', argv[0]] + required_args):
- print word,
- print ''
- for word in (['E.g:', argv[0]] + example_args):
- print word,
- print ''
- sys.exit(1)
-
-def run_clang_format(clang_format_exe, files):
- for target in files:
- if os.path.isdir(target):
- for path, dirs, files in os.walk(target):
- run_clang_format(clang_format_exe, (os.path.join(path, f) for f in files))
- elif target.endswith(accepted_file_extensions):
- print "Format " + target
- subprocess.check_call([clang_format_exe, '-i', '-style=file', target], stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT)
- else:
- print "Skip " + target
-
-def main(argv):
- check_command_line_args(argv)
- clang_format_exe = argv[1]
- files = argv[2:]
- check_clang_format_version(clang_format_exe)
- run_clang_format(clang_format_exe, files)
-
-if __name__ == "__main__":
- main(sys.argv)
diff --git a/contrib/devtools/github-merge.py b/contrib/devtools/github-merge.py
index aae966a8f6..f1b6a12fd0 100755
--- a/contrib/devtools/github-merge.py
+++ b/contrib/devtools/github-merge.py
@@ -15,9 +15,10 @@
# In case of a clean merge that is accepted by the user, the local branch with
# name $BRANCH is overwritten with the merged result, and optionally pushed.
from __future__ import division,print_function,unicode_literals
-import os,sys
+import os
from sys import stdin,stdout,stderr
import argparse
+import hashlib
import subprocess
import json,codecs
try:
@@ -69,6 +70,35 @@ def ask_prompt(text):
print("",file=stderr)
return reply
+def get_symlink_files():
+ files = sorted(subprocess.check_output([GIT, 'ls-tree', '--full-tree', '-r', 'HEAD']).splitlines())
+ ret = []
+ for f in files:
+ if (int(f.decode('utf-8').split(" ")[0], 8) & 0o170000) == 0o120000:
+ ret.append(f.decode('utf-8').split("\t")[1])
+ return ret
+
+def tree_sha512sum():
+ files = sorted(subprocess.check_output([GIT, 'ls-tree', '--full-tree', '-r', '--name-only', 'HEAD']).splitlines())
+ overall = hashlib.sha512()
+ for f in files:
+ intern = hashlib.sha512()
+ fi = open(f, 'rb')
+ while True:
+ piece = fi.read(65536)
+ if piece:
+ intern.update(piece)
+ else:
+ break
+ fi.close()
+ dig = intern.hexdigest()
+ overall.update(dig.encode("utf-8"))
+ overall.update(" ".encode("utf-8"))
+ overall.update(f)
+ overall.update("\n".encode("utf-8"))
+ return overall.hexdigest()
+
+
def parse_arguments():
epilog = '''
In addition, you can set the following git configuration variables:
@@ -157,6 +187,9 @@ def main():
subprocess.check_call([GIT,'checkout','-q','-b',local_merge_branch])
try:
+ # Go up to the repository's root.
+ toplevel = subprocess.check_output([GIT,'rev-parse','--show-toplevel']).strip()
+ os.chdir(toplevel)
# Create unsigned merge commit.
if title:
firstline = 'Merge #%s: %s' % (pull,title)
@@ -175,14 +208,31 @@ def main():
print("ERROR: Creating merge failed (already merged?).",file=stderr)
exit(4)
+ symlink_files = get_symlink_files()
+ for f in symlink_files:
+ print("ERROR: File %s was a symlink" % f)
+ if len(symlink_files) > 0:
+ exit(4)
+
+ # Put tree SHA512 into the message
+ try:
+ first_sha512 = tree_sha512sum()
+ message += '\n\nTree-SHA512: ' + first_sha512
+ except subprocess.CalledProcessError as e:
+ printf("ERROR: Unable to compute tree hash")
+ exit(4)
+ try:
+ subprocess.check_call([GIT,'commit','--amend','-m',message.encode('utf-8')])
+ except subprocess.CalledProcessError as e:
+ printf("ERROR: Cannot update message.",file=stderr)
+ exit(4)
+
print('%s#%s%s %s %sinto %s%s' % (ATTR_RESET+ATTR_PR,pull,ATTR_RESET,title,ATTR_RESET+ATTR_PR,branch,ATTR_RESET))
subprocess.check_call([GIT,'log','--graph','--topo-order','--pretty=format:'+COMMIT_FORMAT,base_branch+'..'+head_branch])
print()
+
# Run test command if configured.
if testcmd:
- # Go up to the repository's root.
- toplevel = subprocess.check_output([GIT,'rev-parse','--show-toplevel']).strip()
- os.chdir(toplevel)
if subprocess.call(testcmd,shell=True):
print("ERROR: Running %s failed." % testcmd,file=stderr)
exit(5)
@@ -218,6 +268,11 @@ def main():
print("ERROR: Merge rejected.",file=stderr)
exit(7)
+ second_sha512 = tree_sha512sum()
+ if first_sha512 != second_sha512:
+ print("ERROR: Tree hash changed unexpectedly",file=stderr)
+ exit(8)
+
# Sign the merge commit.
reply = ask_prompt("Type 's' to sign off on the merge.")
if reply == 's':
diff --git a/contrib/devtools/optimize-pngs.py b/contrib/devtools/optimize-pngs.py
index 0f653e010b..9286ab731f 100755
--- a/contrib/devtools/optimize-pngs.py
+++ b/contrib/devtools/optimize-pngs.py
@@ -39,7 +39,7 @@ for folder in folders:
if extension.lower() == '.png':
print("optimizing "+file+"..."),
file_path = os.path.join(absFolder, file)
- fileMetaMap = {'file' : file, 'osize': os.path.getsize(file_path), 'sha256Old' : file_hash(file_path)};
+ fileMetaMap = {'file' : file, 'osize': os.path.getsize(file_path), 'sha256Old' : file_hash(file_path)}
fileMetaMap['contentHashPre'] = content_hash(file_path)
pngCrushOutput = ""
diff --git a/contrib/devtools/test-security-check.py b/contrib/devtools/test-security-check.py
index c0f120392e..18f9835faa 100755
--- a/contrib/devtools/test-security-check.py
+++ b/contrib/devtools/test-security-check.py
@@ -7,7 +7,6 @@ Test script for security-check.py
'''
from __future__ import division,print_function
import subprocess
-import sys
import unittest
def write_testcode(filename):
diff --git a/contrib/devtools/update-translations.py b/contrib/devtools/update-translations.py
index 78b9f9d179..2011841005 100755
--- a/contrib/devtools/update-translations.py
+++ b/contrib/devtools/update-translations.py
@@ -65,6 +65,14 @@ def split_format_specifiers(specifiers):
else:
other.append(s)
+ # If both numeric format specifiers and "others" are used, assume we're dealing
+ # with a Qt-formatted message. In the case of Qt formatting (see https://doc.qt.io/qt-5/qstring.html#arg)
+ # only numeric formats are replaced at all. This means "(percentage: %1%)" is valid, without needing
+ # any kind of escaping that would be necessary for strprintf. Without this, this function
+ # would wrongly detect '%)' as a printf format specifier.
+ if numeric:
+ other = []
+
# numeric (Qt) can be present in any order, others (strprintf) must be in specified order
return set(numeric),other