Skip to content

Commit 4ba8185

Browse files
authored
Merge pull request #42 from pebble/bugfix/wscript_sdk2-error
PBL-41326 Update convert-project to handle conversions through SDK3
2 parents 66afc91 + 1608dea commit 4ba8185

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

pebble_tool/commands/sdk/project/convert.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __call__(self, args):
2727
print("No conversion required")
2828
except OutdatedProjectException:
2929
self._convert_project()
30+
super(PblProjectConverter, self).__call__(args)
3031
self._convert_to_npm()
3132
print("Project successfully converted!")
3233

@@ -82,25 +83,20 @@ def _ignore_npm(self):
8283
def _convert_project(self):
8384
project_root = os.getcwd()
8485
project_template_path = os.path.join(self.get_sdk_path(), 'pebble', 'common', 'templates')
85-
if not os.path.exists(project_template_path):
86-
project_template_path = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'sdk', 'templates')
86+
tool_project_template_path = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'sdk', 'templates')
8787

8888
self._generate_appinfo_from_old_project(project_root)
8989

9090
wscript_path = os.path.join(project_root, "wscript")
9191

92-
wscript2_hash = hashlib.md5(open(os.path.join(project_template_path, 'wscript_sdk2')).read()).hexdigest()
93-
wscript3_hash = hashlib.md5(open(os.path.join(project_template_path, 'wscript')).read()).hexdigest()
94-
with open(wscript_path, "r") as f:
95-
current_hash = hashlib.md5(f.read()).hexdigest()
96-
97-
if wscript2_hash != current_hash and wscript3_hash != current_hash:
98-
print('WARNING: You had modified your wscript and those changes will be lost.\n'
99-
'Saving your old wscript in wscript.backup.')
100-
os.rename(wscript_path, wscript_path + '.backup')
92+
print('Saving your old wscript in wscript.backup.')
93+
os.rename(wscript_path, wscript_path + '.backup')
10194

10295
print('Generating new 3.x wscript')
103-
copy2(os.path.join(project_template_path, 'wscript'), wscript_path)
96+
try:
97+
copy2(os.path.join(project_template_path, 'wscript'), wscript_path)
98+
except IOError:
99+
copy2(os.path.join(tool_project_template_path, 'wscript'), wscript_path)
104100
os.system('pebble clean')
105101

106102
@classmethod

pebble_tool/sdk/project.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ def _sanity_check(self):
4949
or not os.path.exists(os.path.join(self.project_dir, 'wscript')):
5050
raise OutdatedProjectException("This project is very outdated, and cannot be handled by this SDK.")
5151

52-
if self.sdk_version != SDK_VERSION:
52+
if self.sdk_version == '2.9':
5353
if sdk_version() != '2.9':
5454
raise OutdatedProjectException("This projected is outdated (try 'pebble convert-project' or"
5555
"'pebble sdk install 2.9')")
56+
elif self.sdk_version != SDK_VERSION:
57+
raise PebbleProjectException("An invalid value of '{}' was found in the 'sdkVersion' field of the "
58+
"project's package.json. The latest supported value for this field is '{}'.".
59+
format(self.sdk_version, SDK_VERSION))
5660

5761
def _parse_project(self):
5862
raise NotImplementedError

pebble_tool/sdk/templates/wscript

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,50 @@
1-
21
#
3-
# This file is the default set of rules to compile a Pebble project.
2+
# This file is the default set of rules to compile a Pebble application.
43
#
54
# Feel free to customize this to your needs.
65
#
7-
86
import os.path
97

108
top = '.'
119
out = 'build'
1210

11+
1312
def options(ctx):
1413
ctx.load('pebble_sdk')
1514

15+
1616
def configure(ctx):
17+
"""
18+
This method is used to configure your build. ctx.load(`pebble_sdk`) automatically configures
19+
a build for each valid platform in `targetPlatforms`. Platform-specific configuration: add your
20+
change after calling ctx.load('pebble_sdk') and make sure to set the correct environment first.
21+
Universal configuration: add your change prior to calling ctx.load('pebble_sdk').
22+
"""
1723
ctx.load('pebble_sdk')
1824

25+
1926
def build(ctx):
2027
ctx.load('pebble_sdk')
2128

2229
build_worker = os.path.exists('worker_src')
2330
binaries = []
2431

25-
for p in ctx.env.TARGET_PLATFORMS:
26-
ctx.set_env(ctx.all_envs[p])
32+
cached_env = ctx.env
33+
for platform in ctx.env.TARGET_PLATFORMS:
34+
ctx.env = ctx.all_envs[platform]
2735
ctx.set_group(ctx.env.PLATFORM_NAME)
28-
app_elf='{}/pebble-app.elf'.format(ctx.env.BUILD_DIR)
29-
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'),
30-
target=app_elf)
36+
app_elf = '{}/pebble-app.elf'.format(ctx.env.BUILD_DIR)
37+
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'), target=app_elf)
3138

3239
if build_worker:
33-
worker_elf='{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR)
34-
binaries.append({'platform': p, 'app_elf': app_elf, 'worker_elf': worker_elf})
35-
ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/**/*.c'),
36-
target=worker_elf)
40+
worker_elf = '{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR)
41+
binaries.append({'platform': platform, 'app_elf': app_elf, 'worker_elf': worker_elf})
42+
ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/**/*.c'), target=worker_elf)
3743
else:
38-
binaries.append({'platform': p, 'app_elf': app_elf})
44+
binaries.append({'platform': platform, 'app_elf': app_elf})
45+
ctx.env = cached_env
3946

4047
ctx.set_group('bundle')
41-
ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob('src/js/**/*.js'))
48+
ctx.pbl_bundle(binaries=binaries,
49+
js=ctx.path.ant_glob(['src/js/**/*.js', 'src/js/**/*.json']),
50+
js_entry_file='src/js/app.js')

0 commit comments

Comments
 (0)