File: make-documentation.py

package info (click to toggle)
laniakea 0.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 15,464 kB
  • sloc: javascript: 38,493; python: 21,153; sh: 196; makefile: 129; ansic: 3
file content (107 lines) | stat: -rwxr-xr-x 2,929 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3
# flake8: noqa

import os
import sys
import glob
import signal
import subprocess


def get_sources_list(source_root):
    res = list()
    for fname in glob.iglob(source_root + '/src/**/*.d', recursive=True):
        if os.path.basename(fname) != 'app.d' and not fname.startswith(
            (source_root + '/src/c/', source_root + '/src/web/', source_root + '/src/webswview/')
        ):
            res.append(fname)
    return res


def find_local_include_dirs(source_root):
    res = list()
    for fname in glob.iglob(source_root + '/contrib/subprojects/**/*'):
        basename = os.path.basename(fname)
        if basename == 'src' or basename == 'source':
            res.append(fname)
    return res


def build_include_dir_cmd(source_root):
    incdirs = list()

    extra_inc_dirs = [
        '/usr/include/d/vibe/',
        '/usr/include/d/diet/',
        '/usr/include/d/stdx-allocator/',
        '/usr/include/d/glibd-2/',
        './src',
        './build/wrap/',
    ]

    for d in extra_inc_dirs + find_local_include_dirs(source_root):
        if os.path.isdir(d):
            incdirs.append('-I' + d)
    return incdirs


def get_string_import_dirs(source_root):
    import_dirs = ['data/', 'src/web/views/', 'src/webswview/views/']

    return ['-J' + os.path.join(source_root, d) for d in import_dirs]


def run_mkdocs(source_root, build_root):
    cmd = ['mkdocs', 'build', '--site-dir', os.path.abspath(os.path.join(build_root, 'docs'))]
    print('RUN: ' + ' '.join(cmd))
    subprocess.run(cmd, cwd=os.path.join(source_root, 'docs'), check=True)


def run_ddox(source_root, build_root):
    doc_json_fname = os.path.join(build_root, 'documentation.json')

    ldc_cmd = [
        'ldc2',
        '-D',
        '-dw',
        '-c',
        '-o-',
        '-Dd=/tmp/lk-unused/',
        '-Xf=' + doc_json_fname,
        '-oq',
        '-d-version=USE_PGSQL',
        '-d-version=Derelict_Static',
        '-d-version=Have_diet_ng',
    ]

    ldc_cmd.extend(
        get_sources_list(source_root) + build_include_dir_cmd(source_root) + get_string_import_dirs(source_root)
    )

    print('RUN: ' + ' '.join(ldc_cmd))
    subprocess.run(ldc_cmd, check=True)

    ddox_cmd = ['ddox', 'generate-html', doc_json_fname, os.path.abspath(os.path.join(build_root, 'docs', 'api'))]

    print('RUN: ' + ' '.join(ddox_cmd))
    res = subprocess.run(ddox_cmd)
    if res.returncode == -signal.SIGSEGV:
        print("DDOX crashed!")
        print(res)
    else:
        res.check_returncode()


def run(source_root, build_root):
    # build Markdown documentation
    run_mkdocs(source_root, build_root)

    # build API documentation
    # run_ddox(source_root, build_root)


if __name__ == "__main__":
    if len(sys.argv) < 3:
        print('Need at least source-root and build-root directories as parameters!')
        sys.exit(1)
    run(source_root=sys.argv[1], build_root=sys.argv[2])