diff options
| author | Aleksey Kliger <aleksey@lambdageek.org> | 2025-07-08 07:34:51 -0400 |
|---|---|---|
| committer | Aleksey Kliger <aleksey@lambdageek.org> | 2025-07-08 07:37:44 -0400 |
| commit | 3ba8e330f9960a52b2c8ca10c8cba425514919f9 (patch) | |
| tree | 76ffc2129b57d7506168652bd922be73980e0119 | |
| parent | b6d21308672c9a0aa5c73beeb1d528aab3d347ed (diff) | |
| download | rust-3ba8e330f9960a52b2c8ca10c8cba425514919f9.tar.gz rust-3ba8e330f9960a52b2c8ca10c8cba425514919f9.zip | |
Rewrite for clarity
move common code to a helper function Co-Authored-By: Kobzol <berykubik@gmail.com>
| -rwxr-xr-x | src/bootstrap/configure.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 94e02f942dc..86208b94261 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -744,22 +744,24 @@ def write_uncommented(target, f): A block is a sequence of non-empty lines separated by empty lines. """ block = [] - is_comment = True + + def flush(last): + # If the block is entiry made of comments, ignore it + entire_block_comments = all(ln.startswith("#") or ln == "" for ln in block) + if not entire_block_comments and len(block) > 0: + for line in block: + f.write(line + "\n") + # Required to output a newline before the start of a new section + if last: + f.write("\n") + block.clear() for line in target: block.append(line) if len(line) == 0: - if not is_comment: - for ln in block: - f.write(ln + "\n") - block = [] - is_comment = True - continue - is_comment = is_comment and line.startswith("#") - # Write the last accumulated block - if len(block) > 0 and not is_comment: - for ln in block: - f.write(ln + "\n") + flush(last=False) + + flush(last=True) return f |
