@@ -4,15 +4,37 @@ import sys
4
4
import argparse
5
5
import pathlib
6
6
import subprocess
7
- import os
8
7
from build_support .actions import derive_options_from_args , REPO_ROOT , DownloadBaseSnapshotAction
9
8
10
9
10
+ def default_swift_sdk (options , swift_sdks_path : pathlib .Path ):
11
+ """Return the default target triple based on the scheme."""
12
+ import json
13
+ for artifact_bundle in swift_sdks_path .iterdir ():
14
+ if not artifact_bundle .is_dir () or not artifact_bundle .name .endswith ('.artifactbundle' ):
15
+ # Skip if not ending with .artifactbundle
16
+ continue
17
+ info_json = artifact_bundle / 'info.json'
18
+ if not info_json .is_file ():
19
+ continue
20
+ try :
21
+ with info_json .open ('r' ) as f :
22
+ info = json .load (f )
23
+
24
+ sdk_ids = info .get ('artifacts' , {}).keys ()
25
+ for sdk_id in sdk_ids :
26
+ if sdk_id .endswith ("wasm32-unknown-wasip1" ) or sdk_id .endswith ("wasm32-unknown-wasi" ):
27
+ return sdk_id
28
+ except Exception as e :
29
+ print (f"Error reading { info_json } : { e } " , file = sys .stderr )
30
+ continue
31
+
32
+
11
33
def main ():
12
34
parser = argparse .ArgumentParser (
13
35
description = 'Run e2e integration tests for Swift SDK' )
14
- parser .add_argument ('--swift-sdk' , default = 'wasm32-unknown-wasip1' ,
15
- help = 'Swift SDK identifier (default: wasm32-unknown-wasi )' )
36
+ parser .add_argument ('--swift-sdk' , default = None ,
37
+ help = 'Swift SDK identifier (default: wasm32-unknown-wasip1 )' )
16
38
parser .add_argument ('args' , nargs = argparse .REMAINDER ,
17
39
help = 'Extra arguments to pass to lit.py' )
18
40
options = derive_options_from_args (sys .argv [1 :], parser )
@@ -25,11 +47,12 @@ def main():
25
47
base_toolchain_path = DownloadBaseSnapshotAction .toolchain_path (options )
26
48
lit_py_path = repo_path .parent / "llvm-project" / "llvm" / "utils" / "lit" / "lit.py"
27
49
swift_sdks_path = repo_path .parent / "swift-sdk-generator" / "Bundles"
50
+ swift_sdk = options .swift_sdk or default_swift_sdk (options , swift_sdks_path )
28
51
29
52
# Build lit command
30
53
lit_cmd = [
31
54
str (lit_py_path ),
32
- "--param" , f"swift-sdk={ options . swift_sdk } " ,
55
+ "--param" , f"swift-sdk={ swift_sdk } " ,
33
56
"--param" , f"scheme={ options .scheme } " ,
34
57
"--param" , f"base-toolchain-path={ base_toolchain_path } " ,
35
58
"--param" , f"swift-sdks-path={ swift_sdks_path } " ,
0 commit comments