Skip to content

Commit

Permalink
Fix issue with comments in COMMAND of add_custom_command (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlankSpruce committed Mar 4, 2024
1 parent d41db4b commit 68af084
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
### Added
- support for new keywords in native commands and new commands available in CMake 3.29

### Fixed
- fix issue with comments in `COMMAND` argument of `add_custom_command` (#16)

## [0.11.0] 2024-01-11
### Added
- Number of workers spawned for formatting multiple files can be changed with `-w/--workers`. By default it will be number of CPUs available in the system but limited to 60 for Windows machines due to [this](https://github.com/python/cpython/issues/89240).
Expand All @@ -15,7 +18,7 @@
- support for Python 3.12

### Fixed
- meaningless but syntactically valid `target_link_libraries` with just library name won't crash gersemi
- meaningless but syntactically valid `target_link_libraries` with just library name won't crash gersemi (#13)

## [0.9.4] 2023-12-17
### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ You can use gersemi with a pre-commit hook by adding the following to `.pre-comm
```yaml
repos:
- repo: https://github.com/BlankSpruce/gersemi
rev: 0.11.0
rev: 0.11.1
hooks:
- id: gersemi
```
Expand Down
2 changes: 1 addition & 1 deletion gersemi/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
__license__ = "MPL 2.0"
__title__ = "gersemi"
__url__ = "https://github.com/BlankSpruce/gersemi"
__version__ = "0.11.0"
__version__ = "0.11.1"
10 changes: 8 additions & 2 deletions gersemi/command_line_formatter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gersemi.ast_helpers import is_line_comment
from gersemi.ast_helpers import is_line_comment, is_commented_argument
from gersemi.base_dumper import BaseDumper


Expand All @@ -11,6 +11,7 @@ def _should_start_new_line(self, updated_line, last_line):
)

def _format_command_line(self, args):
force_next_line = False
head, *tail = args
lines = [self.visit(head)]
for arg in tail:
Expand All @@ -21,8 +22,13 @@ def _format_command_line(self, args):
with self.not_indented():
formatted_arg = self.visit(arg)
updated_line = f"{lines[-1]} {formatted_arg}"
if self._should_start_new_line(updated_line, lines[-1]):
if force_next_line or self._should_start_new_line(updated_line, lines[-1]):
force_next_line = False
lines += [self.visit(arg)]
else:
lines[-1] = updated_line
if is_commented_argument(arg):
print(arg)
force_next_line = True

return "\n".join(lines)
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def imap_unordered(
def formatter_creator():
def creator(config):
return create_formatter(
do_sanity_check=False,
do_sanity_check=not config.get("unsafe", False),
line_length=config.get("line_length", 80),
custom_command_definitions=get_custom_command_definitions(
config.get("definitions", [])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### {unsafe: true}
add_custom_command(OUTPUT src.tar.zst DEPENDS ${SRC} COMMAND
set -euo pipefail # line comment
&& tar -c src | zstd --ultra -22 > src.tar.zst #
)

add_custom_command(OUTPUT src.tar.zst DEPENDS ${SRC} COMMAND
set -euo pipefail #[[bracket comment]]
&& tar -c src | zstd --ultra -22 > src.tar.zst #
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
add_custom_command(
OUTPUT src.tar.zst
DEPENDS ${SRC}
COMMAND
set -euo pipefail # line comment
&& tar -c src | zstd --ultra -22 > src.tar.zst #
)

add_custom_command(
OUTPUT src.tar.zst
DEPENDS ${SRC}
COMMAND
set -euo pipefail #[[bracket comment]]
&& tar -c src | zstd --ultra -22 > src.tar.zst #
)

0 comments on commit 68af084

Please sign in to comment.