22__author__ = 'katharine'
33
44import argparse
5- import contextlib
6- import json
75import os
8- import re
96import shutil
107import subprocess
118import sys
@@ -58,9 +55,8 @@ def __call__(self, args):
5855 raise ToolError ("This is a Moddable project, but the currently active SDK does not have Moddable tools. "
5956 "Please install an SDK with Moddable support to build this project." )
6057 self .run_moddable_prebuild ()
61- with self ._temporary_sdk_compatible_version ():
62- self ._waf ("configure" , extra_env = extra_env , args = waf )
63- self ._waf ("build" , args = waf )
58+ self ._waf ("configure" , extra_env = extra_env , args = waf )
59+ self ._waf ("build" , args = waf )
6460 except subprocess .CalledProcessError :
6561 duration = time .time () - start_time
6662 post_event ("app_build_failed" , build_time = duration )
@@ -70,67 +66,6 @@ def __call__(self, args):
7066 has_js = os .path .exists (os .path .join ('src' , 'js' ))
7167 post_event ("app_build_succeeded" , has_js = has_js , line_counts = self ._get_line_counts (), build_time = duration )
7268
73- @contextlib .contextmanager
74- def _temporary_sdk_compatible_version (self ):
75- """
76- Pebble's legacy waf expects patch version 0 (x.y.0) in project metadata.
77- To support publishing semantic patch versions (e.g. 1.0.1), temporarily
78- normalize metadata for build and restore the original file afterwards.
79- """
80- file_path = None
81- raw = None
82- patched = None
83- normalized = None
84-
85- def _normalize_semver (version ):
86- match = re .match (r"^(\d+)\.(\d+)\.(\d+)$" , str (version or "" ).strip ())
87- if not match :
88- return None
89- major , minor , patch = match .groups ()
90- if patch == "0" :
91- return None
92- return "{}.{}.0" .format (major , minor )
93-
94- try :
95- if hasattr (self .project , "project_info" ):
96- candidate = os .path .join (self .project .project_dir , "package.json" )
97- try :
98- with open (candidate , "r" , encoding = "utf-8" ) as f :
99- data = json .load (f )
100- normalized = _normalize_semver (data .get ("version" ))
101- if normalized :
102- file_path = candidate
103- raw = json .dumps (data , indent = 2 )
104- data ["version" ] = normalized
105- patched = json .dumps (data , indent = 2 ) + "\n "
106- except Exception :
107- pass
108- else :
109- candidate = os .path .join (self .project .project_dir , "appinfo.json" )
110- try :
111- with open (candidate , "r" , encoding = "utf-8" ) as f :
112- data = json .load (f )
113- normalized = _normalize_semver (data .get ("versionLabel" ))
114- if normalized :
115- file_path = candidate
116- raw = json .dumps (data , indent = 2 )
117- data ["versionLabel" ] = normalized
118- patched = json .dumps (data , indent = 2 ) + "\n "
119- except Exception :
120- pass
121-
122- if file_path and patched is not None and raw is not None :
123- with open (file_path , "w" , encoding = "utf-8" ) as f :
124- f .write (patched )
125- yield
126- finally :
127- if file_path and raw is not None :
128- try :
129- with open (file_path , "w" , encoding = "utf-8" ) as f :
130- f .write (raw + "\n " )
131- except Exception :
132- pass
133-
13469 def run_moddable_prebuild (self ):
13570 print ("Running Moddable prebuild." )
13671 try :
0 commit comments