aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--smolbote.qbs2
-rwxr-xr-xtools/hooks/pre-commit.rb23
-rw-r--r--tools/qbs/GitRepo.js (renamed from qbs/GitRepo.js)0
-rw-r--r--util/header-gpl3.txt20
-rwxr-xr-xutil/license.py74
-rwxr-xr-xutil/pre-commit.py36
6 files changed, 24 insertions, 131 deletions
diff --git a/smolbote.qbs b/smolbote.qbs
index 236c6da..e58bb1c 100644
--- a/smolbote.qbs
+++ b/smolbote.qbs
@@ -1,5 +1,5 @@
import qbs
-import "qbs/GitRepo.js" as GitRepo
+import "tools/qbs/GitRepo.js" as GitRepo
Project {
id: project
diff --git a/tools/hooks/pre-commit.rb b/tools/hooks/pre-commit.rb
new file mode 100755
index 0000000..83b4978
--- /dev/null
+++ b/tools/hooks/pre-commit.rb
@@ -0,0 +1,23 @@
+#!/usr/bin/env ruby
+
+result = 0
+files = Dir['src/**/*.h'] + Dir['src/**/*.cpp'] - Dir['src/3rd-party/**/*']
+
+puts 'Checking licenses...'
+files.each { |name|
+ File.open(name) { |f|
+ if not f.readline.start_with? '/** LICENSE **' then
+ puts "Missing license header: #{name}"
+ result = 1
+ end
+ }
+}
+
+puts 'Checking style...'
+if not `astyle --dry-run --formatted --options=astyle.rc #{files.join(' ')}`.empty? then
+ system "astyle --verbose --formatted --options=astyle.rc #{files.join(' ')}"
+ result = 1
+end
+
+puts "pre-commit exit(#{result})"
+exit result
diff --git a/qbs/GitRepo.js b/tools/qbs/GitRepo.js
index d7e19a7..d7e19a7 100644
--- a/qbs/GitRepo.js
+++ b/tools/qbs/GitRepo.js
diff --git a/util/header-gpl3.txt b/util/header-gpl3.txt
deleted file mode 100644
index a44bbfe..0000000
--- a/util/header-gpl3.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-/** LICENSE ********************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) $CURRENTYEAR$ Xian Nox
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
diff --git a/util/license.py b/util/license.py
deleted file mode 100755
index 0bbc6be..0000000
--- a/util/license.py
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/usr/bin/env python3
-
-import argparse
-import datetime
-import sys
-
-def readLicense(licenseFile):
- with open(licenseFile) as rawlicense:
- licensetext = rawlicense.read()
-
- # fill in the year
- licensetext = licensetext.replace('$CURRENTYEAR$', str(datetime.datetime.now().year))
-
- return licensetext
-
-def hasLicense(sourceFile):
- with open(sourceFile) as source:
- if source.readline().startswith('/** LICENSE **'):
- return True
- else:
- return False
-
-def addLicense(sourceFile, licenseText):
- with open(sourceFile, 'r') as source:
- origData = source.read()
- with open(sourceFile, 'w') as source:
- source.write(licenseText + origData)
-
-def lint(license, src, dryRun, verbose=False):
- if verbose is True:
- print("license={0}".format(license))
- print("source={0}".format(src))
-
- # read license file
- licensetext = readLicense(license)
- if verbose is True:
- print("-- license text --")
- print(licensetext)
- print("-- license text --")
-
- if len(src) is 0:
- print("No files to process.")
- return 0
-
- # open source file and check for license
- numFaults = 0
- for filename in src:
- if hasLicense(filename) is True:
- if verbose:
- print("OK {0}".format(filename))
- else:
- if dryRun is True:
- if verbose:
- print("fail {0}".format(filename))
- else:
- addLicense(filename, licensetext)
- print("fix {0}".format(filename))
-
- numFaults += 1
-
- if numFaults is not 0:
- print("License check: number of faults: {0}".format(numFaults))
-
- return numFaults
-
-if __name__ == '__main__':
- parser = argparse.ArgumentParser(description='check source files for license')
- parser.add_argument('-l', '--license', required=True, help="use this file as license header template")
- parser.add_argument('-v', '--verbose', action='store_true', help="print additional information")
- parser.add_argument('-c', '--dry-run', action='store_true', help="don't modify any files, only check for licenses")
- parser.add_argument('src', nargs='*', help="list of files to check")
- args = parser.parse_args()
-
- sys.exit(lint(args.license, args.src, args.dry_run, args.verbose))
diff --git a/util/pre-commit.py b/util/pre-commit.py
deleted file mode 100755
index ca1dc35..0000000
--- a/util/pre-commit.py
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/usr/bin/env python3
-
-import os
-import sys
-import subprocess
-import glob
-import license
-
-# stash unstaged files before running test
-#os.system("git stash -q --keep-index")
-
-#print("Running pre-commit hook in {0}".format(os.getcwd()))
-problems = False
-
-# check license
-print("Checking license...")
-if license.lint("util/header-gpl3.txt", glob.glob("src/**/*.cpp") + glob.glob("src/**/*.h"), True) > 0:
- problems = True
- print("Run <<./util/license.py -l util/header-gpl3.txt src/**/*.cpp src/**/*.h>> to autofix")
-
-# check style
-print("Checking style...")
-astyle = subprocess.run(['astyle', '--dry-run', '--formatted', '--options=astyle.rc'] + glob.glob("src/**/*.cpp") + glob.glob("src/**/*.h"), stdout=subprocess.PIPE)
-if len(astyle.stdout.splitlines()) > 0:
- problems = True
- for line in astyle.stdout.splitlines():
- print(line.decode('utf-8'))
- print("Run <<astyle --options=astyle.rc --suffix=none src/**/*.cpp src/**/*.h>> to autofix")
-
-# restore stash
-#os.system("git stash pop -q")
-
-if problems:
- sys.exit(-1)
-else:
- sys.exit(0)