diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index 6098f39aaa..bef9f41ced 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -1,154 +1,142 @@ Contents ======== This directory contains tools for developers working on this repository. check-doc.py ============ Check if all command line args are documented. The return value indicates the number of undocumented args. -clang-format-diff.py -=================== - -A script to format unified git diffs according to [.clang-format](../../src/.clang-format). - -For instance, to format the last commit with 0 lines of context, -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 ==================== Provides utilities for managing copyright headers of `The Bitcoin developers` in repository source files. It has three subcommands: ``` $ ./copyright_header.py report [verbose] $ ./copyright_header.py update $ ./copyright_header.py insert ``` Running these subcommands without arguments displays a usage string. copyright\_header.py report \ [verbose] --------------------------------------------------------- Produces a report of all copyright header notices found inside the source files of a repository. Useful to quickly visualize the state of the headers. Specifying `verbose` will list the full filenames of files of each category. copyright\_header.py update \ [verbose] --------------------------------------------------------- Updates all the copyright headers of `The Bitcoin developers` which were changed in a year more recent than is listed. For example: ``` // Copyright (c) - The Bitcoin developers ``` will be updated to: ``` // Copyright (c) - The Bitcoin developers ``` where `` is obtained from the `git log` history. This subcommand also handles copyright headers that have only a single year. In those cases: ``` // Copyright (c) The Bitcoin developers ``` will be updated to: ``` // Copyright (c) - The Bitcoin developers ``` where the update is appropriate. copyright\_header.py insert \ ------------------------------------ Inserts a copyright header for `The Bitcoin developers` at the top of the file in either Python or C++ style as determined by the file extension. If the file is a Python file and it has `#!` starting the first line, the header is inserted in the line below it. The copyright dates will be set to be `-` where `` is according to the `git log` history. If `` is equal to ``, it will be set as a single year rather than two hyphenated years. If the file already has a copyright for `The Bitcoin developers`, the script will exit. gen-manpages.sh =============== A small script to automatically create manpages in ../../doc/man by running the release binaries with the -help option. This requires help2man which can be found at: https://www.gnu.org/software/help2man/ With in-tree builds this tool can be run from any directory within the repostitory. To use this tool with out-of-tree builds set `BUILDDIR`. For example: ```bash BUILDDIR=$PWD/build contrib/devtools/gen-manpages.sh ``` git-subtree-check.sh ==================== Run this script from the root of the repository to verify that a subtree matches the contents of the commit it claims to have been updated to. To use, make sure that you have fetched the upstream repository branch in which the subtree is maintained: * for `src/secp256k1`: https://github.com/bitcoin-core/secp256k1.git (branch master) * for `src/leveldb`: https://github.com/bitcoin-core/leveldb.git (branch bitcoin-fork) * for `src/univalue`: https://github.com/bitcoin-core/univalue.git (branch master) * for `src/crypto/ctaes`: https://github.com/bitcoin-core/ctaes.git (branch master) Usage: `git-subtree-check.sh DIR (COMMIT)` `COMMIT` may be omitted, in which case `HEAD` is used. optimize-pngs.py ================ A script to optimize png files in the bitcoin repository (requires pngcrush). security-check.py and test-security-check.py ============================================ Perform basic ELF security checks on a series of executables. symbol-check.py =============== A script to check that the (Linux) executables produced by gitian only contain allowed gcc, glibc and libstdc++ version symbols. This makes sure they are still compatible with the minimum supported Linux distribution versions. Example usage after a gitian build: find ../gitian-builder/build -type f -executable | xargs python contrib/devtools/symbol-check.py If only supported symbols are used the return value will be 0 and the output will be empty. If there are 'unsupported' symbols, the return value will be 1 a list like this will be printed: .../64/test_bitcoin: symbol memcpy from unsupported version GLIBC_2.14 .../64/test_bitcoin: symbol __fdelt_chk from unsupported version GLIBC_2.15 .../64/test_bitcoin: symbol std::out_of_range::~out_of_range() from unsupported version GLIBCXX_3.4.15 .../64/test_bitcoin: symbol _ZNSt8__detail15_List_nod from unsupported version GLIBCXX_3.4.15 update-translations.py ====================== Run this script from the root of the repository to update all translations from transifex. It will do the following automatically: - fetch all translations - post-process them into valid and committable format - add missing translations to the build system (TODO) See doc/translation-process.md for more information. diff --git a/contrib/devtools/clang-format-diff.py b/contrib/devtools/clang-format-diff.py deleted file mode 100755 index 0c9fc80aa5..0000000000 --- a/contrib/devtools/clang-format-diff.py +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env python -# -#===- clang-format-diff.py - ClangFormat Diff Reformatter ----*- python -*--===# -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. -# -# ============================================================ -# -# University of Illinois/NCSA -# Open Source License -# -# Copyright (c) 2007-2015 University of Illinois at Urbana-Champaign. -# All rights reserved. -# -# Developed by: -# -# LLVM Team -# -# University of Illinois at Urbana-Champaign -# -# http://llvm.org -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of -# this software and associated documentation files (the "Software"), to deal with -# the Software without restriction, including without limitation the rights to -# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -# of the Software, and to permit persons to whom the Software is furnished to do -# so, subject to the following conditions: -# -# * Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimers. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimers in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the names of the LLVM Team, University of Illinois at -# Urbana-Champaign, nor the names of its contributors may be used to -# endorse or promote products derived from this Software without specific -# prior written permission. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE -# SOFTWARE. -# -# ============================================================ -# -#===------------------------------------------------------------------------===# - -r""" -ClangFormat Diff Reformatter -============================ - -This script reads input from a unified diff and reformats all the changed -lines. This is useful to reformat all the lines touched by a specific patch. -Example usage for git/svn users: - - git diff -U0 HEAD^ | clang-format-diff.py -p1 -i - svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i - -""" - -import argparse -import difflib -import re -import string -import subprocess -import StringIO -import sys - - -# Change this to the full path if clang-format is not on the path. -binary = 'clang-format' - - -def main(): - parser = argparse.ArgumentParser(description='Reformat changed lines in diff. Without -i ' - 'option just output the diff that would be ' - 'introduced.') - parser.add_argument('-i', action='store_true', default=False, - help='apply edits to files instead of displaying a diff') - parser.add_argument('-p', metavar='NUM', default=0, - help='strip the smallest prefix containing P slashes') - parser.add_argument('-regex', metavar='PATTERN', default=None, - help='custom pattern selecting file paths to reformat ' - '(case sensitive, overrides -iregex)') - parser.add_argument('-iregex', metavar='PATTERN', default=r'.*\.(cpp|cc|c\+\+|cxx|c|cl|h|hpp|m|mm|inc|js|ts|proto' - r'|protodevel|java)', - help='custom pattern selecting file paths to reformat ' - '(case insensitive, overridden by -regex)') - parser.add_argument('-sort-includes', action='store_true', default=False, - help='let clang-format sort include blocks') - parser.add_argument('-v', '--verbose', action='store_true', - help='be more verbose, ineffective without -i') - args = parser.parse_args() - - # Extract changed lines for each file. - filename = None - lines_by_file = {} - for line in sys.stdin: - match = re.search('^\+\+\+\ (.*?/){%s}(\S*)' % args.p, line) - if match: - filename = match.group(2) - if filename == None: - continue - - if args.regex is not None: - if not re.match('^%s$' % args.regex, filename): - continue - else: - if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE): - continue - - match = re.search('^@@.*\+(\d+)(,(\d+))?', line) - if match: - start_line = int(match.group(1)) - line_count = 1 - if match.group(3): - line_count = int(match.group(3)) - if line_count == 0: - continue - end_line = start_line + line_count - 1 - lines_by_file.setdefault(filename, []).extend( - ['-lines', str(start_line) + ':' + str(end_line)]) - - # Reformat files containing changes in place. - for filename, lines in lines_by_file.iteritems(): - if args.i and args.verbose: - print 'Formatting', filename - command = [binary, filename] - if args.i: - command.append('-i') - if args.sort_includes: - command.append('-sort-includes') - command.extend(lines) - command.extend(['-style=file', '-fallback-style=none']) - p = subprocess.Popen(command, stdout=subprocess.PIPE, - stderr=None, stdin=subprocess.PIPE) - stdout, stderr = p.communicate() - if p.returncode != 0: - sys.exit(p.returncode) - - if not args.i: - with open(filename) as f: - code = f.readlines() - formatted_code = StringIO.StringIO(stdout).readlines() - diff = difflib.unified_diff(code, formatted_code, - filename, filename, - '(before formatting)', '(after formatting)') - diff_string = string.join(diff, '') - if len(diff_string) > 0: - sys.stdout.write(diff_string) - - -if __name__ == '__main__': - main()