Skip to content

Commit

Permalink
build: replace "\\" with "\" in raw string
Browse files Browse the repository at this point in the history
in Python, a raw string is created using 'r' or 'R' prefix. when
creating the regex using Python string, sometimes, we have to use
"\" to escape the parenthesis so the tools like "sed" can consider
the parenthesis as a capture group. but "\" is also used to escape
strings in Python, in order to put "\" as it is, we use "\" instead
of escaping "\" with "\\" which is obscure.

turns out in
CPython 3.12, it loyally generates "\\" if "\\" is in a raw string.
so "sed" is confused when executing the generated build rule, like:

```
[3/36] ANTLR3 alternator/expressions.g
FAILED: build/debug/gen/alternator/expressionsLexer.cpp build/debug/gen/alternator/expressionsLexer.hpp build/debug/gen/alternator/expressionsParser.cpp build/debug/gen/alternator/expressionsParser.hpp
sed -e '/^#if 0/,/^#endif/d' alternator/expressions.g > build/debug/gen/alternator/expressions.g && antlr3 build/debug/gen/alternator/expressions.g && sed -i -e '/^.*On :.*$/d' build/debug/gen/alternator/expressionsLexer.hpp && sed -i -e '/^.*On :.*$/d' build/debug/gen/alternator/expressionsLexer.cpp && sed -i -e '/^.*On :.*$/d' build/debug/gen/alternator/expressionsParser.hpp && sed -i -e 's/^\\( *\)\\(ImplTraits::CommonTokenType\\* [a-zA-Z0-9_]* = NULL;\)$/\1const \2/' -e '/^.*On :.*$/d' -e '1i using ExceptionBaseType = int;' -e 's/^{/{ ExceptionBaseType\* ex = nullptr;/; s/ExceptionBaseType\* ex = new/ex = new/; s/exceptions::syntax_exception e/exceptions::syntax_exception\& e/' build/debug/gen/alternator/expressionsParser.cpp
sed: -e expression #1, char 80: Unmatched ) or \)
```

in this change, we replace "\\" with "\" in raw string where we
intend to put a single "\" in the created string. this is accepted
by both Python 3.11 shipped along with Fedora 38 and Python 3.12
shipped along with Fedora 39.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
  • Loading branch information
tchaikov committed Nov 25, 2023
1 parent a472700 commit e5758e6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1956,7 +1956,7 @@ def write_build_file(f,
&& sed -i -e '/^.*On :.*$$/d' $builddir/{mode}/gen/${{stem}}Lexer.hpp $
&& sed -i -e '/^.*On :.*$$/d' $builddir/{mode}/gen/${{stem}}Lexer.cpp $
&& sed -i -e '/^.*On :.*$$/d' $builddir/{mode}/gen/${{stem}}Parser.hpp $
&& sed -i -e 's/^\\( *\)\\(ImplTraits::CommonTokenType\\* [a-zA-Z0-9_]* = NULL;\\)$$/\\1const \\2/' $
&& sed -i -e 's/^\\( *\)\\(ImplTraits::CommonTokenType\\* [a-zA-Z0-9_]* = NULL;\)$$/\1const \2/' $
-e '/^.*On :.*$$/d' $
-e '1i using ExceptionBaseType = int;' $
-e 's/^{{/{{ ExceptionBaseType\* ex = nullptr;/; $
Expand Down

0 comments on commit e5758e6

Please sign in to comment.