From 401123b44bc4d41300711864be985abc513a0319 Mon Sep 17 00:00:00 2001 From: Mike Bishop Date: Thu, 16 Nov 2017 18:17:22 +0800 Subject: [PATCH 1/4] Make lint faster --- .gitignore | 1 + Makefile | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index f5de85b1be..c598493d52 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ pulls.json lib .targets.mk *.upload +.lintcache diff --git a/Makefile b/Makefile index d2e18a6747..a28d387972 100644 --- a/Makefile +++ b/Makefile @@ -15,14 +15,33 @@ endif latest:: lint .PHONY: lint lint:: - @err=0; for f in draft-*.md ; do \ - if cat "$$f" | (l=0; while read -r a; do l=$$(($$l + 1)); echo -E "$$l:$$a"; done) | \ - sed -e '1,/--- abstract/d;/^[0-9]*: *|/d' | tr -d '\r' | grep '^[0-9]*:.\{81\}'; then \ - echo "$$f contains a line with >80 characters"; err=1; \ - fi; \ - if cat "$$f" | (l=0; while read -r a; do l=$$(($$l + 1)); echo -E "$$l:$$a"; done) | \ - sed -e '/^[0-9]*:~~~/,/^[0-9]*:~~~/p;/^[0-9]*:```/,/^[0-9]*:```/p;d' | \ - tr -d '\r' | grep '^[0-9]*:.\{66\}'; then \ - echo "$$f contains a figure with >65 characters"; err=1; \ - fi; \ + + @err=0; \ + lint_dir=".lintcache/`git rev-parse --abbrev-ref HEAD`"; \ + if [ -d "$$lint_dir" ]; then \ + MAYBE_OBSOLETE=`comm -13 <(git branch | sed -e 's,.*[ /],,' | sort | uniq) <(ls ".lintcache" | sed -e 's,.*/,,')`; \ + for item in $$MAYBE_OBSOLETE; do \ + rm -rf ".lintcache/$$item"; \ + done \ + fi; \ + for f in draft-*.md ; do \ + localerr=0; \ + hash=`git hash-object "$$f"`; \ + lint_file="$$lint_dir/$$f"; \ + mkdir -p "$$lint_dir"; \ + if [ ! -r "$$lint_file" ] || [ "`cat "$$lint_file"`" != "$$hash" ]; then \ + if cat "$$f" | (l=0; while read -r a; do l=$$(($$l + 1)); echo -E "$$l:$$a"; done) | \ + sed -e '1,/--- abstract/d;/^[0-9]*: *|/d' | tr -d '\r' | grep '^[0-9]*:.\{81\}'; then \ + echo "$$f contains a line with >80 characters"; localerr=1; \ + fi; \ + if cat "$$f" | (l=0; while read -r a; do l=$$(($$l + 1)); echo -E "$$l:$$a"; done) | \ + sed -e '/^[0-9]*:~~~/,/^[0-9]*:~~~/p;/^[0-9]*:```/,/^[0-9]*:```/p;d' | \ + tr -d '\r' | grep '^[0-9]*:.\{66\}'; then \ + echo "$$f contains a figure with >65 characters"; localerr=1; \ + fi; \ + if [ "$$localerr" -eq 1 ]; then err=1; \ + else \ + echo "$$hash" > "$$lint_file"; \ + fi; \ + fi; \ done; [ "$$err" -eq 0 ] From 6b3c15fe58c6ea9348e4391f74870ae4a74d315e Mon Sep 17 00:00:00 2001 From: Mike Bishop Date: Fri, 17 Nov 2017 15:36:44 +0800 Subject: [PATCH 2/4] Use Makefile to manage lint cache --- Makefile | 88 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index a28d387972..946936426f 100644 --- a/Makefile +++ b/Makefile @@ -12,36 +12,66 @@ else -b master https://github.com/martinthomson/i-d-template $(LIBDIR) endif +CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) +LINT_DIR := .lintcache/$(CURRENT_BRANCH) + +lint_files:= $(addprefix $(LINT_DIR)/,$(addsuffix .lint,$(drafts))) + latest:: lint -.PHONY: lint -lint:: - - @err=0; \ - lint_dir=".lintcache/`git rev-parse --abbrev-ref HEAD`"; \ - if [ -d "$$lint_dir" ]; then \ - MAYBE_OBSOLETE=`comm -13 <(git branch | sed -e 's,.*[ /],,' | sort | uniq) <(ls ".lintcache" | sed -e 's,.*/,,')`; \ - for item in $$MAYBE_OBSOLETE; do \ - rm -rf ".lintcache/$$item"; \ - done \ - fi; \ - for f in draft-*.md ; do \ - localerr=0; \ - hash=`git hash-object "$$f"`; \ - lint_file="$$lint_dir/$$f"; \ - mkdir -p "$$lint_dir"; \ - if [ ! -r "$$lint_file" ] || [ "`cat "$$lint_file"`" != "$$hash" ]; then \ - if cat "$$f" | (l=0; while read -r a; do l=$$(($$l + 1)); echo -E "$$l:$$a"; done) | \ - sed -e '1,/--- abstract/d;/^[0-9]*: *|/d' | tr -d '\r' | grep '^[0-9]*:.\{81\}'; then \ - echo "$$f contains a line with >80 characters"; localerr=1; \ - fi; \ - if cat "$$f" | (l=0; while read -r a; do l=$$(($$l + 1)); echo -E "$$l:$$a"; done) | \ - sed -e '/^[0-9]*:~~~/,/^[0-9]*:~~~/p;/^[0-9]*:```/,/^[0-9]*:```/p;d' | \ - tr -d '\r' | grep '^[0-9]*:.\{66\}'; then \ - echo "$$f contains a figure with >65 characters"; localerr=1; \ +lint:: lint-purge $(lint_files) + +.PHONY: lint lint-purge + +$(LINT_DIR):: + @mkdir -p $(LINT_DIR) + +$(LINT_DIR)/%.lint: %.md $(LINT_DIR) + @hash=`git hash-object "$<"`; \ + if [ -r "$@" ] && [ "`cat '$@'`" == "$$hash" ]; then \ + touch "$@"; \ + echo "Reused lint of $<"; \ + else \ + for draft_lint in $(LINT_DIR)/*.lint; do \ + if [ -r "$$draft_lint" ] && [ "`cat "$$draft_lint"`" == "$$hash" ]; then \ + cp "$$draft_lint" "$@"; \ + echo "Reused lint from $$draft_lint"; \ fi; \ - if [ "$$localerr" -eq 1 ]; then err=1; \ - else \ - echo "$$hash" > "$$lint_file"; \ + done; \ + if [ ! -r "$@" ] || [ "`cat "$@"`" != "$$hash" ]; then \ + for branch in `git branch --points-at HEAD`; do \ + old_lintfile=".lintcache/$$branch/$(@F)"; \ + if [ -r "$$old_lintfile" ]; then \ + cp "$$old_lintfile" "$@"; \ + echo "Reused lint of $< from $$branch"; \ + break; \ + fi; \ + done; \ + if [ ! -r "$@" ] || [ "`cat "$@"`" != "$$hash" ]; then \ + echo "Linting $<..."; \ + localerr=0 \ + f="$<"; \ + if cat "$<" | (l=0; while read -r a; do l=$$(($$l + 1)); echo -E "$$l:$$a"; done) | \ + sed -e '1,/--- abstract/d;/^[0-9]*: *|/d' | tr -d '\r' | grep '^[0-9]*:.\{81\}'; then \ + echo "$< contains a line with >80 characters"; err=1; \ + fi; \ + if cat "$<" | (l=0; while read -r a; do l=$$(($$l + 1)); echo -E "$$l:$$a"; done) | \ + sed -e '/^[0-9]*:~~~/,/^[0-9]*:~~~/p;/^[0-9]*:```/,/^[0-9]*:```/p;d' | \ + tr -d '\r' | grep '^[0-9]*:.\{66\}'; then \ + echo "$< contains a figure with >65 characters"; err=1; \ + fi; \ + if [ "$$localerr" -eq 1 ]; then false; \ + else \ + echo "$$hash" > "$@"; \ + fi; \ fi; \ fi; \ - done; [ "$$err" -eq 0 ] + fi; + +lint-purge:: $(LINT_DIR) + @MAYBE_OBSOLETE=`comm -13 <(git branch | sed -e 's,.*[ /],,' | sort | uniq) <(ls ".lintcache" | sed -e 's,.*/,,')`; \ + for item in $$MAYBE_OBSOLETE; do \ + rm -rf ".lintcache/$$item"; \ + done; \ + for item in $(filter-out $(lint_files),$(wildcard $(LINT_DIR)/*.lint)); do \ + rm $$item; \ + done From fe7e5cfa3f8f950acd9d69ab476708ab5a5f7655 Mon Sep 17 00:00:00 2001 From: Mike Bishop Date: Fri, 17 Nov 2017 15:48:37 +0800 Subject: [PATCH 3/4] Avoid warnings from cp --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 946936426f..9bc53d64a1 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,8 @@ $(LINT_DIR)/%.lint: %.md $(LINT_DIR) echo "Reused lint of $<"; \ else \ for draft_lint in $(LINT_DIR)/*.lint; do \ - if [ -r "$$draft_lint" ] && [ "`cat "$$draft_lint"`" == "$$hash" ]; then \ + if ["$$draft_lint" != "$@" ] && \ + [ -r "$$draft_lint" ] && [ "`cat "$$draft_lint"`" == "$$hash" ]; then \ cp "$$draft_lint" "$@"; \ echo "Reused lint from $$draft_lint"; \ fi; \ From f6f33c96ff4be923b0c702c80f7aa9dd5622395a Mon Sep 17 00:00:00 2001 From: Mike Bishop Date: Sat, 23 Dec 2017 16:36:14 -0500 Subject: [PATCH 4/4] Minor touchups --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 9bc53d64a1..e1c70761e9 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,8 @@ LINT_DIR := .lintcache/$(CURRENT_BRANCH) lint_files:= $(addprefix $(LINT_DIR)/,$(addsuffix .lint,$(drafts))) -latest:: lint -lint:: lint-purge $(lint_files) +latest:: lint lint-purge +lint:: $(lint_files) .PHONY: lint lint-purge @@ -35,7 +35,7 @@ $(LINT_DIR)/%.lint: %.md $(LINT_DIR) if ["$$draft_lint" != "$@" ] && \ [ -r "$$draft_lint" ] && [ "`cat "$$draft_lint"`" == "$$hash" ]; then \ cp "$$draft_lint" "$@"; \ - echo "Reused lint from $$draft_lint"; \ + echo "Reused lint of $$draft_lint for $@"; \ fi; \ done; \ if [ ! -r "$@" ] || [ "`cat "$@"`" != "$$hash" ]; then \ @@ -68,7 +68,7 @@ $(LINT_DIR)/%.lint: %.md $(LINT_DIR) fi; \ fi; -lint-purge:: $(LINT_DIR) +lint-purge:: $(LINT_DIR) | lint @MAYBE_OBSOLETE=`comm -13 <(git branch | sed -e 's,.*[ /],,' | sort | uniq) <(ls ".lintcache" | sed -e 's,.*/,,')`; \ for item in $$MAYBE_OBSOLETE; do \ rm -rf ".lintcache/$$item"; \