From 75f90bccb981f1f5351612c55f9441091efa44bf Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 5 Sep 2021 22:21:20 -0400 Subject: [PATCH 01/10] Remove travis/all.py Broken since we switched away from Travis --- travis/all.py | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100755 travis/all.py diff --git a/travis/all.py b/travis/all.py deleted file mode 100755 index edd2eee18..000000000 --- a/travis/all.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python3 -import argparse, os, sys, time - -parser = argparse.ArgumentParser() -parser.add_argument('-n', '--dry-run', action='store_true', help='Display commands without running them') -args = parser.parse_args() - -red = '\x1b[31m\x1b[1m' -green = '\x1b[32m\x1b[1m' -reset = '\x1b(B\x1b[m' -if os.environ.get('TRAVIS', '') == 'true': - print('This script cannot be used in a travis build') - sys.exit(1) -os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -commands = [] -with open('.travis.yml') as f: - lines = list(f.readlines()) - script_found = False - for line in lines: - if line.startswith('script:'): - script_found = True - elif script_found: - if line.startswith('- '): - if line.startswith('- python '): - commands.append(line[2:].rstrip('\r\n')) - else: - break -ret = 0 -for cmd in commands: - print('$ %s' % cmd) - if args.dry_run: - continue - start = time.time() - code = os.system(cmd) - end = time.time() - if code != 0: - ret = 1 - print('\n%sThe command "%s" exited with %i.%s [%.3f secs]' % - (green if code == 0 else red, cmd, code, reset, end - start)) - -print('\nDone. Your build exited with %i.' % ret) -sys.exit(ret) From de241b47cca26fe2f44ceeca9b25e8eecb9d2e8a Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 5 Sep 2021 22:24:16 -0400 Subject: [PATCH 02/10] Check for CI env var instead of TRAVIS --- travis/lint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/lint.py b/travis/lint.py index 05aa28950..ef4f6d02d 100755 --- a/travis/lint.py +++ b/travis/lint.py @@ -81,7 +81,7 @@ class Linter(object): class NewlineLinter(Linter): msg = 'Contains DOS-style newlines' # git supports newline conversion. Catch in CI, ignore on Windows. - ignore = os.linesep != '\n' and not os.environ.get('TRAVIS') + ignore = os.linesep != '\n' and not os.environ.get('CI') def check_line(self, line): return '\r' not in line def fix_line(self, line): From cc6c82941543db03bd72f5192f39d1c37f9bbc46 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 5 Sep 2021 22:33:06 -0400 Subject: [PATCH 03/10] lint.py: fix --fix UTF-8 issues --- travis/lint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/lint.py b/travis/lint.py index ef4f6d02d..52716169b 100755 --- a/travis/lint.py +++ b/travis/lint.py @@ -143,7 +143,7 @@ def main(): linter.fix(lines) contents = '\n'.join(lines) with open(full_path, 'wb') as f: - f.write(contents) + f.write(contents.encode('utf-8')) if success: print('All linters completed successfully') From f876688a6a5cbdb780b52926382f8b04d57e621d Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 5 Sep 2021 22:44:42 -0400 Subject: [PATCH 04/10] lint.py: use argparse for argument processing --- .github/workflows/build.yml | 2 +- travis/lint.py | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 869ca407e..f53853eae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -147,7 +147,7 @@ jobs: # don't need tags here - name: Check whitespace run: | - python travis/lint.py + python travis/lint.py --github-actions - name: Check Authors.rst if: success() || failure() run: | diff --git a/travis/lint.py b/travis/lint.py index 52716169b..f93c4f1b3 100755 --- a/travis/lint.py +++ b/travis/lint.py @@ -1,5 +1,8 @@ #!/usr/bin/env python3 -import re, os, sys +import argparse +import re +import os +import sys valid_extensions = ['c', 'cpp', 'h', 'hpp', 'mm', 'lua', 'rb', 'proto', 'init', 'init-example', 'rst'] @@ -104,13 +107,12 @@ class TabLinter(Linter): linters = [cls() for cls in Linter.__subclasses__() if not cls.ignore] -def main(): - is_github_actions = bool(os.environ.get('GITHUB_ACTIONS')) - root_path = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else '.') - if not os.path.exists(root_path): +def main(args): + root_path = os.path.abspath(args.path) + if not os.path.exists(args.path): print('Nonexistent path: %s' % root_path) sys.exit(2) - fix = (len(sys.argv) > 2 and sys.argv[2] == '--fix') + global path_blacklist path_blacklist = list(map(lambda s: os.path.join(root_path, s.replace('^', '')) if s.startswith('^') else s, path_blacklist)) @@ -129,7 +131,7 @@ def main(): except UnicodeDecodeError: msg_params = (rel_path, i + 1, 'Invalid UTF-8 (other errors will be ignored)') error('%s:%i: %s' % msg_params) - if is_github_actions: + if args.github_actions: print('::error file=%s,line=%i::%s' % msg_params) lines[i] = '' for linter in linters: @@ -137,9 +139,9 @@ def main(): linter.check(lines) except LinterError as e: error('%s: %s' % (rel_path, e)) - if is_github_actions: + if args.github_actions: print(e.github_actions_workflow_command(rel_path)) - if fix: + if args.fix: linter.fix(lines) contents = '\n'.join(lines) with open(full_path, 'wb') as f: @@ -152,4 +154,12 @@ def main(): sys.exit(1) if __name__ == '__main__': - main() + parser = argparse.ArgumentParser() + parser.add_argument('path', nargs='?', default='.', + help='Path to scan (default: current directory)') + parser.add_argument('--fix', action='store_true', + help='Attempt to modify files in-place to fix identified issues') + parser.add_argument('--github-actions', action='store_true', + help='Enable GitHub Actions workflow command output') + args = parser.parse_args() + main(args) From 2ac3258ae88ddcb7da14fcd098397a6b32fecaa6 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 5 Sep 2021 22:48:41 -0400 Subject: [PATCH 05/10] Move travis/ scripts to ci/ --- .github/workflows/build.yml | 18 +++++++++--------- {travis => ci}/authors-rst.py | 0 {travis => ci}/build-lua.sh | 0 {travis => ci}/check-rpc.py | 0 {travis => ci}/download-df.sh | 0 {travis => ci}/get-df-version.sh | 0 {travis => ci}/lint.py | 0 {travis => ci}/run-tests.py | 0 {travis => ci}/script-docs.py | 0 {travis => ci}/script-syntax.py | 0 10 files changed, 9 insertions(+), 9 deletions(-) rename {travis => ci}/authors-rst.py (100%) rename {travis => ci}/build-lua.sh (100%) mode change 100644 => 100755 rename {travis => ci}/check-rpc.py (100%) rename {travis => ci}/download-df.sh (100%) rename {travis => ci}/get-df-version.sh (100%) rename {travis => ci}/lint.py (100%) rename {travis => ci}/run-tests.py (100%) rename {travis => ci}/script-docs.py (100%) rename {travis => ci}/script-syntax.py (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f53853eae..69703992b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,7 @@ jobs: - name: Set up environment id: env_setup run: | - DF_VERSION="$(sh travis/get-df-version.sh)" + DF_VERSION="$(sh ci/get-df-version.sh)" echo "::set-output name=df_version::${DF_VERSION}" echo "DF_VERSION=${DF_VERSION}" >> $GITHUB_ENV echo "DF_FOLDER=${HOME}/DF/${DF_VERSION}/df_linux" >> $GITHUB_ENV @@ -61,7 +61,7 @@ jobs: key: ${{ steps.env_setup.outputs.df_version }} - name: Download DF run: | - sh travis/download-df.sh + sh ci/download-df.sh - name: Build DFHack env: CC: gcc-${{ matrix.gcc }} @@ -84,8 +84,8 @@ jobs: run: | export TERM=dumb mv "$DF_FOLDER"/dfhack.init-example "$DF_FOLDER"/dfhack.init - script -qe -c "python travis/run-tests.py --headless --keep-status \"$DF_FOLDER\"" - python travis/check-rpc.py "$DF_FOLDER/dfhack-rpc.txt" + script -qe -c "python ci/run-tests.py --headless --keep-status \"$DF_FOLDER\"" + python ci/check-rpc.py "$DF_FOLDER/dfhack-rpc.txt" mkdir -p artifacts cp "$DF_FOLDER/test_status.json" "$DF_FOLDER"/*.log artifacts - name: Upload test artifacts @@ -147,23 +147,23 @@ jobs: # don't need tags here - name: Check whitespace run: | - python travis/lint.py --github-actions + python ci/lint.py --github-actions - name: Check Authors.rst if: success() || failure() run: | - python travis/authors-rst.py + python ci/authors-rst.py - name: Check for missing documentation if: success() || failure() run: | - python travis/script-docs.py + python ci/script-docs.py - name: Check Lua syntax if: success() || failure() run: | - python travis/script-syntax.py --ext=lua --cmd="luac5.3 -p" --github-actions + python ci/script-syntax.py --ext=lua --cmd="luac5.3 -p" --github-actions - name: Check Ruby syntax if: success() || failure() run: | - python travis/script-syntax.py --ext=rb --cmd="ruby -c" --github-actions + python ci/script-syntax.py --ext=rb --cmd="ruby -c" --github-actions check-pr: runs-on: ubuntu-latest diff --git a/travis/authors-rst.py b/ci/authors-rst.py similarity index 100% rename from travis/authors-rst.py rename to ci/authors-rst.py diff --git a/travis/build-lua.sh b/ci/build-lua.sh old mode 100644 new mode 100755 similarity index 100% rename from travis/build-lua.sh rename to ci/build-lua.sh diff --git a/travis/check-rpc.py b/ci/check-rpc.py similarity index 100% rename from travis/check-rpc.py rename to ci/check-rpc.py diff --git a/travis/download-df.sh b/ci/download-df.sh similarity index 100% rename from travis/download-df.sh rename to ci/download-df.sh diff --git a/travis/get-df-version.sh b/ci/get-df-version.sh similarity index 100% rename from travis/get-df-version.sh rename to ci/get-df-version.sh diff --git a/travis/lint.py b/ci/lint.py similarity index 100% rename from travis/lint.py rename to ci/lint.py diff --git a/travis/run-tests.py b/ci/run-tests.py similarity index 100% rename from travis/run-tests.py rename to ci/run-tests.py diff --git a/travis/script-docs.py b/ci/script-docs.py similarity index 100% rename from travis/script-docs.py rename to ci/script-docs.py diff --git a/travis/script-syntax.py b/ci/script-syntax.py similarity index 100% rename from travis/script-syntax.py rename to ci/script-syntax.py From 2f5cee1af1df158e305b255610a97ef2fdb3342d Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 5 Sep 2021 23:06:29 -0400 Subject: [PATCH 06/10] Add stubs in travis/ to call ci/ scripts --- travis/authors-rst.py | 14 ++++++++++++++ travis/buildmaster-rebuild-pr.py | 14 ++++++++++++++ travis/check-rpc.py | 14 ++++++++++++++ travis/download-df.sh | 9 +++++++++ travis/get-df-version.sh | 9 +++++++++ travis/lint.py | 14 ++++++++++++++ travis/run-tests.py | 14 ++++++++++++++ travis/script-docs.py | 14 ++++++++++++++ travis/script-syntax.py | 14 ++++++++++++++ 9 files changed, 116 insertions(+) create mode 100755 travis/authors-rst.py create mode 100755 travis/buildmaster-rebuild-pr.py create mode 100755 travis/check-rpc.py create mode 100755 travis/download-df.sh create mode 100755 travis/get-df-version.sh create mode 100755 travis/lint.py create mode 100755 travis/run-tests.py create mode 100755 travis/script-docs.py create mode 100755 travis/script-syntax.py diff --git a/travis/authors-rst.py b/travis/authors-rst.py new file mode 100755 index 000000000..cf52385b5 --- /dev/null +++ b/travis/authors-rst.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import os +import subprocess +import sys + +script_name = os.path.basename(__file__) +new_script_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'ci', script_name) + +sys.stderr.write('\nNote: travis/{script_name} is deprecated. Use ci/{script_name} instead.\n\n'.format(script_name=script_name)) +sys.stderr.flush() + +p = subprocess.run([sys.executable, new_script_path] + sys.argv[1:]) +sys.exit(p.returncode) diff --git a/travis/buildmaster-rebuild-pr.py b/travis/buildmaster-rebuild-pr.py new file mode 100755 index 000000000..cf52385b5 --- /dev/null +++ b/travis/buildmaster-rebuild-pr.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import os +import subprocess +import sys + +script_name = os.path.basename(__file__) +new_script_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'ci', script_name) + +sys.stderr.write('\nNote: travis/{script_name} is deprecated. Use ci/{script_name} instead.\n\n'.format(script_name=script_name)) +sys.stderr.flush() + +p = subprocess.run([sys.executable, new_script_path] + sys.argv[1:]) +sys.exit(p.returncode) diff --git a/travis/check-rpc.py b/travis/check-rpc.py new file mode 100755 index 000000000..cf52385b5 --- /dev/null +++ b/travis/check-rpc.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import os +import subprocess +import sys + +script_name = os.path.basename(__file__) +new_script_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'ci', script_name) + +sys.stderr.write('\nNote: travis/{script_name} is deprecated. Use ci/{script_name} instead.\n\n'.format(script_name=script_name)) +sys.stderr.flush() + +p = subprocess.run([sys.executable, new_script_path] + sys.argv[1:]) +sys.exit(p.returncode) diff --git a/travis/download-df.sh b/travis/download-df.sh new file mode 100755 index 000000000..aec2d6d99 --- /dev/null +++ b/travis/download-df.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +script_name="$(basename "$0")" +new_script_path="$(dirname "$0")/../ci/${script_name}" + +printf >&2 "\nNote: travis/%s is deprecated. Use ci/%s instead.\n\n" "${script_name}" "${script_name}" + +"${new_script_path}" "$@" +exit $? diff --git a/travis/get-df-version.sh b/travis/get-df-version.sh new file mode 100755 index 000000000..aec2d6d99 --- /dev/null +++ b/travis/get-df-version.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +script_name="$(basename "$0")" +new_script_path="$(dirname "$0")/../ci/${script_name}" + +printf >&2 "\nNote: travis/%s is deprecated. Use ci/%s instead.\n\n" "${script_name}" "${script_name}" + +"${new_script_path}" "$@" +exit $? diff --git a/travis/lint.py b/travis/lint.py new file mode 100755 index 000000000..cf52385b5 --- /dev/null +++ b/travis/lint.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import os +import subprocess +import sys + +script_name = os.path.basename(__file__) +new_script_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'ci', script_name) + +sys.stderr.write('\nNote: travis/{script_name} is deprecated. Use ci/{script_name} instead.\n\n'.format(script_name=script_name)) +sys.stderr.flush() + +p = subprocess.run([sys.executable, new_script_path] + sys.argv[1:]) +sys.exit(p.returncode) diff --git a/travis/run-tests.py b/travis/run-tests.py new file mode 100755 index 000000000..cf52385b5 --- /dev/null +++ b/travis/run-tests.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import os +import subprocess +import sys + +script_name = os.path.basename(__file__) +new_script_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'ci', script_name) + +sys.stderr.write('\nNote: travis/{script_name} is deprecated. Use ci/{script_name} instead.\n\n'.format(script_name=script_name)) +sys.stderr.flush() + +p = subprocess.run([sys.executable, new_script_path] + sys.argv[1:]) +sys.exit(p.returncode) diff --git a/travis/script-docs.py b/travis/script-docs.py new file mode 100755 index 000000000..cf52385b5 --- /dev/null +++ b/travis/script-docs.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import os +import subprocess +import sys + +script_name = os.path.basename(__file__) +new_script_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'ci', script_name) + +sys.stderr.write('\nNote: travis/{script_name} is deprecated. Use ci/{script_name} instead.\n\n'.format(script_name=script_name)) +sys.stderr.flush() + +p = subprocess.run([sys.executable, new_script_path] + sys.argv[1:]) +sys.exit(p.returncode) diff --git a/travis/script-syntax.py b/travis/script-syntax.py new file mode 100755 index 000000000..cf52385b5 --- /dev/null +++ b/travis/script-syntax.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import os +import subprocess +import sys + +script_name = os.path.basename(__file__) +new_script_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'ci', script_name) + +sys.stderr.write('\nNote: travis/{script_name} is deprecated. Use ci/{script_name} instead.\n\n'.format(script_name=script_name)) +sys.stderr.flush() + +p = subprocess.run([sys.executable, new_script_path] + sys.argv[1:]) +sys.exit(p.returncode) From 3e26618004294aa289eeff40702a8774318b6789 Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 6 Sep 2021 18:22:59 -0400 Subject: [PATCH 07/10] lint.py: make check/ignore logic more flexible, move patterns to files --- ci/lint-check.txt | 11 ++++++++++ ci/lint-ignore.txt | 8 +++++++ ci/lint.py | 52 ++++++++++++++++++++++++++++------------------ 3 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 ci/lint-check.txt create mode 100644 ci/lint-ignore.txt diff --git a/ci/lint-check.txt b/ci/lint-check.txt new file mode 100644 index 000000000..926577e62 --- /dev/null +++ b/ci/lint-check.txt @@ -0,0 +1,11 @@ +*.c +*.cpp +*.h +*.hpp +*.init +*.init-example +*.lua +*.mm +*.proto +*.rb +*.rst diff --git a/ci/lint-ignore.txt b/ci/lint-ignore.txt new file mode 100644 index 000000000..c8c5fcd3e --- /dev/null +++ b/ci/lint-ignore.txt @@ -0,0 +1,8 @@ +library/include/df/* +plugins/stonesense/allegro/* +plugins/isoworld/allegro/* +plugins/isoworld/agui/* +depends/* +.git/* +build*/* +*.pb.h diff --git a/ci/lint.py b/ci/lint.py index f93c4f1b3..56735faeb 100755 --- a/ci/lint.py +++ b/ci/lint.py @@ -1,25 +1,27 @@ #!/usr/bin/env python3 import argparse +import fnmatch import re import os import sys -valid_extensions = ['c', 'cpp', 'h', 'hpp', 'mm', 'lua', 'rb', 'proto', - 'init', 'init-example', 'rst'] -path_blacklist = [ - '^library/include/df/', - '^plugins/stonesense/allegro', - '^plugins/isoworld/allegro', - '^plugins/isoworld/agui', - '^depends/', - '^.git/', - '^build', - '.pb.h', -] - -def valid_file(filename): - return len(list(filter(lambda ext: filename.endswith('.' + ext), valid_extensions))) and \ - not len(list(filter(lambda path: path.replace('\\', '/') in filename.replace('\\', '/'), path_blacklist))) +DFHACK_ROOT = os.path.normpath(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +def load_pattern_files(paths): + patterns = [] + for p in paths: + with open(p) as f: + for line in f.readlines(): + line = line.strip() + if line and not line.startswith('#'): + patterns.append(line) + return patterns + +def valid_file(rel_path, check_patterns, ignore_patterns): + return ( + any(fnmatch.fnmatch(rel_path, pattern) for pattern in check_patterns) + and not any(fnmatch.fnmatch(rel_path, pattern) for pattern in ignore_patterns) + ) success = True def error(msg=None): @@ -113,15 +115,17 @@ def main(args): print('Nonexistent path: %s' % root_path) sys.exit(2) - global path_blacklist - path_blacklist = list(map(lambda s: os.path.join(root_path, s.replace('^', '')) if s.startswith('^') else s, path_blacklist)) + check_patterns = load_pattern_files(args.check_patterns) + ignore_patterns = load_pattern_files(args.ignore_patterns) for cur, dirnames, filenames in os.walk(root_path): for filename in filenames: full_path = os.path.join(cur, filename) - rel_path = full_path.replace(root_path, '.') - if not valid_file(full_path): + rel_path = full_path.replace(root_path, '').replace('\\', '/').lstrip('/') + if not valid_file(rel_path, check_patterns, ignore_patterns): continue + if args.verbose: + print('Checking:', rel_path) lines = [] with open(full_path, 'rb') as f: lines = f.read().split(b'\n') @@ -161,5 +165,13 @@ if __name__ == '__main__': help='Attempt to modify files in-place to fix identified issues') parser.add_argument('--github-actions', action='store_true', help='Enable GitHub Actions workflow command output') + parser.add_argument('-v', '--verbose', action='store_true', + help='Log files as they are checked') + parser.add_argument('--check-patterns', action='append', + default=[os.path.join(DFHACK_ROOT, 'ci', 'lint-check.txt')], + help='File(s) containing filename patterns to check') + parser.add_argument('--ignore-patterns', action='append', + default=[os.path.join(DFHACK_ROOT, 'ci', 'lint-ignore.txt')], + help='File(s) containing filename patterns to ignore') args = parser.parse_args() main(args) From 11222f21d3ad52c2078cf07d7f9bd2ca45793c26 Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 6 Sep 2021 18:42:45 -0400 Subject: [PATCH 08/10] Update lint.py filters and fix a couple identified issues --- ci/lint-check.txt | 21 +++++++++++++++++++++ ci/lint-ignore.txt | 27 +++++++++++++++++++++------ package/windows/sdl license.txt | 16 ++++++++-------- plugins/rendermax/CMakeLists.txt | 4 ++-- plugins/ruby/codegen.pl | 2 +- 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/ci/lint-check.txt b/ci/lint-check.txt index 926577e62..bdfa74365 100644 --- a/ci/lint-check.txt +++ b/ci/lint-check.txt @@ -1,11 +1,32 @@ +# Files that lint.py should check + +*.bash +*.bat *.c +*.cc +*.cmake *.cpp +*.css +*.gitignore *.h +*.hh *.hpp +*.in +*.inc *.init *.init-example +*.js *.lua +*.manifest +*.md *.mm +*.pl *.proto +*.py *.rb *.rst +*.sh +*.txt +*.vbs +*.yaml +*.yml diff --git a/ci/lint-ignore.txt b/ci/lint-ignore.txt index c8c5fcd3e..ee68f67b8 100644 --- a/ci/lint-ignore.txt +++ b/ci/lint-ignore.txt @@ -1,8 +1,23 @@ -library/include/df/* -plugins/stonesense/allegro/* -plugins/isoworld/allegro/* -plugins/isoworld/agui/* -depends/* +# Files that lint.py should ignore + .git/* -build*/* + +# Old files exempt from checks for now +plugins/isoworld/*.txt +plugins/raw/*.txt +plugins/stonesense/*.txt +plugins/stonesense/utilities/* + +# Generated files *.pb.h +build*/* +docs/_* +docs/html/* +docs/pdf/* +library/include/df/* + +# Dependencies that we don't control +depends/* +plugins/isoworld/agui/* +plugins/isoworld/allegro/* +plugins/stonesense/allegro/* diff --git a/package/windows/sdl license.txt b/package/windows/sdl license.txt index e819febfb..4362b4915 100644 --- a/package/windows/sdl license.txt +++ b/package/windows/sdl license.txt @@ -1,5 +1,5 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -10,7 +10,7 @@ as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] - Preamble + Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public @@ -112,7 +112,7 @@ modification follow. Pay close attention to the difference between a former contains code derived from the library, whereas the latter must be combined with the library in order to run. - GNU LESSER GENERAL PUBLIC LICENSE + GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other @@ -146,7 +146,7 @@ such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. - + 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an @@ -432,7 +432,7 @@ decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. - NO WARRANTY + NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. @@ -455,7 +455,7 @@ FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - END OF TERMS AND CONDITIONS + END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries @@ -499,4 +499,4 @@ necessary. Here is a sample; alter the names: , 1 April 1990 Ty Coon, President of Vice -That's all there is to it! \ No newline at end of file +That's all there is to it! diff --git a/plugins/rendermax/CMakeLists.txt b/plugins/rendermax/CMakeLists.txt index 651fb1e06..349bae13b 100644 --- a/plugins/rendermax/CMakeLists.txt +++ b/plugins/rendermax/CMakeLists.txt @@ -3,12 +3,12 @@ project(rendermax) # A list of source files set(PROJECT_SRCS rendermax.cpp - renderer_light.cpp + renderer_light.cpp ) # A list of headers set(PROJECT_HDRS renderer_opengl.hpp - renderer_light.hpp + renderer_light.hpp ) set_source_files_properties(${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE) diff --git a/plugins/ruby/codegen.pl b/plugins/ruby/codegen.pl index 535a49694..95d91c3ab 100755 --- a/plugins/ruby/codegen.pl +++ b/plugins/ruby/codegen.pl @@ -787,7 +787,7 @@ sub sizeof { } elsif ($subtype eq 'df-linked-list') { return 3 * $SIZEOF_PTR; } elsif ($subtype eq 'df-flagarray') { - return 2 * $SIZEOF_PTR; # XXX length may be 4 on windows? + return 2 * $SIZEOF_PTR; # XXX length may be 4 on windows? } elsif ($subtype eq 'df-static-flagarray') { return $field->getAttribute('count'); } elsif ($subtype eq 'df-array') { From 5dfb633db8017e57703077a5be4894545c090d96 Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 6 Sep 2021 18:59:08 -0400 Subject: [PATCH 09/10] lint.py: add option to only check tracked files --- .github/workflows/build.yml | 2 +- ci/lint.py | 80 +++++++++++++++++++++++-------------- 2 files changed, 51 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 69703992b..14361daeb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -147,7 +147,7 @@ jobs: # don't need tags here - name: Check whitespace run: | - python ci/lint.py --github-actions + python ci/lint.py --git-only --github-actions - name: Check Authors.rst if: success() || failure() run: | diff --git a/ci/lint.py b/ci/lint.py index 56735faeb..b2fb8e647 100755 --- a/ci/lint.py +++ b/ci/lint.py @@ -3,6 +3,7 @@ import argparse import fnmatch import re import os +import subprocess import sys DFHACK_ROOT = os.path.normpath(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) @@ -109,6 +110,21 @@ class TabLinter(Linter): linters = [cls() for cls in Linter.__subclasses__() if not cls.ignore] +def walk_all(root_path): + for cur, dirnames, filenames in os.walk(root_path): + for filename in filenames: + full_path = os.path.join(cur, filename) + yield full_path + +def walk_git_files(root_path): + p = subprocess.Popen(['git', '-C', root_path, 'ls-files', root_path], stdout=subprocess.PIPE) + for line in p.stdout.readlines(): + path = line.decode('utf-8').strip() + full_path = os.path.join(root_path, path) + yield full_path + if p.wait() != 0: + raise RuntimeError('git exited with %r' % p.returncode) + def main(args): root_path = os.path.abspath(args.path) if not os.path.exists(args.path): @@ -118,38 +134,40 @@ def main(args): check_patterns = load_pattern_files(args.check_patterns) ignore_patterns = load_pattern_files(args.ignore_patterns) - for cur, dirnames, filenames in os.walk(root_path): - for filename in filenames: - full_path = os.path.join(cur, filename) - rel_path = full_path.replace(root_path, '').replace('\\', '/').lstrip('/') - if not valid_file(rel_path, check_patterns, ignore_patterns): - continue - if args.verbose: - print('Checking:', rel_path) - lines = [] - with open(full_path, 'rb') as f: - lines = f.read().split(b'\n') - for i, line in enumerate(lines): - try: - lines[i] = line.decode('utf-8') - except UnicodeDecodeError: - msg_params = (rel_path, i + 1, 'Invalid UTF-8 (other errors will be ignored)') - error('%s:%i: %s' % msg_params) - if args.github_actions: - print('::error file=%s,line=%i::%s' % msg_params) - lines[i] = '' - for linter in linters: + walk_iter = walk_all + if args.git_only: + walk_iter = walk_git_files + + for full_path in walk_iter(root_path): + rel_path = full_path.replace(root_path, '').replace('\\', '/').lstrip('/') + if not valid_file(rel_path, check_patterns, ignore_patterns): + continue + if args.verbose: + print('Checking:', rel_path) + lines = [] + with open(full_path, 'rb') as f: + lines = f.read().split(b'\n') + for i, line in enumerate(lines): try: - linter.check(lines) - except LinterError as e: - error('%s: %s' % (rel_path, e)) + lines[i] = line.decode('utf-8') + except UnicodeDecodeError: + msg_params = (rel_path, i + 1, 'Invalid UTF-8 (other errors will be ignored)') + error('%s:%i: %s' % msg_params) if args.github_actions: - print(e.github_actions_workflow_command(rel_path)) - if args.fix: - linter.fix(lines) - contents = '\n'.join(lines) - with open(full_path, 'wb') as f: - f.write(contents.encode('utf-8')) + print('::error file=%s,line=%i::%s' % msg_params) + lines[i] = '' + for linter in linters: + try: + linter.check(lines) + except LinterError as e: + error('%s: %s' % (rel_path, e)) + if args.github_actions: + print(e.github_actions_workflow_command(rel_path)) + if args.fix: + linter.fix(lines) + contents = '\n'.join(lines) + with open(full_path, 'wb') as f: + f.write(contents.encode('utf-8')) if success: print('All linters completed successfully') @@ -163,6 +181,8 @@ if __name__ == '__main__': help='Path to scan (default: current directory)') parser.add_argument('--fix', action='store_true', help='Attempt to modify files in-place to fix identified issues') + parser.add_argument('--git-only', action='store_true', + help='Only check files tracked by git') parser.add_argument('--github-actions', action='store_true', help='Enable GitHub Actions workflow command output') parser.add_argument('-v', '--verbose', action='store_true', From e5487c812a2d5b92a875849755ff0b76709e6140 Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 6 Sep 2021 19:08:22 -0400 Subject: [PATCH 10/10] Update stonesense lint filter --- ci/lint-ignore.txt | 1 - plugins/stonesense | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/lint-ignore.txt b/ci/lint-ignore.txt index ee68f67b8..d384b80f3 100644 --- a/ci/lint-ignore.txt +++ b/ci/lint-ignore.txt @@ -6,7 +6,6 @@ plugins/isoworld/*.txt plugins/raw/*.txt plugins/stonesense/*.txt -plugins/stonesense/utilities/* # Generated files *.pb.h diff --git a/plugins/stonesense b/plugins/stonesense index d81cb598e..296ba91c2 160000 --- a/plugins/stonesense +++ b/plugins/stonesense @@ -1 +1 @@ -Subproject commit d81cb598e7aa179bc85440d3ba06ef6ec119815f +Subproject commit 296ba91c2d7e3b011895df17caa032e90a27e186