diff --git a/.licenseignore b/.licenseignore index bdd742c1..53248196 100644 --- a/.licenseignore +++ b/.licenseignore @@ -1,6 +1,7 @@ .gitignore **/.gitignore .licenseignore +.unacceptablelanguageignore .gitattributes .git-blame-ignore-revs .mailfilter diff --git a/scripts/build-asm.py b/scripts/build-asm.py index 8758ab65..306d2600 100755 --- a/scripts/build-asm.py +++ b/scripts/build-asm.py @@ -7,15 +7,14 @@ ## Licensed under Apache License v2.0 ## ## See LICENSE.txt for license information -## See CONTRIBUTORS.md for the list of SwiftCrypto project authors +## See CONTRIBUTORS.txt for the list of SwiftCrypto project authors ## ## SPDX-License-Identifier: Apache-2.0 ## ##===----------------------------------------------------------------------===## -import contextlib -import subprocess import os +import subprocess # OS_ARCH_COMBOS maps from OS and platform to the OpenSSL assembly "style" for @@ -49,85 +48,85 @@ def FindCMakeFiles(directory): - """Returns list of all CMakeLists.txt files recursively in directory.""" - cmakefiles = [] + """Returns list of all CMakeLists.txt files recursively in directory.""" + cmakefiles = [] - for (path, _, filenames) in os.walk(directory): - for filename in filenames: - if filename == 'CMakeLists.txt': - cmakefiles.append(os.path.join(path, filename)) + for (path, _, filenames) in os.walk(directory): + for filename in filenames: + if filename == 'CMakeLists.txt': + cmakefiles.append(os.path.join(path, filename)) - return cmakefiles + return cmakefiles def ExtractPerlAsmFromCMakeFile(cmakefile): - """Parses the contents of the CMakeLists.txt file passed as an argument and - returns a list of all the perlasm() directives found in the file.""" - perlasms = [] - with open(cmakefile) as f: - for line in f: - line = line.strip() - if not line.startswith('perlasm('): - continue - if not line.endswith(')'): - raise ValueError('Bad perlasm line in %s' % cmakefile) - # Remove "perlasm(" from start and ")" from end - params = line[8:-1].split() - if len(params) < 4: - raise ValueError('Bad perlasm line in %s: %s' % (cmakefile, line)) - perlasms.append({ - 'arch': params[1], - 'output': os.path.join(os.path.dirname(cmakefile), params[2]), - 'input': os.path.join(os.path.dirname(cmakefile), params[3]), - 'extra_args': params[4:], - }) - - return perlasms + """Parses the contents of the CMakeLists.txt file passed as an argument and + returns a list of all the perlasm() directives found in the file.""" + perlasms = [] + with open(cmakefile) as f: + for line in f: + line = line.strip() + if not line.startswith('perlasm('): + continue + if not line.endswith(')'): + raise ValueError('Bad perlasm line in %s' % cmakefile) + # Remove "perlasm(" from start and ")" from end + params = line[8:-1].split() + if len(params) < 4: + raise ValueError('Bad perlasm line in %s: %s' % (cmakefile, line)) + perlasms.append({ + 'arch': params[1], + 'output': os.path.join(os.path.dirname(cmakefile), params[2]), + 'input': os.path.join(os.path.dirname(cmakefile), params[3]), + 'extra_args': params[4:], + }) + + return perlasms def ReadPerlAsmOperations(): - """Returns a list of all perlasm() directives found in CMake config files in - src/.""" - perlasms = [] - cmakefiles = FindCMakeFiles('boringssl') + """Returns a list of all perlasm() directives found in CMake config files in + src/.""" + perlasms = [] + cmakefiles = FindCMakeFiles('boringssl') - for cmakefile in cmakefiles: - perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile)) + for cmakefile in cmakefiles: + perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile)) - return perlasms + return perlasms def PerlAsm(output_filename, input_filename, perlasm_style, extra_args): - """Runs the a perlasm script and puts the output into output_filename.""" - base_dir = os.path.dirname(output_filename) - if not os.path.isdir(base_dir): - os.makedirs(base_dir) - subprocess.check_call( - ['perl', input_filename, perlasm_style] + extra_args + [output_filename]) + """Runs the a perlasm script and puts the output into output_filename.""" + base_dir = os.path.dirname(output_filename) + if not os.path.isdir(base_dir): + os.makedirs(base_dir) + subprocess.check_call( + ['perl', input_filename, perlasm_style] + extra_args + [output_filename]) + def WriteAsmFiles(perlasms): - """Generates asm files from perlasm directives for each supported OS x - platform combination.""" - asmfiles = {} - - for perlasm in perlasms: - for (osname, arch, perlasm_style, extra_args, asm_ext) in OS_ARCH_COMBOS: - if arch != perlasm['arch']: - continue - key = (osname, arch) - outDir = '%s-%s' % key - - filename = os.path.basename(perlasm['input']) - output = perlasm['output'] - if not output.startswith('boringssl/crypto'): - raise ValueError('output missing crypto: %s' % output) - output = os.path.join(outDir, output[17:]) - output = '%s-%s.%s' % (output, osname, asm_ext) - per_command_extra_args = extra_args + perlasm['extra_args'] - PerlAsm(output, perlasm['input'], perlasm_style, per_command_extra_args) - asmfiles.setdefault(key, []).append(output) - - return asmfiles + """Generates asm files from perlasm directives for each supported OS x + platform combination.""" + asmfiles = {} + + for perlasm in perlasms: + for (osname, arch, perlasm_style, extra_args, asm_ext) in OS_ARCH_COMBOS: + if arch != perlasm['arch']: + continue + key = (osname, arch) + outDir = '%s-%s' % key + + output = perlasm['output'] + if not output.startswith('boringssl/crypto'): + raise ValueError('output missing crypto: %s' % output) + output = os.path.join(outDir, output[17:]) + output = '%s-%s.%s' % (output, osname, asm_ext) + per_command_extra_args = extra_args + perlasm['extra_args'] + PerlAsm(output, perlasm['input'], perlasm_style, per_command_extra_args) + asmfiles.setdefault(key, []).append(output) + + return asmfiles def preprocessor_arch_for_arch(arch): @@ -152,7 +151,7 @@ def preprocessor_platform_for_os(osname): def asm_target(osname, arch, asm): components = asm.split('/') - new_components = ["boringssl/crypto"] + components[1:-1] + [components[-1].replace('.S', '.' + osname + '.' + arch + '.S')] + new_components = ["boringssl/crypto"] + components[1:-1] + [components[-1].replace('.S', '.' + osname + '.' + arch + '.S')] # noqa: E501 return '/'.join(new_components) @@ -160,11 +159,11 @@ def munge_file(pp_arch, pp_platform, source_lines, sink): """ Wraps a single assembly file in appropriate defines. """ - sink.write(b"#if defined(%b) && defined(%b)\n" % (pp_arch.encode(), pp_platform.encode())) + sink.write(b"#if defined(%b) && defined(%b)\n" % (pp_arch.encode(), pp_platform.encode())) # noqa: E501 for line in source_lines: sink.write(line) - sink.write(b"#endif // defined(%b) && defined(%b)\n" % (pp_arch.encode(), pp_platform.encode())) + sink.write(b"#endif // defined(%b) && defined(%b)\n" % (pp_arch.encode(), pp_platform.encode())) # noqa: E501 def munge_all_files(osname, arch, asms): @@ -175,11 +174,10 @@ def munge_all_files(osname, arch, asms): pp_arch = preprocessor_arch_for_arch(arch) pp_platform = preprocessor_platform_for_os(osname) target = asm_target(osname, arch, asm) - + with open(asm, 'rb') as source: with open(target, 'wb') as sink: munge_file(pp_arch, pp_platform, source, sink) - def main(): @@ -194,15 +192,14 @@ def main(): for ((osname, arch), asm_files) in NON_PERL_FILES.items(): for asm_file in asm_files: - with open(asm_file, 'rb') as f: - lines = f.readlines() + with open(asm_file, 'rb') as f: + lines = f.readlines() + pp_arch = preprocessor_arch_for_arch(arch) + pp_platform = preprocessor_platform_for_os(osname) + + with open(asm_file, 'wb') as sink: + munge_file(pp_arch, pp_platform, lines, sink) - pp_arch = preprocessor_arch_for_arch(arch) - pp_platform = preprocessor_platform_for_os(osname) - - with open(asm_file, 'wb') as sink: - munge_file(pp_arch, pp_platform, lines, sink) if __name__ == '__main__': main() - diff --git a/scripts/environment.sh b/scripts/environment.sh index 2882ff60..74afcc84 100755 --- a/scripts/environment.sh +++ b/scripts/environment.sh @@ -7,7 +7,7 @@ ## Licensed under Apache License v2.0 ## ## See LICENSE.txt for license information -## See CONTRIBUTORS.md for the list of SwiftCrypto project authors +## See CONTRIBUTORS.txt for the list of SwiftCrypto project authors ## ## SPDX-License-Identifier: Apache-2.0 ## diff --git a/scripts/gyb b/scripts/gyb index dece788e..ef8021ad 100755 --- a/scripts/gyb +++ b/scripts/gyb @@ -1,3 +1,4 @@ #!/usr/bin/env python2.7 + import gyb gyb.main() diff --git a/scripts/gyb.py b/scripts/gyb.py index 2df9a031..d60de49b 100644 --- a/scripts/gyb.py +++ b/scripts/gyb.py @@ -51,7 +51,7 @@ def split_lines(s): If the lines are later concatenated, the result is s, possibly with a single appended newline. """ - return [l + '\n' for l in s.split('\n')] + return [line + '\n' for line in s.split('\n')] # text on a line up to the first '$$', '${', or '%%' @@ -74,8 +74,7 @@ def split_lines(s): ^ (?: (?P - (?P<_indent> [\ \t]* % (?! [{%] ) [\ \t]* ) (?! [\ \t] | ''' + - linesClose + r''' ) .* + (?P<_indent> [\ \t]* % (?! [{%] ) [\ \t]* ) (?! [\ \t] | ''' + linesClose + r''' ) .* # noqa: E501 ( \n (?P=_indent) (?! ''' + linesClose + r''' ) .* ) * ) | (?P [\ \t]* % [ \t]* ''' + linesClose + r''' ) @@ -612,8 +611,8 @@ def format_children(self, indent): return ' []' return '\n'.join( - ['', indent + '['] + - [x.__str__(indent + 4 * ' ') for x in self.children] + + ['', indent + '['] + # noqa: W504 + [x.__str__(indent + 4 * ' ') for x in self.children] + # noqa: W504 [indent + ']']) @@ -657,7 +656,7 @@ def execute(self, context): def __str__(self, indent=''): return '\n'.join( - [indent + x for x in ['Literal:'] + + [indent + x for x in ['Literal:'] + # noqa: W504 strip_trailing_nl(self.text).split('\n')]) @@ -748,7 +747,7 @@ def __str__(self, indent=''): s = indent + 'Code: {' + source_lines[0] + '}' else: s = indent + 'Code:\n' + indent + '{\n' + '\n'.join( - indent + 4 * ' ' + l for l in source_lines + indent + 4 * ' ' + line for line in source_lines ) + '\n' + indent + '}' return s + self.format_children(indent) diff --git a/scripts/vendor-boringssl.sh b/scripts/vendor-boringssl.sh index 0f6b7c04..ffdc128d 100755 --- a/scripts/vendor-boringssl.sh +++ b/scripts/vendor-boringssl.sh @@ -101,9 +101,9 @@ function mangle_symbols { ) # Now cross compile for our targets. - docker run -t -i --rm --privileged -v$(pwd):/src -w/src --platform linux/arm64 swift:5.9-jammy \ + docker run -t -i --rm --privileged -v"$(pwd)":/src -w/src --platform linux/arm64 swift:5.9-jammy \ swift build --product CCryptoBoringSSL - docker run -t -i --rm --privileged -v$(pwd):/src -w/src --platform linux/amd64 swift:5.9-jammy \ + docker run -t -i --rm --privileged -v"$(pwd)":/src -w/src --platform linux/amd64 swift:5.9-jammy \ swift build --product CCryptoBoringSSL # Now we need to generate symbol mangles for Linux. We can do this in @@ -133,6 +133,7 @@ function mangle_symbols { echo "ADDING symbol mangling" perl -pi -e '$_ .= qq(\n#define BORINGSSL_PREFIX CCryptoBoringSSL\n) if /#define OPENSSL_HEADER_BASE_H/' "$DSTROOT/include/openssl/base.h" + # shellcheck disable=SC2044 for assembly_file in $(find "$DSTROOT" -name "*.S") do $sed -i '1 i #define BORINGSSL_PREFIX CCryptoBoringSSL' "$assembly_file" @@ -145,6 +146,7 @@ case "$(uname -s)" in sed=gsed ;; *) + # shellcheck disable=SC2209 sed=sed ;; esac @@ -218,7 +220,7 @@ echo "COPYING boringssl" for pattern in "${PATTERNS[@]}" do for i in $SRCROOT/$pattern; do - path=${i#$SRCROOT} + path=${i#"$SRCROOT"} dest="$DSTROOT$path" dest_dir=$(dirname "$dest") mkdir -p "$dest_dir" @@ -255,6 +257,7 @@ echo "RENAMING header files" rmdir "include/openssl" # Now change the imports from " to "", apply the same prefix to the 'boringssl_prefix_symbols' headers. + # shellcheck disable=SC2038 find . -name "*.[ch]" -or -name "*.cc" -or -name "*.S" -or -name "*.c.inc" | xargs $sed -i -e 's+include +include "\1CCryptoBoringSSL_\2"+' popd ) @@ -274,6 +278,7 @@ echo "RENAMING header files" echo "PROTECTING against executable stacks" ( cd "$DSTROOT" + # shellcheck disable=SC2038 find . -name "*.S" | xargs $sed -i '$ a #if defined(__linux__) && defined(__ELF__)\n.section .note.GNU-stack,"",%progbits\n#endif\n' ) @@ -292,7 +297,7 @@ cat << EOF > "$DSTROOT/include/CCryptoBoringSSL.h" // Licensed under Apache License v2.0 // // See LICENSE.txt for license information -// See CONTRIBUTORS.md for the list of SwiftCrypto project authors +// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors // // SPDX-License-Identifier: Apache-2.0 //