4545SUFFIXES_C_OR_CPP = frozenset ({".c" , ".h" , ".cpp" })
4646SUFFIXES_DOCUMENTATION = frozenset ({".rst" , ".md" })
4747
48+ ANDROID_DIRS = frozenset ({"Android" })
49+ IOS_DIRS = frozenset ({"Apple" , "iOS" })
50+ MACOS_DIRS = frozenset ({"Mac" })
51+ WASI_DIRS = frozenset ({Path ("Tools" , "wasm" )})
52+
4853
4954@dataclass (kw_only = True , slots = True )
5055class Outputs :
56+ run_android : bool = False
5157 run_ci_fuzz : bool = False
5258 run_docs : bool = False
59+ run_ios : bool = False
60+ run_macos : bool = False
5361 run_tests : bool = False
62+ run_ubuntu : bool = False
63+ run_wasi : bool = False
5464 run_windows_msi : bool = False
5565 run_windows_tests : bool = False
5666
@@ -63,7 +73,15 @@ def compute_changes() -> None:
6373 outputs = process_changed_files (files )
6474 else :
6575 # Otherwise, just run the tests
66- outputs = Outputs (run_tests = True , run_windows_tests = True )
76+ outputs = Outputs (
77+ run_android = True ,
78+ run_ios = True ,
79+ run_macos = True ,
80+ run_tests = True ,
81+ run_ubuntu = True ,
82+ run_wasi = True ,
83+ run_windows_tests = True ,
84+ )
6785 outputs = process_target_branch (outputs , target_branch )
6886
6987 if outputs .run_tests :
@@ -111,13 +129,31 @@ def get_changed_files(
111129 return frozenset (map (Path , filter (None , map (str .strip , changed_files ))))
112130
113131
132+ def get_file_platform (file : Path ) -> str | None :
133+ if not file .parts :
134+ return None
135+ first_part = file .parts [0 ]
136+ if first_part in MACOS_DIRS :
137+ return "macos"
138+ if first_part in IOS_DIRS :
139+ return "ios"
140+ if first_part in ANDROID_DIRS :
141+ return "android"
142+ if len (file .parts ) >= 2 and Path (* file .parts [:2 ]) in WASI_DIRS : # Tools/wasm/
143+ return "wasi"
144+ return None
145+
146+
114147def process_changed_files (changed_files : Set [Path ]) -> Outputs :
115148 run_tests = False
116149 run_ci_fuzz = False
117150 run_docs = False
118151 run_windows_tests = False
119152 run_windows_msi = False
120153
154+ platforms_changed = set ()
155+ has_platform_specific_change = True
156+
121157 for file in changed_files :
122158 # Documentation files
123159 doc_or_misc = file .parts [0 ] in {"Doc" , "Misc" }
@@ -126,10 +162,15 @@ def process_changed_files(changed_files: Set[Path]) -> Outputs:
126162 if file .parent == GITHUB_WORKFLOWS_PATH :
127163 if file .name == "build.yml" :
128164 run_tests = run_ci_fuzz = True
165+ has_platform_specific_change = False
129166 if file .name == "reusable-docs.yml" :
130167 run_docs = True
131168 if file .name == "reusable-windows-msi.yml" :
132169 run_windows_msi = True
170+ if file .name == "reusable-macos.yml" :
171+ platforms_changed .add ("macos" )
172+ if file .name == "reusable-wasi.yml" :
173+ platforms_changed .add ("wasi" )
133174
134175 if not (
135176 doc_file
@@ -138,8 +179,13 @@ def process_changed_files(changed_files: Set[Path]) -> Outputs:
138179 ):
139180 run_tests = True
140181
141- if file not in UNIX_BUILD_SYSTEM_FILE_NAMES :
142- run_windows_tests = True
182+ platform = get_file_platform (file )
183+ if platform is not None :
184+ platforms_changed .add (platform )
185+ else :
186+ has_platform_specific_change = False
187+ if file not in UNIX_BUILD_SYSTEM_FILE_NAMES :
188+ run_windows_tests = True
143189
144190 # The fuzz tests are pretty slow so they are executed only for PRs
145191 # changing relevant files.
@@ -159,12 +205,38 @@ def process_changed_files(changed_files: Set[Path]) -> Outputs:
159205 if file .parts [:2 ] == ("Tools" , "msi" ):
160206 run_windows_msi = True
161207
208+ # Check which platform specific tests to run
209+ if run_tests :
210+ if not has_platform_specific_change or not platforms_changed :
211+ run_android = True
212+ run_ios = True
213+ run_macos = True
214+ run_ubuntu = True
215+ run_wasi = True
216+ else :
217+ run_android = "android" in platforms_changed
218+ run_ios = "ios" in platforms_changed
219+ run_macos = "macos" in platforms_changed
220+ run_ubuntu = False
221+ run_wasi = "wasi" in platforms_changed
222+ else :
223+ run_android = False
224+ run_ios = False
225+ run_macos = False
226+ run_ubuntu = False
227+ run_wasi = False
228+
162229 return Outputs (
230+ run_android = run_android ,
163231 run_ci_fuzz = run_ci_fuzz ,
164232 run_docs = run_docs ,
233+ run_ios = run_ios ,
234+ run_macos = run_macos ,
165235 run_tests = run_tests ,
166- run_windows_tests = run_windows_tests ,
236+ run_ubuntu = run_ubuntu ,
237+ run_wasi = run_wasi ,
167238 run_windows_msi = run_windows_msi ,
239+ run_windows_tests = run_windows_tests ,
168240 )
169241
170242
@@ -191,11 +263,16 @@ def write_github_output(outputs: Outputs) -> None:
191263 return
192264
193265 with open (os .environ ["GITHUB_OUTPUT" ], "a" , encoding = "utf-8" ) as f :
266+ f .write (f"run-android={ bool_lower (outputs .run_android )} \n " )
194267 f .write (f"run-ci-fuzz={ bool_lower (outputs .run_ci_fuzz )} \n " )
195268 f .write (f"run-docs={ bool_lower (outputs .run_docs )} \n " )
269+ f .write (f"run-ios={ bool_lower (outputs .run_ios )} \n " )
270+ f .write (f"run-macos={ bool_lower (outputs .run_macos )} \n " )
196271 f .write (f"run-tests={ bool_lower (outputs .run_tests )} \n " )
197- f .write (f"run-windows-tests={ bool_lower (outputs .run_windows_tests )} \n " )
272+ f .write (f"run-ubuntu={ bool_lower (outputs .run_ubuntu )} \n " )
273+ f .write (f"run-wasi={ bool_lower (outputs .run_wasi )} \n " )
198274 f .write (f"run-windows-msi={ bool_lower (outputs .run_windows_msi )} \n " )
275+ f .write (f"run-windows-tests={ bool_lower (outputs .run_windows_tests )} \n " )
199276
200277
201278def bool_lower (value : bool , / ) -> str :
0 commit comments