@@ -393,6 +393,58 @@ def invoke_query(self, query_args):
393393 print (subprocess .list2cmdline (combined_arguments ))
394394 call_executable (combined_arguments )
395395
396+ def get_spm_aspect_invocation (self ):
397+ combined_arguments = [
398+ self .build_environment .bazel_path
399+ ]
400+ combined_arguments += self .get_startup_bazel_arguments ()
401+ combined_arguments += ['build' ]
402+
403+ if self .custom_target is not None :
404+ combined_arguments += [self .custom_target ]
405+ else :
406+ combined_arguments += ['Telegram/Telegram' ]
407+
408+ if self .continue_on_error :
409+ combined_arguments += ['--keep_going' ]
410+ if self .show_actions :
411+ combined_arguments += ['--subcommands' ]
412+
413+ if self .enable_sandbox :
414+ combined_arguments += ['--spawn_strategy=sandboxed' ]
415+
416+ if self .disable_provisioning_profiles :
417+ combined_arguments += ['--//Telegram:disableProvisioningProfiles' ]
418+
419+ if self .configuration_path is None :
420+ raise Exception ('configuration_path is not defined' )
421+
422+ combined_arguments += [
423+ '--override_repository=build_configuration={}' .format (self .configuration_path )
424+ ]
425+
426+ combined_arguments += self .common_args
427+ combined_arguments += self .common_build_args
428+ combined_arguments += self .get_define_arguments ()
429+ combined_arguments += self .get_additional_build_arguments ()
430+
431+ if self .remote_cache is not None :
432+ combined_arguments += [
433+ '--remote_cache={}' .format (self .remote_cache ),
434+ '--experimental_remote_downloader={}' .format (self .remote_cache )
435+ ]
436+ elif self .cache_dir is not None :
437+ combined_arguments += [
438+ '--disk_cache={path}' .format (path = self .cache_dir )
439+ ]
440+
441+ combined_arguments += self .configuration_args
442+
443+ combined_arguments += ['--aspects' , '//build-system/bazel-utils:spm.bzl%spm_text_aspect' ]
444+
445+ print (subprocess .list2cmdline (combined_arguments ))
446+ call_executable (combined_arguments )
447+
396448
397449def clean (bazel , arguments ):
398450 bazel_command_line = BazelCommandLine (
@@ -696,6 +748,36 @@ def query(bazel, arguments):
696748 bazel_command_line .invoke_query (query_args )
697749
698750
751+ def get_spm_aspect_invocation (bazel , arguments ):
752+ bazel_command_line = BazelCommandLine (
753+ bazel = bazel ,
754+ override_bazel_version = arguments .overrideBazelVersion ,
755+ override_xcode_version = arguments .overrideXcodeVersion ,
756+ bazel_user_root = arguments .bazelUserRoot
757+ )
758+
759+ if arguments .cacheDir is not None :
760+ bazel_command_line .add_cache_dir (arguments .cacheDir )
761+ elif arguments .cacheHost is not None :
762+ bazel_command_line .add_remote_cache (arguments .cacheHost )
763+
764+ resolve_configuration (
765+ base_path = os .getcwd (),
766+ bazel_command_line = bazel_command_line ,
767+ arguments = arguments ,
768+ additional_codesigning_output_path = None
769+ )
770+
771+ bazel_command_line .set_configuration (arguments .configuration )
772+ bazel_command_line .set_build_number (arguments .buildNumber )
773+ bazel_command_line .set_custom_target (arguments .target )
774+ bazel_command_line .set_continue_on_error (False )
775+ bazel_command_line .set_show_actions (False )
776+ bazel_command_line .set_enable_sandbox (False )
777+ bazel_command_line .set_split_swiftmodules (False )
778+
779+ bazel_command_line .get_spm_aspect_invocation ()
780+
699781def add_codesigning_common_arguments (current_parser : argparse .ArgumentParser ):
700782 configuration_group = current_parser .add_mutually_exclusive_group (required = True )
701783 configuration_group .add_argument (
@@ -1121,6 +1203,38 @@ def add_project_and_build_common_arguments(current_parser: argparse.ArgumentPars
11211203 metavar = 'query_string'
11221204 )
11231205
1206+ spm_parser = subparsers .add_parser ('spm' , help = 'Generate SPM package' )
1207+ spm_parser .add_argument (
1208+ '--target' ,
1209+ type = str ,
1210+ help = 'A custom bazel target name to build.' ,
1211+ metavar = 'target_name'
1212+ )
1213+ spm_parser .add_argument (
1214+ '--buildNumber' ,
1215+ required = False ,
1216+ type = int ,
1217+ default = 10000 ,
1218+ help = 'Build number.' ,
1219+ metavar = 'number'
1220+ )
1221+ spm_parser .add_argument (
1222+ '--configuration' ,
1223+ choices = [
1224+ 'debug_universal' ,
1225+ 'debug_arm64' ,
1226+ 'debug_armv7' ,
1227+ 'debug_sim_arm64' ,
1228+ 'release_sim_arm64' ,
1229+ 'release_arm64' ,
1230+ 'release_armv7' ,
1231+ 'release_universal'
1232+ ],
1233+ required = True ,
1234+ help = 'Build configuration'
1235+ )
1236+ add_codesigning_common_arguments (spm_parser )
1237+
11241238 if len (sys .argv ) < 2 :
11251239 parser .print_help ()
11261240 sys .exit (1 )
@@ -1229,6 +1343,8 @@ def add_project_and_build_common_arguments(current_parser: argparse.ArgumentPars
12291343 test (bazel = bazel_path , arguments = args )
12301344 elif args .commandName == 'query' :
12311345 query (bazel = bazel_path , arguments = args )
1346+ elif args .commandName == 'spm' :
1347+ get_spm_aspect_invocation (bazel = bazel_path , arguments = args )
12321348 else :
12331349 raise Exception ('Unknown command' )
12341350 except KeyboardInterrupt :
0 commit comments