-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
195 lines (169 loc) · 6.93 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
SHELL := /bin/bash
EMACS ?= $(shell which emacs)
export PYTHON ?= python
ifeq ($(shell command -v $(PYTHON) 2>/dev/null),)
$(error $(PYTHON) not found)
endif
ifeq ($(shell expr $$($(PYTHON) --version 2>&1 | cut -d' ' -f2) \< 3),1)
$(error Set PYTHON to python3)
endif
ifeq ($(shell expr $$($(PYTHON) --version 2>&1 | cut -d'.' -f2) \< 11),0)
$(error Set PYTHON to an older python3)
endif
SRC=$(shell cask files)
PKBUILD=2.3
ELCFILES = $(SRC:.el=.elc)
CASK_DIR := $(shell EMACS=$(EMACS) cask package-directory || exit 1)
export TEST_PYTHON ?= $(PYTHON)
ifeq ($(shell command -v $(TEST_PYTHON) 2>/dev/null),)
$(error $(TEST_PYTHON) not found)
endif
.DEFAULT_GOAL := test-compile
.PHONY: cask
cask: $(CASK_DIR)
$(CASK_DIR): Cask
cask install
touch $(CASK_DIR)
lisp/nnreddit-pkg.el: nnreddit/VERSION lisp/nnreddit-pkg.el.in
sed 's/VERSION/"$(shell cat $<)"/' lisp/nnreddit-pkg.el.in > $@
.PHONY: autoloads
autoloads: lisp/nnreddit-pkg.el
cask emacs -Q --batch -l package --eval "(let ((v (format \"%s.%s\" emacs-major-version emacs-minor-version))) (custom-set-variables (backquote (package-user-dir ,(concat \".cask/\" v)))))" -f package-initialize --eval "(package-generate-autoloads \"nnreddit\" \"./lisp\")"
README.rst: README.in.rst lisp/nnreddit.el
grep ';;' lisp/nnreddit.el \
| awk '/;;;\s*Commentary/{within=1;next}/;;;\s*/{within=0}within' \
| sed -e 's/^\s*;;*\s*//g' \
| tools/readme-sed.sh "COMMENTARY" README.in.rst > README.rst
.PHONY: clean
clean:
cask clean-elc
pyclean nnreddit
$(PYTHON) setup.py clean
rm -f tests/log/*
rm -rf tests/test-install
.PHONY: pylint
ifeq ($(shell expr $$($(PYTHON) --version 2>&1 | cut -d'.' -f2) \> 9),1)
pylint:
$(PYTHON) -m pip -q install --user pylint
$(PYTHON) -m pylint nnreddit --rcfile=nnreddit/pylintrc
else
pylint:
@echo forgoing pylint
endif
.PHONY: test-compile
test-compile: cask autoloads pylint
sh -e tools/package-lint.sh lisp/nnreddit.el
! (cask eval "(let ((byte-compile-error-on-warn t) (bytecomp--inhibit-lexical-cookie-warning t) (byte-compile--suppressed-warnings (quote ((obsolete define-package))))) (cask-cli/build))" 2>&1 | egrep -a "(Warning|Error):")
cask clean-elc
define SET_GITHUB_ACTOR =
GITHUB_ACTOR := $(shell if [ -z ${GITHUB_ACTOR} ]; then git config user.name; else echo ${GITHUB_ACTOR} ; fi)
endef
define SET_GITHUB_ACTOR_REPOSITORY =
GITHUB_ACTOR_REPOSITORY := $(GITHUB_ACTOR)/$(shell basename `git rev-parse --show-toplevel`)
endef
define SET_GITHUB_HEAD_REF =
GITHUB_HEAD_REF := $(shell if [ -z ${GITHUB_HEAD_REF} ]; then git rev-parse --abbrev-ref HEAD; else echo ${GITHUB_HEAD_REF} ; fi)
endef
define SET_GITHUB_SHA =
GITHUB_SHA := $(shell if [ -z ${GITHUB_SHA} ] ; then git rev-parse origin/${GITHUB_HEAD_REF}; else echo ${GITHUB_SHA}; fi)
endef
define SET_GITHUB_COMMIT =
GITHUB_COMMIT := $(shell if git show -s --format=%s "${GITHUB_SHA}" | egrep -q "^Merge .* into" ; then git show -s --format=%s "${GITHUB_SHA}" | cut -d " " -f2 ; else echo "${GITHUB_SHA}" ; fi)
endef
.PHONY: test-install-vars
test-install-vars:
$(eval $(call SET_GITHUB_ACTOR))
$(eval $(call SET_GITHUB_ACTOR_REPOSITORY))
$(eval $(call SET_GITHUB_HEAD_REF))
$(eval $(call SET_GITHUB_SHA))
$(eval $(call SET_GITHUB_COMMIT))
git show -s --format=%s $(GITHUB_COMMIT)
git show -s --format=%s $(GITHUB_SHA)
.PHONY: test-install-defunct
test-install-defunct: test-install-vars
mkdir -p tests/test-install
if [ ! -s "tests/test-install/$(PKBUILD).tar.gz" ] ; then \
cd tests/test-install ; curl -sLOk https://github.com/melpa/package-build/archive/$(PKBUILD).tar.gz ; fi
cd tests/test-install ; tar xfz $(PKBUILD).tar.gz
cd tests/test-install ; rm -f $(PKBUILD).tar.gz
cd tests/test-install/package-build-$(PKBUILD) ; make -s loaddefs
mkdir -p tests/test-install/recipes
cd tests/test-install/recipes ; curl -sfLOk https://raw.githubusercontent.com/melpa/melpa/master/recipes/nnreddit || cp -f ../../../tools/recipe ./nnreddit
! ( $(EMACS) -Q --batch -L tests/test-install/package-build-$(PKBUILD) \
--eval "(require 'package-build)" \
--eval "(require 'subr-x)" \
-f package-initialize \
--eval "(add-to-list 'package-archives '(\"melpa\" . \"http://melpa.org/packages/\"))" \
--eval "(package-refresh-contents)" \
--eval "(setq rcp (package-recipe-lookup \"nnreddit\"))" \
--eval "(unless (file-exists-p package-build-archive-dir) \
(make-directory package-build-archive-dir))" \
--eval "(let* ((my-repo \"$(GITHUB_ACTOR_REPOSITORY)\") \
(my-branch \"$(GITHUB_HEAD_REF)\") \
(my-commit \"$(GITHUB_COMMIT)\")) \
(oset rcp :repo my-repo) \
(oset rcp :branch my-branch) \
(oset rcp :commit my-commit))" \
--eval "(package-build--package rcp (package-build--checkout rcp))" \
--eval "(package-install-file (car (file-expand-wildcards (concat package-build-archive-dir \"nnreddit*.tar\"))))" 2>&1 | egrep -ia "error: |fatal" )
.PHONY: test-venv
test-venv: test-install-defunct
$(EMACS) -Q --batch -f package-initialize \
--eval "(custom-set-variables (quote (gnus-verbose 8)))" \
--eval "(require (quote nnreddit))" \
--eval "nnreddit-venv"
define TESTRUN
--eval "(custom-set-variables \
(quote (gnus-select-method (quote (nnreddit \"\")))) \
(backquote (venv-location ,(file-name-as-directory (make-temp-file \"testrun-\" t)))) \
(quote (nnreddit-python-command \"$(PYTHON)\"))\
(quote (gnus-verbose 8)) \
(quote (nnreddit-log-rpc t)))" \
--eval "(setq debug-on-error t)" \
--eval "(fset (quote gnus-y-or-n-p) (function ignore))"
endef
.PHONY: test-run
test-run: cask autoloads
cask emacs -Q --batch \
$(TESTRUN) \
--eval "(require 'nnreddit)" \
--eval "(cl-assert (nnreddit-rpc-get))" \
--eval "(sleep-for 0 7300)" \
-f nnreddit-dump-diagnostics \
--eval "(cl-assert nnreddit-processes)"
.PHONY: test-run-interactive
test-run-interactive: cask autoloads
cask emacs -Q \
$(TESTRUN) \
-f gnus
.PHONY: test-unit
test-unit:
PYTHON=$(TEST_PYTHON) cask exec ert-runner -L . -L tests tests/test*.el
.PHONY: test
test: test-compile test-unit test-int
.PHONY: test-int
test-int:
@>/dev/null expr $$($(TEST_PYTHON) --version 2>&1 | cut -d'.' -f2) \< 9 || { echo "need python less than 3.9" ; exit -1; }
rm -rf venv-nnreddit-test
$(TEST_PYTHON) -m venv venv-nnreddit-test
( \
source venv-nnreddit-test/bin/activate; \
python -m pip -q install -r requirements-dev.txt; \
python -m pytest tests/test_oauth.py; \
rm -f tests/.newsrc.eld; \
cask exec ecukes --reporter magnars --tags "~@inbox"; \
rm -f tests/.newsrc.eld; \
cask exec ecukes --reporter magnars --tags "@inbox"; \
)
.PHONY: dist-clean
dist-clean:
rm -rf dist
.PHONY: dist
dist: dist-clean
cask package
.PHONY: install
install: dist autoloads
$(EMACS) -Q --batch -f package-initialize \
--eval "(add-to-list 'package-archives '(\"melpa\" . \"http://melpa.org/packages/\"))" \
--eval "(package-refresh-contents)" \
--eval "(package-install-file (car (file-expand-wildcards \"dist/nnreddit*.tar\")))"