@@ -26,9 +26,9 @@ def serialize_and_parse(configure_args, bootstrap_args=None):
26
26
if bootstrap_args is None :
27
27
bootstrap_args = bootstrap .FakeArgs ()
28
28
29
- section_order , sections , targets = configure .parse_args (configure_args )
29
+ config = configure .parse_args (configure_args )
30
30
buffer = StringIO ()
31
- configure .write_config_toml (buffer , section_order , targets , sections )
31
+ configure .write_config_toml (buffer , config )
32
32
build = bootstrap .RustBuild (config_toml = buffer .getvalue (), args = bootstrap_args )
33
33
34
34
try :
@@ -108,50 +108,69 @@ def test_same_dates(self):
108
108
)
109
109
110
110
111
- class ParseArgsInConfigure (unittest .TestCase ):
112
- """Test if `parse_args ` function in `configure.py` works properly"""
111
+ class ValidateArgsInConfigure (unittest .TestCase ):
112
+ """Test if `validate_args ` function in `configure.py` works properly"""
113
113
114
114
@patch ("configure.err" )
115
115
def test_unknown_args (self , err ):
116
116
# It should be print an error message if the argument doesn't start with '--'
117
- configure .parse_args (["enable-full-tools" ])
117
+ configure .validate_args (["enable-full-tools" ])
118
118
err .assert_called_with ("Option 'enable-full-tools' is not recognized" )
119
119
err .reset_mock ()
120
120
# It should be print an error message if the argument is not recognized
121
- configure .parse_args (["--some-random-flag" ])
121
+ configure .validate_args (["--some-random-flag" ])
122
122
err .assert_called_with ("Option '--some-random-flag' is not recognized" )
123
123
124
124
@patch ("configure.err" )
125
125
def test_need_value_args (self , err ):
126
126
"""It should print an error message if a required argument value is missing"""
127
- configure .parse_args (["--target" ])
127
+ configure .validate_args (["--target" ])
128
128
err .assert_called_with ("Option '--target' needs a value (--target=val)" )
129
129
130
+ @patch ("configure.err" )
131
+ def test_duplicate_args (self , err ):
132
+ """It should print an error message if an option is passed more than once"""
133
+ configure .validate_args (["--enable-sccache" , "--enable-sccache" ])
134
+ err .assert_called_with ("Option 'sccache' provided more than once" )
135
+ err .reset_mock ()
136
+
137
+ configure .validate_args (["--enable-sccache" , "--disable-sccache" ])
138
+ err .assert_called_with ("Option 'sccache' provided more than once" )
139
+
130
140
@patch ("configure.err" )
131
141
def test_option_checking (self , err ):
132
142
# Options should be checked even if `--enable-option-checking` is not passed
133
- configure .parse_args (["--target" ])
143
+ configure .validate_args (["--target" ])
134
144
err .assert_called_with ("Option '--target' needs a value (--target=val)" )
135
145
err .reset_mock ()
136
146
# Options should be checked if `--enable-option-checking` is passed
137
- configure .parse_args (["--enable-option-checking" , "--target" ])
147
+ configure .validate_args (["--enable-option-checking" , "--target" ])
138
148
err .assert_called_with ("Option '--target' needs a value (--target=val)" )
139
149
err .reset_mock ()
140
150
# Options should not be checked if `--disable-option-checking` is passed
141
- configure .parse_args (["--disable-option-checking" , "--target" ])
151
+ configure .validate_args (["--disable-option-checking" , "--target" ])
142
152
err .assert_not_called ()
143
153
144
- @patch ("configure.parse_example_config" , lambda known_args , _ : known_args )
154
+ @patch ("configure.p" )
155
+ def test_warns_on_rpm_args (self , p ):
156
+ """It should print a warning if rpm args are passed, and ignore them"""
157
+ configure .validate_args (["--infodir=/usr/share/info" ])
158
+ p .assert_called_with ("WARNING: infodir will be ignored" )
159
+ p .reset_mock ()
160
+
161
+ configure .validate_args (["--localstatedir=/var/lib/info" ])
162
+ p .assert_called_with ("WARNING: localstatedir will be ignored" )
163
+
145
164
def test_known_args (self ):
146
165
# It should contain known and correct arguments
147
- known_args = configure .parse_args (["--enable-full-tools" ])
166
+ known_args = configure .validate_args (["--enable-full-tools" ])
148
167
self .assertTrue (known_args ["full-tools" ][0 ][1 ])
149
- known_args = configure .parse_args (["--disable-full-tools" ])
168
+ known_args = configure .validate_args (["--disable-full-tools" ])
150
169
self .assertFalse (known_args ["full-tools" ][0 ][1 ])
151
170
# It should contain known arguments and their values
152
- known_args = configure .parse_args (["--target=x86_64-unknown-linux-gnu" ])
171
+ known_args = configure .validate_args (["--target=x86_64-unknown-linux-gnu" ])
153
172
self .assertEqual (known_args ["target" ][0 ][1 ], "x86_64-unknown-linux-gnu" )
154
- known_args = configure .parse_args (["--target" , "x86_64-unknown-linux-gnu" ])
173
+ known_args = configure .validate_args (["--target" , "x86_64-unknown-linux-gnu" ])
155
174
self .assertEqual (known_args ["target" ][0 ][1 ], "x86_64-unknown-linux-gnu" )
156
175
157
176
@@ -173,6 +192,30 @@ def test_set_target(self):
173
192
build .get_toml ("cc" , section = "target.x86_64-unknown-linux-gnu" ), "gcc"
174
193
)
175
194
195
+ def test_set_target_option (self ):
196
+ build = serialize_and_parse (["--build=x86_64-unknown-linux-gnu" , "--llvm-config=/usr/bin/llvm-config" ])
197
+ self .assertEqual (
198
+ build .get_toml ("llvm-config" , section = "target.x86_64-unknown-linux-gnu" ), "/usr/bin/llvm-config"
199
+ )
200
+
201
+ def test_set_targets (self ):
202
+ # Multiple targets can be set
203
+ build = serialize_and_parse (["--set" , "target.x86_64-unknown-linux-gnu.cc=gcc" , "--set" , "target.aarch64-apple-darwin.cc=clang" ])
204
+ self .assertEqual (
205
+ build .get_toml ("cc" , section = "target.x86_64-unknown-linux-gnu" ), "gcc"
206
+ )
207
+ self .assertEqual (
208
+ build .get_toml ("cc" , section = "target.aarch64-apple-darwin" ), "clang"
209
+ )
210
+
211
+ build = serialize_and_parse (["--target" , "x86_64-unknown-linux-gnu,aarch64-apple-darwin" ])
212
+ self .assertNotEqual (
213
+ build .config_toml .find ("target.aarch64-apple-darwin" ), - 1
214
+ )
215
+ self .assertNotEqual (
216
+ build .config_toml .find ("target.x86_64-unknown-linux-gnu" ), - 1
217
+ )
218
+
176
219
def test_set_top_level (self ):
177
220
build = serialize_and_parse (["--set" , "profile=compiler" ])
178
221
self .assertEqual (build .get_toml ("profile" ), "compiler" )
0 commit comments