6
6
import shlex
7
7
import sys
8
8
import os
9
+ import re
9
10
10
11
rust_dir = os .path .dirname (os .path .abspath (__file__ ))
11
12
rust_dir = os .path .dirname (rust_dir )
@@ -585,16 +586,31 @@ def parse_example_config(known_args, config):
585
586
section_order = [None ]
586
587
targets = {}
587
588
top_level_keys = []
589
+ comment_lines = []
588
590
589
591
with open (rust_dir + "/bootstrap.example.toml" ) as example_config :
590
592
example_lines = example_config .read ().split ("\n " )
591
593
for line in example_lines :
592
- if cur_section is None :
593
- if line .count ("=" ) == 1 :
594
- top_level_key = line .split ("=" )[0 ]
595
- top_level_key = top_level_key .strip (" #" )
596
- top_level_keys .append (top_level_key )
597
- if line .startswith ("[" ):
594
+ if line .count ("=" ) == 1 and not line .startswith ("# " ):
595
+ key = line .split ("=" )[0 ]
596
+ key = key .strip (" #" )
597
+ parts = key .split ("." )
598
+ if len (parts ) > 1 :
599
+ cur_section = parts [0 ]
600
+ if cur_section not in sections :
601
+ sections [cur_section ] = ["[" + cur_section + "]" ]
602
+ section_order .append (cur_section )
603
+ elif cur_section is None :
604
+ top_level_keys .append (key )
605
+ # put the comment lines within the start of
606
+ # a new section, not outside it.
607
+ sections [cur_section ] += comment_lines
608
+ comment_lines = []
609
+ # remove just the `section.` part from the line, if present.
610
+ sections [cur_section ].append (
611
+ re .sub ("(#?)([a-zA-Z_-]+\\ .)?(.*)" , "\\ 1\\ 3" , line )
612
+ )
613
+ elif line .startswith ("[" ):
598
614
cur_section = line [1 :- 1 ]
599
615
if cur_section .startswith ("target" ):
600
616
cur_section = "target"
@@ -605,8 +621,9 @@ def parse_example_config(known_args, config):
605
621
sections [cur_section ] = [line ]
606
622
section_order .append (cur_section )
607
623
else :
608
- sections [ cur_section ] .append (line )
624
+ comment_lines .append (line )
609
625
626
+ sections [cur_section ] += comment_lines
610
627
# Fill out the `targets` array by giving all configured targets a copy of the
611
628
# `target` section we just loaded from the example config
612
629
configured_targets = [build (known_args )]
0 commit comments