-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwscript
More file actions
134 lines (114 loc) · 5.18 KB
/
Copy pathwscript
File metadata and controls
134 lines (114 loc) · 5.18 KB
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
#
# This file is the default set of rules to compile a Pebble application.
#
# Feel free to customize this to your needs.
#
import os.path
import json
import re
top = '.'
out = 'build'
def _c_escape(s):
"""Escape a Python string for embedding in a C string literal."""
return (s.replace('\\', '\\\\')
.replace('"', '\\"')
.replace('\n', '\\n')
.replace('\r', '')
.replace('\t', ' '))
def generate_version_header(ctx):
"""Generate src/c/version_gen.h from CHANGELOG.md's top entry.
The newest release is the first `## x.y.z` block in CHANGELOG.md. Its
version drives the in-app "What's New" show-once trigger, and its bullet
lines become the notes shown on screen. This runs on every build, so the
only per-release action is editing CHANGELOG.md (+ bumping package.json).
"""
changelog = ctx.path.find_node('CHANGELOG.md')
code, label, notes = 0, '0.0.0', 'No release notes.'
if changelog:
text = changelog.read()
# First "## x.y.z" header and everything up to the next "## ".
m = re.search(r'(?m)^##\s+(\d+)\.(\d+)\.(\d+)[^\n]*\n(.*?)(?=^##\s|\Z)',
text, re.S)
if m:
major, minor, patch = int(m.group(1)), int(m.group(2)), int(m.group(3))
code = major * 10000 + minor * 100 + patch
label = '%d.%d.%d' % (major, minor, patch)
bullets = []
for line in m.group(4).splitlines():
line = line.strip()
if line.startswith('-'):
bullets.append(line[1:].strip())
notes = '\n'.join(bullets) if bullets else 'See changelog for details.'
else:
from waflib import Logs
Logs.warn('version_gen: no "## x.y.z" entry found in CHANGELOG.md')
# Guarantee versions only ever go up: the top entry must be strictly
# greater than the previous one. Fails the build otherwise so a
# non-increasing version can never be shipped.
vers = re.findall(r'(?m)^##\s+(\d+)\.(\d+)\.(\d+)', text)
if len(vers) >= 2:
top = tuple(int(x) for x in vers[0])
prev = tuple(int(x) for x in vers[1])
top_code = top[0] * 10000 + top[1] * 100 + top[2]
prev_code = prev[0] * 10000 + prev[1] * 100 + prev[2]
if top_code <= prev_code:
ctx.fatal('version_gen: CHANGELOG top version %d.%d.%d must be '
'greater than the previous entry %d.%d.%d'
% (top + prev))
# Warn (non-fatal) if the store version drifts from the changelog top.
pkg = ctx.path.find_node('package.json')
if pkg:
try:
pkg_version = json.loads(pkg.read()).get('version', '')
if pkg_version and pkg_version != label:
from waflib import Logs
Logs.warn('version_gen: package.json version (%s) != CHANGELOG top (%s)'
% (pkg_version, label))
except ValueError:
pass
out_node = ctx.path.make_node('src/c/version_gen.h')
out_node.write(
'#pragma once\n'
'//\n// AUTOGENERATED BY BUILD FROM CHANGELOG.md\n'
'// DO NOT EDIT - CHANGES WILL BE OVERWRITTEN\n//\n'
'#define APP_VERSION_CODE %d\n' % code +
'#define APP_VERSION_LABEL "%s"\n' % _c_escape(label) +
'#define APP_UPDATE_NOTES "%s"\n' % _c_escape(notes)
)
def options(ctx):
ctx.load('pebble_sdk')
def configure(ctx):
"""
This method is used to configure your build. ctx.load(`pebble_sdk`) automatically configures
a build for each valid platform in `targetPlatforms`. Platform-specific configuration: add your
change after calling ctx.load('pebble_sdk') and make sure to set the correct environment first.
Universal configuration: add your change prior to calling ctx.load('pebble_sdk').
"""
ctx.load('pebble_sdk')
def build(ctx):
ctx.load('pebble_sdk')
# Regenerate src/c/version_gen.h from CHANGELOG.md before the C compile.
generate_version_header(ctx)
build_worker = os.path.exists('worker_src')
binaries = []
cached_env = ctx.env
for platform in ctx.env.TARGET_PLATFORMS:
ctx.env = ctx.all_envs[platform]
ctx.set_group(ctx.env.PLATFORM_NAME)
app_elf = '{}/pebble-app.elf'.format(ctx.env.BUILD_DIR)
ctx.pbl_build(source=ctx.path.ant_glob('src/c/**/*.c'), target=app_elf, bin_type='app')
if build_worker:
worker_elf = '{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR)
binaries.append({'platform': platform, 'app_elf': app_elf, 'worker_elf': worker_elf})
ctx.pbl_build(source=ctx.path.ant_glob('worker_src/c/**/*.c'),
target=worker_elf,
bin_type='worker')
else:
binaries.append({'platform': platform, 'app_elf': app_elf})
ctx.env = cached_env
ctx.set_group('bundle')
ctx.pbl_bundle(binaries=binaries,
js=ctx.path.ant_glob(['src/pkjs/**/*.js',
'src/pkjs/**/*.json',
'src/common/**/*.js']),
js_entry_file='src/pkjs/index.js')