94
94
"will need to be manually set in Xcode." ,
95
95
)
96
96
97
+ FLAG_HARDLINK_CS_FILES = flags .DEFINE_boolean (
98
+ name = "hardlink" ,
99
+ default = False ,
100
+ help = "Instead of copying the .cs source files, hardlink them. This can be "
101
+ "useful when developing the C# code for the testapp itself, as changes "
102
+ "to those files will be instantly reflected both in the destination "
103
+ "Unity project and the GitHub repository."
104
+ )
105
+
97
106
98
107
def main (argv : Sequence [str ]) -> None :
99
108
if len (argv ) > 1 :
@@ -118,6 +127,7 @@ def main(argv: Sequence[str]) -> None:
118
127
google_service_info_plist_file = flags .google_service_info_plist_file ,
119
128
android_package_name = flags .android_package_name ,
120
129
apple_developer_team_id = flags .apple_developer_team_id ,
130
+ hardlink_cs_files = flags .hardlink_cs_files ,
121
131
)
122
132
123
133
try :
@@ -152,6 +162,7 @@ class ParsedFlags:
152
162
google_service_info_plist_file : Optional [pathlib .Path ]
153
163
android_package_name : Optional [str ]
154
164
apple_developer_team_id : Optional [str ]
165
+ hardlink_cs_files : bool
155
166
156
167
def parse (self ) -> ParsedFlags :
157
168
self ._load_defaults_file ()
@@ -167,6 +178,7 @@ def _to_parsed_flags(self) -> ParsedFlags:
167
178
google_service_info_plist_file = self .google_service_info_plist_file ,
168
179
android_package_name = self .android_package_name ,
169
180
apple_developer_team_id = self .apple_developer_team_id ,
181
+ hardlink_cs_files = FLAG_HARDLINK_CS_FILES .value ,
170
182
)
171
183
172
184
def _load_defaults_file (self ) -> None :
@@ -218,6 +230,8 @@ def _load_flag_values(self) -> None:
218
230
self ._log_using_flag_from_command_line (FLAG_APPLE_DEVELOPER_TEAM_ID )
219
231
self .apple_developer_team_id = FLAG_APPLE_DEVELOPER_TEAM_ID .value
220
232
233
+ self ._log_using_flag_from_command_line (FLAG_HARDLINK_CS_FILES )
234
+
221
235
@classmethod
222
236
def _log_using_flag_from_command_line (cls , flag : flags .Flag ) -> None :
223
237
logging .info ("Using flag from command line: --%s=%s" , flag .name , flag .value )
@@ -278,6 +292,7 @@ def __init__(
278
292
google_service_info_plist_file : Optional [pathlib .Path ],
279
293
android_package_name : Optional [str ],
280
294
apple_developer_team_id : Optional [str ],
295
+ hardlink_cs_files : bool ,
281
296
) -> None :
282
297
self .git_repo_dir = git_repo_dir
283
298
self .dest_dir_2017 = dest_dir_2017
@@ -286,6 +301,7 @@ def __init__(
286
301
self .google_service_info_plist_file = google_service_info_plist_file
287
302
self .android_package_name = android_package_name
288
303
self .apple_developer_team_id = apple_developer_team_id
304
+ self .hardlink_cs_files = hardlink_cs_files
289
305
290
306
def run (self ) -> None :
291
307
something_done = False
@@ -349,15 +365,23 @@ def _run(self, dest_dir: pathlib.Path, unity_version: int) -> None:
349
365
project_settings_file = dest_dir / "ProjectSettings" / "ProjectSettings.asset"
350
366
self ._update_unity_app_info (project_settings_file , android_package_name , bundle_id )
351
367
352
- @classmethod
353
- def _copy_file (cls , src_file : pathlib .Path , dest_file : pathlib .Path ) -> None :
368
+ # A drop-in replacement for `shutil.copy()` that creates hard links for some files
369
+ # if hardlink_cs_files=True was specified to __init__().
370
+ def _copy (self , src , dst , * , follow_symlinks = True ):
371
+ if self .hardlink_cs_files and str (src ).endswith (".cs" ):
372
+ src_file = pathlib .Path (src )
373
+ dst_file = pathlib .Path (dst )
374
+ src_file .link_to (dst_file )
375
+ else :
376
+ shutil .copy (src , dst , follow_symlinks = follow_symlinks )
377
+
378
+ def _copy_file (self , src_file : pathlib .Path , dest_file : pathlib .Path ) -> None :
354
379
logging .info ("Copying %s to %s" , src_file , dest_file )
355
- shutil . copy (src_file , dest_file )
380
+ self . _copy (src_file , dest_file )
356
381
357
- @classmethod
358
- def _copy_tree (cls , src_dir : pathlib .Path , dest_dir : pathlib .Path ) -> None :
382
+ def _copy_tree (self , src_dir : pathlib .Path , dest_dir : pathlib .Path ) -> None :
359
383
logging .info ("Copying %s to %s" , src_dir , dest_dir )
360
- shutil .copytree (src_dir , dest_dir )
384
+ shutil .copytree (src_dir , dest_dir , copy_function = self . _copy )
361
385
362
386
@classmethod
363
387
def _rmtree (cls , dir_path : pathlib .Path ) -> None :
0 commit comments