-
Notifications
You must be signed in to change notification settings - Fork 62
/
build.py
executable file
·156 lines (127 loc) · 5.21 KB
/
build.py
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
#!/usr/bin/env python
from __future__ import print_function
from os import path, listdir
import sh
from mkdocs import config
import yaml
# repos of products that are released together
mynewt_repos = ['mynewt-core', 'mynewt-newt', 'mynewt-newtmgr']
nimble_repo = 'mynewt-nimble'
revisioned_repos = [nimble_repo] + mynewt_repos[:]
dependent_repos = ['mynewt-documentation'] + revisioned_repos[:]
BSP_DIR = "hw/bsp"
BSP_ARCH_NAMES = {
'arc': 'ARC',
'cortex_m0': 'Cortex-M0',
'cortex_m3': 'Cortex-M3',
'cortex_m33': 'Cortex-M33',
'cortex_m4': 'Cortex-M4',
'cortex_m7': 'Cortex-M7',
'mips': 'MIPS',
'pic32': 'PIC32',
'rv32imac': 'RISC-V',
}
class BSP:
'''
Stores data for Mynewt BSPs
'''
def __init__(self, name, url, maker, arch):
self.name = name
self.url = url
self.maker = maker
self._arch = arch
def arch(self):
return BSP_ARCH_NAMES[self._arch]
def repr(self):
return "{}(name={}, url={}, maker={})".format(
self.__class__.__name__, self.name, self.url, self.maker)
def generate_supported_boards(filename, bsps):
with open(filename, 'w') as f:
f.write("<ul>\n")
for bsp in bsps:
f.write("<li>\n")
f.write("<a href=\"{}\"> {} </a> from {} ({})\n".format(bsp.url,
bsp.name,
bsp.maker,
bsp.arch()))
f.write("</li>\n")
f.write("</ul>\n")
def find_BSPs():
bsp_dir = path.join(cwd, '../mynewt-core', BSP_DIR)
if not path.isdir(bsp_dir):
raise Exception("The directory %s does not exist".format(bsp_dir))
bsps = []
for bsp in listdir(bsp_dir):
with open(path.join(bsp_dir, bsp, "bsp.yml"), 'r') as f:
data = yaml.full_load(f)
if data.get('bsp.exclude_site') == 1:
print("{} has 'exclude_site' set, skipping".format(bsp))
continue
for k in ['bsp.name', 'bsp.url', 'bsp.maker', 'bsp.arch']:
if k not in data:
print("{} is missing metadata".format(bsp))
break
else:
bsp = BSP(name=data['bsp.name'], url=data['bsp.url'],
maker=data['bsp.maker'], arch=data['bsp.arch'])
bsps.append(bsp)
bsps_sorted = sorted(bsps, key=lambda bsp: bsp.name.lower())
return bsps_sorted
def build(cwd, site_dir):
cfg = config.load_config()
# sanity check - dependent_repos exist in '..'
for repo in dependent_repos:
d = path.join(cwd, '..', repo)
print('Verifying repo dependency in {}'.format(d))
if not path.isdir(d):
print("The directory %s does not exist".format(d))
return
# return all extra repos to master in case last run failed
for repo in revisioned_repos:
repo_dir = path.normpath(path.join(cwd, '..', repo))
sh.git('checkout', 'master', _cwd=repo_dir)
# sanity check - only one latest
latest = False
latest_version = None
for version in cfg['extra']['versions']:
if not latest and 'latest' in version and version['latest']:
print('Latest is {}'.format(version['label']))
latest = True
latest_version = version['label']
elif latest and 'latest' in version and version['latest']:
print('ERROR: More than one version is latest.')
print('Only one version can be latest: True.')
print('Check mkdocs.yml.')
return
print("Building site pages")
sh.rm('-rf', site_dir)
bsps = find_BSPs()
generate_supported_boards("custom-theme/supported-boards.html", bsps)
sh.mkdocs('build', '--clean', '--site-dir', site_dir)
for version in cfg['extra']['versions']:
print("Building doc pages for: {}".format(version['label']))
if 'sha' not in version:
sh.mkdocs('build', '--site-dir',
path.join(site_dir, version['dir']),
_cwd=path.join("versions", version['dir']))
else:
sha = version['sha']
for repo in mynewt_repos:
repo_dir = path.normpath(path.join(cwd, '..', repo))
sh.git('checkout', sha, _cwd=repo_dir)
sha = version['nimble_sha']
nimble_dir = path.normpath(path.join(cwd, '..', nimble_repo))
sh.git('checkout', sha, _cwd=nimble_dir)
repo_dir = path.normpath(path.join(cwd, '..',
'mynewt-documentation'))
sh.make('clean', _cwd=repo_dir)
sh.make('docs',
'O=-A cur_version={} -A latest_version={}'.format(
version['label'], latest_version), _cwd=repo_dir)
sh.mv(path.join(repo_dir, '_build', 'html'),
path.join(site_dir, version['dir']))
if 'latest' in version and version['latest']:
sh.ln('-s', version['dir'], 'latest', _cwd=site_dir)
if __name__ == '__main__':
cwd = path.dirname(path.abspath(__file__))
build(cwd, path.join(cwd, "site"))