35
35
archive_deterministically ,
36
36
BuildNotFound ,
37
37
cd ,
38
+ check_output ,
38
39
CommandBase ,
39
40
is_windows ,
40
41
)
@@ -124,6 +125,10 @@ class PackageCommands(CommandBase):
124
125
default = None ,
125
126
action = 'store_true' ,
126
127
help = 'Package Android' )
128
+ @CommandArgument ('--ohos' ,
129
+ default = None ,
130
+ action = 'store_true' ,
131
+ help = 'Package OpenHarmony' )
127
132
@CommandArgument ('--target' , '-t' ,
128
133
default = None ,
129
134
help = 'Package for given target platform' )
@@ -178,6 +183,55 @@ def package(self, build_type: BuildType, flavor=None, with_asan=False):
178
183
except subprocess .CalledProcessError as e :
179
184
print ("Packaging Android exited with return value %d" % e .returncode )
180
185
return e .returncode
186
+ elif self .is_openharmony ():
187
+ # hvigor doesn't support an option to place output files in a specific directory
188
+ # so copy the source files into the target/openharmony directory first.
189
+ ohos_app_dir = path .join (self .get_top_dir (), "support" , "openharmony" )
190
+ build_mode = build_type .directory_name ()
191
+ ohos_target_dir = path .join (
192
+ self .get_top_dir (), "target" , "openharmony" , self .target .triple (), build_mode )
193
+ if path .exists (ohos_target_dir ):
194
+ print ("Cleaning up from previous packaging" )
195
+ delete (ohos_target_dir )
196
+ shutil .copytree (ohos_app_dir , ohos_target_dir )
197
+
198
+ # Map non-debug profiles to 'release' buildMode HAP.
199
+ if build_type .is_custom ():
200
+ build_mode = "release"
201
+
202
+ hvigor_command = ["--no-daemon" , "assembleHap" , "-p" , "product=default" , "-p" , f"buildMode={ build_mode } " ]
203
+ # Detect if PATH already has hvigor, or else fallback to npm installation
204
+ # provided via HVIGOR_PATH
205
+ if "HVIGOR_PATH" not in env :
206
+ try :
207
+ with cd (ohos_target_dir ):
208
+ version = check_output (["hvigorw" , "--version" , "--no-daemon" ])
209
+ print (f"Found `hvigorw` with version { str (version , 'utf-8' ).strip ()} in system PATH" )
210
+ hvigor_command [0 :0 ] = ["hvigorw" ]
211
+ except FileNotFoundError :
212
+ print ("Unable to find `hvigor` tool. Please either modify PATH to include the"
213
+ "path to hvigorw or set the HVIGOR_PATH environment variable to the npm"
214
+ "installation containing `node_modules` directory with hvigor modules." )
215
+ sys .exit (1 )
216
+ else :
217
+ env ["NODE_PATH" ] = env ["HVIGOR_PATH" ] + "/node_modules"
218
+ hvigor_script = f"{ env ['HVIGOR_PATH' ]} /node_modules/@ohos/hvigor/bin/hvigor.js"
219
+ hvigor_command [0 :0 ] = ["node" , hvigor_script ]
220
+
221
+ abi_string = self .target .abi_string ()
222
+ ohos_libs_dir = path .join (ohos_target_dir , "entry" , "libs" , abi_string )
223
+ os .makedirs (ohos_libs_dir )
224
+ # The libservoshell.so binary that was built needs to be copied
225
+ # into the app folder heirarchy where hvigor expects it.
226
+ print (f"Copying { binary_path } to { ohos_libs_dir } " )
227
+ shutil .copy (binary_path , ohos_libs_dir )
228
+ try :
229
+ with cd (ohos_target_dir ):
230
+ print ("Calling" , hvigor_command )
231
+ subprocess .check_call (hvigor_command , env = env )
232
+ except subprocess .CalledProcessError as e :
233
+ print ("Packaging OpenHarmony exited with return value %d" % e .returncode )
234
+ return e .returncode
181
235
elif 'darwin' in self .target .triple ():
182
236
print ("Creating Servo.app" )
183
237
dir_to_dmg = path .join (target_dir , 'dmg' )
@@ -347,6 +401,9 @@ def package(self, build_type: BuildType, flavor=None, with_asan=False):
347
401
@CommandArgument ('--android' ,
348
402
action = 'store_true' ,
349
403
help = 'Install on Android' )
404
+ @CommandArgument ('--ohos' ,
405
+ action = 'store_true' ,
406
+ help = 'Install on OpenHarmony' )
350
407
@CommandArgument ('--emulator' ,
351
408
action = 'store_true' ,
352
409
help = 'For Android, install to the only emulated device' )
@@ -376,7 +433,7 @@ def install(self, build_type: BuildType, emulator=False, usb=False, with_asan=Fa
376
433
return 1
377
434
378
435
if self .is_android ():
379
- pkg_path = self .get_apk_path (build_type )
436
+ pkg_path = self .target . get_package_path (build_type . directory_name () )
380
437
exec_command = [self .android_adb_path (env )]
381
438
if emulator and usb :
382
439
print ("Cannot install to both emulator and USB at the same time." )
@@ -386,6 +443,10 @@ def install(self, build_type: BuildType, emulator=False, usb=False, with_asan=Fa
386
443
if usb :
387
444
exec_command += ["-d" ]
388
445
exec_command += ["install" , "-r" , pkg_path ]
446
+ elif self .is_openharmony ():
447
+ pkg_path = self .target .get_package_path (build_type .directory_name ())
448
+ hdc_path = path .join (env ["OHOS_SDK_NATIVE" ], "../" , "toolchains" , "hdc" )
449
+ exec_command = [hdc_path , "install" , "-r" , pkg_path ]
389
450
elif is_windows ():
390
451
pkg_path = path .join (path .dirname (binary_path ), 'msi' , 'Servo.msi' )
391
452
exec_command = ["msiexec" , "/i" , pkg_path ]
0 commit comments