Improve skip test if socks server is unavailable
[navi2ch.git] / meson.build
blob497d6137c3e7e054c617a5234422c8d55347cb09
1 # -*- mode: meson;-*-
2 project('navi2ch',
3         version: '2.0.0-DEV' # from configure.in
4                  + '+' + run_command([find_program('python', required: true),
5                                       'scripts/patchtag.py'], check: true).stdout().strip(),
6         default_options: run_command([find_program('python', required: true),
7                                       'scripts/default_options.py'], check: true).stdout().strip().split('\n'))
8 fsmod = import('fs')
10 pyton=find_program('python')
11 # find programs
12 if meson.is_cross_build()
13   error('cross build is not allowed')
14 else
15   if host_machine.system() == 'windows'
16     emacs = find_program('emacs', dirs: [
17       'C:/Program Files/Emacs/', 'C:/Program Files/Emacs/bin/',
18       'C:/Program Files/GNU/', 'C:/Program Files/GNU/bin/'], required: true)
19     install_info_script = files('scripts/inst-info.cmd')
20   else
21     if host_machine.system() == 'darwin' # for mac
22       emacs = find_program('Emacs', dirs: [
23         '/Applications/MacPorts/EmacsMac.app/Contents/MacOS/',
24         '/Applications/MacPorts/Emacs.app/Contents/MacOS/',
25         '/opt/local/bin', '/usr/local/bin'], required: true)
26     else
27       emacs = find_program('emacs', required: true)
28     endif
29     install_info_script = files('scripts/inst-info.sh')
30   endif
31   git = find_program('git', disabler: true, required: false)
32   intall_info = find_program('install-info', disabler: true, required: false)
33   openssl = find_program('openssl', disabler: true, required: false)
34   ncat = find_program('ncat', disabler: true, required: false)
35   python = find_program('python', required: true)
36 endif
37 patch_tag = meson.project_version().split('+')[1]
38 lisp_dir = get_option('lispdir') / meson.project_name()
39 info_dir = lisp_dir
40 icon_dir = lisp_dir / 'icons'
42 inl_files = ['navi2ch-decls.el', 'navi2ch-inline.el']
43 el_files_all = ['navi2ch-vars.el', 'navi2ch-face.el', 'navi2ch-util.el', 'navi2ch-net.el', 'navi2ch-socks.el', 'navi2ch-multibbs.el', 'navi2ch-list.el', 'navi2ch-article.el', 'navi2ch-popup-article.el', 'navi2ch-board-misc.el', 'navi2ch-board.el', 'navi2ch-articles.el', 'navi2ch-bookmark.el', 'navi2ch-history.el', 'navi2ch-search.el', 'navi2ch-message.el', 'navi2ch-head.el', 'navi2ch-mona.el', 'navi2ch-e21.el', 'navi2ch-xmas.el', 'navi2ch-splash.el', 'navi2ch-directory.el', 'navi2ch-be2ch.el', 'navi2ch-jbbs-net.el', 'navi2ch-jbbs-shitaraba.el', 'navi2ch-machibbs.el', 'navi2ch-futaba.el', 'navi2ch-megabbs.el', 'navi2ch-http-date.el', 'navi2ch-localfile.el', 'navi2ch-oyster.el', 'navi2ch-auto-modify.el', 'navi2ch-p2.el', 'navi2ch-thumbnail.el', 'navi2ch.el']
44 texi_files = ['doc/navi2ch.texi']
46 if run_command(emacs, '-q', '-batch', '--eval', '(princ (featurep \'xemacs))', check: true).stdout().strip() == 'nil'
47   skip_files = ['navi2ch-xmas.el']
48 else
49   skip_files = ['navi2ch-e21.el']
50 endif
52 el_files = []
53 foreach el: el_files_all
54   if skip_files.contains(el)
55     message(el + ': skipped')
56   else
57     el_files += el
58   endif
59 endforeach
61 contrib_files = []
62 foreach f: ['gikope.el', 'izonmoji-mode.el', 'navi2ch-js-livedoor-move.el', 'navi2ch-logo.el', 'navi2ch-migemo.el', 'navi2ch-pizaunix.el', 'navi2ch-track-mouse.el']
63   contrib_files += 'contrib' / f
64 endforeach
65 ico_files = []
66 foreach f: ['plugged.xpm', 'unplugged.xpm']
67   ico_files += 'icons' / f
68 endforeach
70 in_files = ['navi2ch-version.el.in', 'navi2ch-config.el.in']
72 cpied_inl = []
73 preloads = []
74 foreach f: inl_files
75   cpied_inl += fsmod.copyfile(f, install: true, install_dir: lisp_dir, install_mode: 'rw-r--r--')
76   preloads += ['--eval', '(require \'' + fsmod.stem(f) + ')']
77 endforeach
79 dep = '(setq depends (list'
80 foreach f: inl_files
81    dep += ' "' + f + '"'
82 endforeach
83 dep += '))'
85 conf_el = []
86 elc_files = []
87 foreach f: in_files
88   c = configure_file(
89     input: f,
90     output: fsmod.stem(f),
91     install: true,
92     install_dir: lisp_dir,
93     install_mode: 'rw-r--r--',
94     configuration : {
95       'VERSION': meson.project_version(),
96       'icondir': get_option('prefix') / icon_dir,
97       'configure_input': f
98   })
99   conf_el += c
100   elc_files += fsmod.replace_suffix(c, '.elc')
101 endforeach
103 cpied_el = []
104 foreach el: el_files + contrib_files
105   cpied_el += fsmod.copyfile(
106     el,
107     install: true,
108     install_dir: lisp_dir,
109     install_mode: 'rw-r--r--',
110     install_tag: 'lisp')
111   elc_files += fsmod.name(fsmod.replace_suffix(el, '.elc'))
112 endforeach
114 rfc3986_el = custom_target(
115   'rfc3986',
116   output: 'navi2ch-rfc3986.el',
117   depend_files: [files('scripts/rfc3986-regexp-generator.el')],
118   command: [emacs, '-q', '--batch',
119             '-l', '@SOURCE_ROOT@' / 'scripts/rfc3986-regexp-generator.el',
120             '--eval', '(with-temp-buffer  (erase-buffer) (insert ";; automatically generated (do not edit) -*- lexical-binding: t -*-\n;; Generated from rfc3986-regexp-generator.el\n") (insert (prin1-to-string `(defconst navi2ch-rfc3986-rules-alist (quote ,(rfc3986-regexp-generate-alist))))) (insert "\n(provide \'navi2ch-rfc3986)\n") (write-file (car argv)))',
121             '@OUTPUT@'],
122   install: true,
123   install_dir: lisp_dir,
124   install_mode: 'rw-r--r--',
125   build_by_default: true,
126   install_tag: 'lisp')
127 elc_files += 'navi2ch-rfc3986.elc'
130 # byte compile
131 elc = custom_target(
132   input: [rfc3986_el, conf_el, cpied_el],
133   output: elc_files,
134   depends: cpied_inl,
135   command: [emacs, '-q', '--batch',
136             '--eval', '(require \'cl-extra)',
137             '--eval', '(setq load-path (cons "@OUTDIR@" load-path))',
138             preloads,
139             '--eval', dep,
140             '--eval', '(dolist (el argv) (let* ((base-name  (file-name-sans-extension (file-name-sans-extension el))) (name (intern base-name)) (pred (lambda (f) (file-newer-than-file-p (concat base-name ".elc") f)))) (unless (cl-every pred (cons el depends)) (message "compiling %s" el) (byte-compile-file el)) (cond ((memq name \'(navi2ch-xmas)) (when (featurep \'xemacs) (require name))) ((memq name \'(navi2ch-e21)) (unless (featurep \'xemacs) (require name))) (t (require name)))))', '@INPUT@'],
141   install: true,
142   install_dir: lisp_dir,
143   install_mode: 'rw-r--r--',
144   build_by_default: true,
145   install_tag: 'lisp')
147 # generate navi2ch-autoloads.el
148 autoloads = custom_target(
149   input: [conf_el, cpied_el],
150   output: meson.project_name() + '-autoloads.el',
151   # command: [emacs, '-q', '--batch', '--eval', '(require \'package)', '--eval', '(package-generate-autoloads (car argv) (cadr argv))', meson.project_name(), '@OUTDIR@'],
152   command: [emacs, '-q', '--batch',
153             '--eval', '(require \'package)',
154             '--eval', '(require \'nadvice)',
155             '--eval', '(advice-add \'loaddefs-generate :filter-args (lambda (args) (let ((info-extra (prin1-to-string \'(let ((info-dir (directory-file-name (file-name-directory load-file-name)))) (when (file-exists-p (file-name-concat info-dir "dir")) (add-to-list \'Info-directory-list info-dir t)))))) (list (nth 0 args)  (nth 1 args)  (nth 2 args)  (format "%s\n%s" (nth 3 args) info-extra) (nth 4 args) (nth 5 args)))) (list :name "loaddefs-generate:filter-args"))',
156             '--eval', '(package-generate-autoloads (car argv) (cadr argv))', meson.project_name(), '@OUTDIR@'],
157   install: true,
158   install_dir: lisp_dir,
159   install_mode: 'rw-r--r--',
160   install_tag: 'lisp')
162 if intall_info.found()
163   texi2info = files('doc/batch-texi2info.el')
164   env = environment()
165   if find_program('gzip', disabler: true, required: false).found()
166     gzip = 'YES'
167   else
168     gzip = 'NO'
169   endif
170   info = []
171   foreach ti: texi_files
172     texi = fsmod.copyfile(ti)
173     info += custom_target(
174       input: texi,
175       output: fsmod.stem(texi.full_path()) + '.info',
176       command: [emacs, '-q', '--batch', '-l', texi2info, '-f', 'batch-texi2info', texi])
177   endforeach
178   meson.add_install_script(
179     install_info_script, gzip, info_dir, info,
180     install_tag: 'info')
181 endif
183 install_data(
184   ico_files,
185   install_dir: icon_dir,
186   install_mode: 'rw-r--r--',
187   install_tag: 'icon')
190 if not get_option('disable-test') and openssl.found()
191   ecparams = []
192   foreach i: ['0', '1']
193     ecparams += custom_target(
194       output: 'ecprm' + i + '.pem',
195       command: [openssl, 'ecparam', '-name', 'prime256v1', '-out', '@OUTPUT@'])
196   endforeach
198   cacert = custom_target(
199     input: ['test/ssl.conf', ecparams[0]],
200     output: ['ca_key.pem', 'ca_cert.pem', 'ca_cert.srl'],
201     command: [openssl, 'req', '-batch', '-newkey', 'ec:' + '@INPUT1@', '-sha256', '-nodes',
202               '-subj', '/C=JP/ST=Tokyo/O=Snake Oil Company/CN=Snake Oil company Root Certificate Authority',
203               '-keyout', '@OUTPUT0@', '-out', '@OUTPUT1@',
204               '-x509', '-days', '3650', '-extensions', 'v3_ca', '-config', '@INPUT0@'])
206   hostcsr = custom_target(
207     input: ['test/ssl.conf', ecparams[1]],
208     output: ['localhost_key.pem', 'localhost_csr.pem'],
209     command: ['openssl', 'req', '-new', '-newkey', 'ec:' + '@INPUT1@', '-nodes', '-keyout', '@OUTPUT0@',
210               '-subj', '/C=JP/ST=Tokyo/O=Snake Oil Company/OU=Limiment Div./CN=localhost',
211               '-addext', 'subjectAltName=DNS:localhost,DNS:[::1],IP:127.0.0.1,IP:::1',
212                '-out', '@OUTPUT1@'])
214   hostcert = custom_target(
215     input: ['test/ssl.conf', hostcsr[1], cacert],
216     output: 'localhost_cert.pem',
217     command: [openssl, 'x509', '-req', '-in', '@INPUT1@',
218               '-CAkey', '@INPUT2@','-CA', '@INPUT3@',
219               '-CAcreateserial', '-subj', '/C=JP/ST=Tokyo/O=Snake Oil Company/OU=Limiment Div./CN=localhost',
220               '-days', '3650', '-sha256', '-extfile', '@INPUT0@', '-extensions', 'server_ext', '-out', '@OUTPUT@'])
222   net_test_depends = [cacert, hostcert]
223   alias_target('net_test_certs', net_test_depends)
224 else
225   net_test_depends = []
226 endif
228 test_depends = [elc, autoloads]
229 test_env = ['NAVI2CHDIR=' + meson.current_build_dir()]
232 ### patch file
234 if git.found()
235   extra_files = ['meson.build', 'meson.options',
236                  'test/test-basic.el', 'test/test-network.el',
237                  'test/test-basic.sh', 'test/test-network.sh',
238                  'test/ssl.conf',
239                  'scripts/default_options.py', 'scripts/patchtag.py',
240                  'scripts/inst-info.cmd', 'scripts/inst-info.sh',
241                  'scripts/rfc3986-regexp-generator.el',
242                  'scripts/make-patch.sh']
243   custom_target(
244     'patch-kit',
245     output: 'navi2ch-patch-kit-' + patch_tag + '.patch',
246     command: ['scripts/make-patch.sh', '@SOURCE_ROOT@', '@OUTPUT@',
247               [inl_files, el_files_all, texi_files, contrib_files, in_files, extra_files]],
248     depends: [rfc3986_el],
249     install: false,
250     build_by_default: false,
251     build_always: true)
252 endif
255 ### tests
258 if not get_option('disable-test')
259   if ncat.found()
260     net_test_env = [test_env, 'NCAT=ncat %s %s']
261   else
262     net_test_env = test_env
263   endif
266   test('basic test',
267        files('test/test-basic.sh'),
268        depends: test_depends,
269        env: test_env)
271   test('network test',
272        files('test/test-network.sh'),
273        depends: [test_depends, net_test_depends],
274        timeout: 60,
275        env: net_test_env)
276 endif
277 # alias_target('byte-compile', elc)