@@ -44,6 +44,68 @@ from lib.workspace import Workspace
44
44
45
45
import sys
46
46
47
+ def reconfigure (config , path ):
48
+ with open (path , 'r' ) as infile :
49
+ info = json .load (infile )
50
+ if 'version' in info and info ['version' ] == config .version :
51
+ if 'command' in info :
52
+ config .command = info ['command' ]
53
+ if 'project' in info :
54
+ config .command = info ['project' ]
55
+ if 'script_path' in info :
56
+ config .script_path = Path (info ['script_path' ])
57
+ if 'build_script_path' in info :
58
+ config .build_script_path = Path (info ['build_script_path' ])
59
+ if 'source_root' in info :
60
+ config .source_root = Path (info ['source_root' ])
61
+ if 'target' in info :
62
+ config .target = Target (info ['target' ])
63
+ if 'system_root' in info :
64
+ config .system_root = Path (info ['system_root' ])
65
+ if 'toolchain' in info :
66
+ config .toolchain = info ['toolchain' ]
67
+ if 'build_directory' in info :
68
+ config .build_directory = Path (info ['build_directory' ])
69
+ if 'intermediate_directory' in info :
70
+ config .intermediate_directory = Path (info ['intermediate_directory' ])
71
+ if 'module_cache_directory' in info :
72
+ config .module_cache_directory = Path (info ['module_cache_directory' ])
73
+ if 'install_directory' in info :
74
+ config .install_directory = Path (info ['install_directory' ])
75
+ if 'prefix' in info :
76
+ config .prefix = info ['prefix' ]
77
+ if 'swift_install' in info :
78
+ config .swift_install = info ['swift_install' ]
79
+ if 'clang' in info :
80
+ config .clang = info ['clang' ]
81
+ if 'clangxx' in info :
82
+ config .clangxx = info ['clangxx' ]
83
+ if 'swift' in info :
84
+ config .swift = info ['swift' ]
85
+ if 'swiftc' in info :
86
+ config .swiftc = info ['swiftc' ]
87
+ if 'ar' in info :
88
+ config .ar = info ['ar' ]
89
+ if 'swift_sdk' in info :
90
+ config .swift_sdk = info ['swift_sdk' ]
91
+ if 'bootstrap_directory' in info :
92
+ config .bootstrap_directory = Path (info ['bootstrap_directory' ])
93
+ if 'verbose' in info :
94
+ config .verbose = info ['verbose' ]
95
+ if 'extra_c_flags' in info :
96
+ config .extra_c_flags = info ['extra_c_flags' ]
97
+ if 'extra_swift_flags' in info :
98
+ config .extra_swift_flags = info ['extra_swift_flags' ]
99
+ if 'extra_ld_flags' in info :
100
+ config .extra_ld_flags = info ['extra_ld_flags' ]
101
+ if 'build_mode' in info :
102
+ config .build_mode = info ['build_mode' ]
103
+ if 'variables' in info :
104
+ config .variables = info ['variables' ]
105
+ else :
106
+ sys .exit ("invalid version" )
107
+
108
+
47
109
def main ():
48
110
config = Configuration ()
49
111
CWD = Path .path (os .getcwd ())
@@ -64,49 +126,56 @@ def main():
64
126
config .swift_sdk = os .getenv ("SDKROOT" , None )
65
127
config .script_path = config .source_root .path_by_appending ("build.py" )
66
128
config .build_script_path = config .source_root .path_by_appending ("build.ninja" )
129
+ config .config_path = config .source_root .path_by_appending (".configuration" )
67
130
68
131
parser = argparse .ArgumentParser (description = 'Configure and emit ninja build scripts for building.' )
69
132
parser .add_argument ('--target' , dest = 'target' , type = str , default = Target .default ())
70
133
parser .add_argument ('--sysroot' , dest = 'sysroot' , type = str , default = None )
71
134
parser .add_argument ('--toolchain' , dest = 'toolchain' , type = str , default = None )
72
135
parser .add_argument ('--bootstrap' , dest = 'bootstrap' , type = str , default = os .path .join (os .path .dirname (os .path .abspath (__file__ )), "bootstrap" ))
136
+ parser .add_argument ('--reconfigure' , dest = 'reconfigure' , action = "store_true" )
73
137
parser .add_argument ('-v' , '--verbose' , dest = 'verbose' , action = "store_true" )
74
138
args , extras = parser .parse_known_args ()
75
-
76
- config .build_mode = Configuration .Debug # by default build in debug mode
77
-
78
- for arg in extras :
79
- if arg .lower () == 'debug' :
80
- config .build_mode = Configuration .Debug
81
- elif arg .lower () == 'release' :
82
- config .build_mode = Configuration .Release
83
- elif arg .startswith ('-D' ): # accept -DNAME=value as extra parameters to the configuration of the build.ninja
84
- key , val = arg [2 :].split ("=" , 1 )
85
- config .variables [key ] = val
86
-
87
- config .command = [os .path .abspath (__file__ )] + sys .argv [1 :]
88
-
89
- config .target = Target (args .target )
90
-
91
- config .system_root = Path .path (args .sysroot )
92
- if config .target .sdk == OSType .MacOSX and config .system_root is None and Target (Target .default ()).sdk == OSType .MacOSX :
93
- import subprocess
94
- config .system_root = Path .path (subprocess .Popen (['xcrun' , '--show-sdk-path' ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , stdin = subprocess .PIPE ).communicate ()[0 ])
95
- swift_path = Path .path (subprocess .Popen (['xcrun' , '--find' , 'swift' ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , stdin = subprocess .PIPE ).communicate ()[0 ]).parent ().parent ()
96
- config .swift_sdk = swift_path .absolute ()
97
- elif config .swift_sdk is None :
98
- config .swift_sdk = "/usr"
99
- config .toolchain = Path .path (args .toolchain )
100
- config .bootstrap_directory = Path .path (args .bootstrap )
101
- config .verbose = args .verbose
102
- if config .toolchain is not None :
103
- config .ar = os .path .join (config .toolchain .relative (), "bin" , "ar" )
104
- elif config .ar is None :
105
- config .ar = "ar"
106
-
139
+
140
+ if args .reconfigure :
141
+ reconfigure (config , config .config_path .absolute ())
142
+ else :
143
+ config .build_mode = Configuration .Debug # by default build in debug mode
144
+
145
+ for arg in extras :
146
+ if arg .lower () == 'debug' :
147
+ config .build_mode = Configuration .Debug
148
+ elif arg .lower () == 'release' :
149
+ config .build_mode = Configuration .Release
150
+ elif arg .startswith ('-D' ): # accept -DNAME=value as extra parameters to the configuration of the build.ninja
151
+ key , val = arg [2 :].split ("=" , 1 )
152
+ config .variables [key ] = val
153
+
154
+ config .command = [os .path .abspath (__file__ )] + sys .argv [1 :]
155
+
156
+ config .target = Target (args .target )
157
+
158
+ config .system_root = Path .path (args .sysroot )
159
+ if config .target .sdk == OSType .MacOSX and config .system_root is None and Target (Target .default ()).sdk == OSType .MacOSX :
160
+ import subprocess
161
+ config .system_root = Path .path (subprocess .Popen (['xcrun' , '--show-sdk-path' ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , stdin = subprocess .PIPE ).communicate ()[0 ])
162
+ swift_path = Path .path (subprocess .Popen (['xcrun' , '--find' , 'swift' ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , stdin = subprocess .PIPE ).communicate ()[0 ]).parent ().parent ()
163
+ config .swift_sdk = swift_path .absolute ()
164
+ elif config .swift_sdk is None :
165
+ config .swift_sdk = "/usr"
166
+ config .toolchain = Path .path (args .toolchain )
167
+ config .bootstrap_directory = Path .path (args .bootstrap )
168
+ config .verbose = args .verbose
169
+ if config .toolchain is not None :
170
+ config .ar = os .path .join (config .toolchain .relative (), "bin" , "ar" )
171
+ elif config .ar is None :
172
+ config .ar = "ar"
173
+
174
+ config .write (config .config_path .absolute ())
107
175
Configuration .current = config
108
176
109
177
execfile (config .script_path .absolute ())
110
178
179
+
111
180
if __name__ == "__main__" :
112
181
main ()
0 commit comments