Skip to content

Commit 0f522c2

Browse files
committed
Remove deserializing/reserializing toml from configure.py
1 parent 827a0d6 commit 0f522c2

File tree

2 files changed

+202
-184
lines changed

2 files changed

+202
-184
lines changed

src/bootstrap/bootstrap_test.py

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def serialize_and_parse(configure_args, bootstrap_args=None):
2626
if bootstrap_args is None:
2727
bootstrap_args = bootstrap.FakeArgs()
2828

29-
section_order, sections, targets = configure.parse_args(configure_args)
29+
config = configure.parse_args(configure_args)
3030
buffer = StringIO()
31-
configure.write_config_toml(buffer, section_order, targets, sections)
31+
configure.write_config_toml(buffer, config)
3232
build = bootstrap.RustBuild(config_toml=buffer.getvalue(), args=bootstrap_args)
3333

3434
try:
@@ -108,50 +108,69 @@ def test_same_dates(self):
108108
)
109109

110110

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"""
113113

114114
@patch("configure.err")
115115
def test_unknown_args(self, err):
116116
# 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"])
118118
err.assert_called_with("Option 'enable-full-tools' is not recognized")
119119
err.reset_mock()
120120
# 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"])
122122
err.assert_called_with("Option '--some-random-flag' is not recognized")
123123

124124
@patch("configure.err")
125125
def test_need_value_args(self, err):
126126
"""It should print an error message if a required argument value is missing"""
127-
configure.parse_args(["--target"])
127+
configure.validate_args(["--target"])
128128
err.assert_called_with("Option '--target' needs a value (--target=val)")
129129

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+
130140
@patch("configure.err")
131141
def test_option_checking(self, err):
132142
# Options should be checked even if `--enable-option-checking` is not passed
133-
configure.parse_args(["--target"])
143+
configure.validate_args(["--target"])
134144
err.assert_called_with("Option '--target' needs a value (--target=val)")
135145
err.reset_mock()
136146
# 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"])
138148
err.assert_called_with("Option '--target' needs a value (--target=val)")
139149
err.reset_mock()
140150
# 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"])
142152
err.assert_not_called()
143153

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+
145164
def test_known_args(self):
146165
# 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"])
148167
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"])
150169
self.assertFalse(known_args["full-tools"][0][1])
151170
# 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"])
153172
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"])
155174
self.assertEqual(known_args["target"][0][1], "x86_64-unknown-linux-gnu")
156175

157176

@@ -173,6 +192,30 @@ def test_set_target(self):
173192
build.get_toml("cc", section="target.x86_64-unknown-linux-gnu"), "gcc"
174193
)
175194

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+
176219
def test_set_top_level(self):
177220
build = serialize_and_parse(["--set", "profile=compiler"])
178221
self.assertEqual(build.get_toml("profile"), "compiler")

0 commit comments

Comments
 (0)