Util script cleanup; Enable pre-commit hook

pull/37/head
Andre Richter 5 years ago
parent b2219ca520
commit 3dc450bb44
No known key found for this signature in database
GPG Key ID: 2116C1AB102F615E

@ -1,25 +1,18 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative '../utils/helpers/copyrighted'
# SPDX-License-Identifier: MIT
#
# Copyright (c) 2018-2019 Andre Richter <andre.o.richter@gmail.com>
puts "Warning, git pre-commit hooks temporarily disabled!"
exit
require_relative '../utils/helpers/copyrighted'
source_files_exts = ['.S', '.rs', '.rb']
staged_files = `git --no-pager diff --name-only --cached`.split(/\n/)
need_inspection = []
staged_files.each do |f|
puts f
need_inspection << f if
f.include?('Makefile') || source_files_exts.include?(File.extname(f))
if f.include?('Makefile') || source_files_exts.include?(File.extname(f))
puts "Checking for copyright range: #{f}"
exit 1 unless copyrighted?(f, true)
end
end
error = false
need_inspection.each do |f|
error = true unless copyrighted?(f, true)
end
exit 1 if error

@ -262,19 +262,6 @@ make chainbot
## Diff to previous
```diff
diff -uNr 10_privilege_level/Makefile 11_virtual_memory/Makefile
--- 10_privilege_level/Makefile
+++ 11_virtual_memory/Makefile
@@ -17,7 +17,7 @@
OPENOCD_ARG = -f /openocd/tcl/interface/ftdi/olimex-arm-usb-tiny-h.cfg -f /openocd/rpi3.cfg
JTAG_BOOT_IMAGE = jtag_boot_rpi3.img
LINKER_FILE = src/bsp/rpi/link.ld
- RUSTC_MISC_ARGS = -C target-cpu=cortex-a53
+ RUSTC_MISC_ARGS = -C target-cpu=cortex-a53 -C llvm-args=-ffixed-x18
else ifeq ($(BSP),rpi4)
TARGET = aarch64-unknown-none-softfloat
OUTPUT = kernel8.img
diff -uNr 10_privilege_level/src/arch/aarch64/mmu.rs 11_virtual_memory/src/arch/aarch64/mmu.rs
--- 10_privilege_level/src/arch/aarch64/mmu.rs
+++ 11_virtual_memory/src/arch/aarch64/mmu.rs

@ -15,7 +15,7 @@ def clean_all
x = File.dirname(x)
Dir.chdir(x) do
puts "Cleaning #{x}"
system('rm -rf target') || exit(1)
FileUtils.rm_rf('target')
end
end

@ -18,7 +18,6 @@ def fmt_all(check = false)
crates.each do |x|
x = File.dirname(x)
Dir.chdir(x) do
puts "Format #{x}"
unless system("cargo fmt #{args}")

@ -11,33 +11,40 @@ def checkin_years(file)
checkin_years.split(/\n/).map!(&:to_i)
end
def copyrighted?(file, is_being_checked_in)
def parse_checkin_years(file, is_being_checked_in)
checkin_years = checkin_years(file)
checkin_years << Time.now.year if is_being_checked_in
checkin_min = checkin_years.min
checkin_max = checkin_years.max
copyright_lines = File.readlines(file).grep(/.*Copyright.*/)
checkin_years.minmax
end
def min_max_seen?(copyright_lines, checkin_min, checkin_max)
min_seen = false
max_seen = false
copyright_lines.each do |x|
x.scan(/\d\d\d\d/).each do |y|
y = y.to_i
x.scan(/\d\d\d\d/).map!(&:to_i).each do |y|
min_seen = true if y == checkin_min
max_seen = true if y == checkin_max
end
end
unless min_seen && max_seen
puts file + ': '
puts "\tHeader: " + copyright_lines.inspect
puts "\tMin year: " + checkin_min.to_s
puts "\tMax year: " + checkin_max.to_s
[min_seen, max_seen]
end
def print_on_err(file, copyright_lines, checkin_min, checkin_max)
puts file + ': '
puts "\tHeader: " + copyright_lines.inspect
puts "\tMin year: " + checkin_min.to_s
puts "\tMax year: " + checkin_max.to_s
end
def copyrighted?(file, is_being_checked_in)
checkin_min, checkin_max = parse_checkin_years(file, is_being_checked_in)
copyright_lines = File.readlines(file).grep(/.*Copyright.*/)
min_seen, max_seen = min_max_seen?(copyright_lines, checkin_min, checkin_max)
unless min_seen && max_seen
print_on_err(file, copyright_lines, checkin_min, checkin_max)
return false
end

@ -20,20 +20,17 @@ def patched?
end
def check_old_copyrights
error = false
sources = Dir.glob('**/*.{S,rs,rb}') + Dir.glob('**/Makefile')
sources.delete_if do |x|
# if x is not in the index, treat this as an error
!system("git ls-files --error-unmatch #{x}", %i[out err] => File::NULL)
end
sources.sort.reverse_each do |f|
sources.sort.each do |f|
puts "Checking for copyright: #{f}"
error = true unless copyrighted?(f, false)
exit(1) unless copyrighted?(f, false)
end
exit(1) if error
end
def sanity_checks

Loading…
Cancel
Save