Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions content/docs/rpm/macro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ with any blank lines present. Blank lines must end with a `\`:
you'll need `\` at the end of each line.
</Callout>

#### Escaping Regex in RPM Macros

Escaping characters in regex inside RPM macros has some notable differences from regular regex usage, especially when it comes to escapes. These are imporant to be aware of when using exclusion macros such as `%__requires_exclude`.

For example, if you wanted to escape a literal dot (`.`), you would need `\\.` instead of `\.`.

And if you need a literal backslash (`\`), you would then need `\\\\`.

In [Lua macros](/rpm/macros#lua) in a macros file (*not* in a spec!), this can get more complicated as you must sometimes escape in Lua *and* RPM.

For example, if you need a `.`, in Lua macros you need to escape this as `\\\\.`.

### Comments

In [`%{lua:…}`](./macros#lua), comments must start with `-- ` (with the space).
Expand Down Expand Up @@ -342,18 +354,6 @@ $ rpm -D 'p(-) %**' -E '%p -o'
-o
```

## Regex in RPM

Regex in RPM has some notable differences especially when it comes to escapes.

For example, if you wanted to escape a literal dot (`.`), you would need `\\.` instead of `\.`.

And if you need a literal backslash (`\`), you would then need `\\\\`.

In [Lua macros](/rpm/macros#lua) this can get even more complicated as you must sometimes escape in Lua *and* RPM.

For example, if you need a `.`, in Lua macros you need to escape this as `\\\\.`.

---

[^1]: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/macros.md#defining-a-macro, permalink: https://github.com/rpm-software-management/rpm/blob/1ca57c6cfe264a211a6a93bf4fe68b463bd4861a/docs/manual/macros.md#defining-a-macro
Expand Down
2 changes: 1 addition & 1 deletion content/docs/rpm/macros.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This document only covers the first type.
</Callout>

<Callout>
For macros which use regex ([`%__requires_exclude`](#__requires_exclude), [`%__requires_exclude_from`](#__requires_exclude_from), [`%__provides_exclude`](#__provides_exclude), [`%__provides_exclude_from`](#__provides_exclude_from), [`%__brp_mangle_shebangs_exclude_from`](#__brp_mangle_shebangs_exclude_from)) you SHOULD also note the [quirks with regex](/rpm/macro#regex-in-rpm) in RPM.
For macros which use regex ([`%__requires_exclude`](#__requires_exclude), [`%__requires_exclude_from`](#__requires_exclude_from), [`%__provides_exclude`](#__provides_exclude), [`%__provides_exclude_from`](#__provides_exclude_from), [`%__brp_mangle_shebangs_exclude_from`](#__brp_mangle_shebangs_exclude_from)) you SHOULD also note the [quirks with regex](/rpm/macro#escaping-regex-in-rpm-macros) in RPM.
</Callout>

If you are new to RPM packaging, you should first check out the macros with the 🔰 icon.
Expand Down
2 changes: 1 addition & 1 deletion content/docs/terra/srpm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ The safest location is under `Name:{:rpmspec}` and above other preambles. When i
`%__provides_exclude` and `%__requires_exclude` can be recursively added to if needed by defining the macro again as a `%global` and appending the needed exclusions using [regex](https://wikipedia.org/wiki/Regular_expression).<br />
Example: `%global __provides_exclude %{__provides_exclude}|libcurl\\.so`<br />
MUST be done after setting `%electronmeta`.<br />
You SHOULD double check [the notes for regex in macros](/rpm/macro#regex-in-rpm) on our macro syntax page for more information as RPM has some notable quirks with regex.
You SHOULD double check [the notes for regex in macros](/rpm/macro#escaping-regex-in-rpm-macros) on our macro syntax page for more information as RPM has some notable quirks with regex.
</Callout>

Example usage:
Expand Down