@@ -20,6 +20,8 @@ import time
20
20
21
21
from build_swift import defaults
22
22
from build_swift import driver_arguments
23
+ from build_swift import presets
24
+ from build_swift .migration import migrate_swift_sdks
23
25
24
26
from swift_build_support .swift_build_support import (
25
27
arguments ,
@@ -32,16 +34,12 @@ from swift_build_support.swift_build_support import (
32
34
targets ,
33
35
workspace
34
36
)
35
-
36
37
from swift_build_support .swift_build_support .SwiftBuildSupport import (
37
38
HOME ,
38
39
SWIFT_BUILD_ROOT ,
39
40
SWIFT_REPO_NAME ,
40
41
SWIFT_SOURCE_ROOT ,
41
- get_all_preset_names ,
42
- get_preset_options ,
43
42
)
44
-
45
43
from swift_build_support .swift_build_support .cmake import CMake
46
44
from swift_build_support .swift_build_support .targets import \
47
45
StdlibDeploymentTarget
@@ -977,42 +975,63 @@ def main_preset():
977
975
978
976
if len (args .preset_file_names ) == 0 :
979
977
args .preset_file_names = [
980
- os .path .join (HOME , ".swift-build-presets" ),
981
978
os .path .join (
982
979
SWIFT_SOURCE_ROOT , SWIFT_REPO_NAME , "utils" ,
983
980
"build-presets.ini" )
984
981
]
985
982
983
+ user_presets_file = os .path .join (HOME , '.swift-build-presets' )
984
+ if os .path .isfile (user_presets_file ):
985
+ args .preset_file_names .append (user_presets_file )
986
+
987
+ preset_parser = presets .PresetParser ()
988
+
989
+ try :
990
+ preset_parser .read (args .preset_file_names )
991
+ except presets .UnparsedFilesError as e :
992
+ diagnostics .fatal ('unable to parse preset files {}'
993
+ .format (e .message ))
994
+
986
995
if args .show_presets :
987
- for name in sorted (get_all_preset_names ( args . preset_file_names ),
988
- key = str .lower ):
996
+ for name in sorted (preset_parser . preset_names ( ),
997
+ key = lambda name : name .lower () ):
989
998
print (name )
990
999
return 0
991
1000
992
1001
if not args .preset :
993
1002
diagnostics .fatal ("missing --preset option" )
994
1003
995
1004
args .preset_substitutions = {}
996
-
997
1005
for arg in args .preset_substitutions_raw :
998
1006
name , value = arg .split ("=" , 1 )
999
1007
args .preset_substitutions [name ] = value
1000
1008
1001
- preset_args = get_preset_options (
1002
- args .preset_substitutions , args .preset_file_names , args .preset )
1009
+ try :
1010
+ preset = preset_parser .get_preset (args .preset ,
1011
+ vars = args .preset_substitutions )
1012
+ except presets .InterpolationError as e :
1013
+ diagnostics .fatal ('missing value for substitution "{}" in preset "{}"'
1014
+ .format (e .message , args .preset ))
1015
+ except presets .MissingOptionError as e :
1016
+ diagnostics .fatal ('missing option(s) for preset "{}": {}'
1017
+ .format (args .preset , e .message ))
1018
+ except presets .PresetNotFoundError :
1019
+ diagnostics .fatal ('preset "{}" not found' .format (args .preset ))
1020
+
1021
+ preset_args = migrate_swift_sdks (preset .format_args ())
1003
1022
1004
1023
build_script_args = [sys .argv [0 ]]
1005
1024
if args .dry_run :
1006
1025
build_script_args += ["--dry-run" ]
1026
+
1007
1027
build_script_args += preset_args
1008
1028
if args .distcc :
1009
1029
build_script_args += ["--distcc" ]
1010
1030
if args .build_jobs :
1011
1031
build_script_args += ["--jobs" , str (args .build_jobs )]
1012
1032
1013
- diagnostics .note (
1014
- "using preset '" + args .preset + "', which expands to \n \n " +
1015
- shell .quote_command (build_script_args ) + "\n " )
1033
+ diagnostics .note ('using preset "{}", which expands to \n \n {}\n ' .format (
1034
+ args .preset , shell .quote_command (build_script_args )))
1016
1035
1017
1036
if args .expand_build_script_invocation :
1018
1037
return 0
0 commit comments