Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: make shell commands more portable in firejail.vim #5577

Merged
merged 4 commits into from
Jan 12, 2023

Conversation

kmk3
Copy link
Collaborator

@kmk3 kmk3 commented Jan 9, 2023

Added on commit a1cc4a5 ("Add vim syntax and ftdetect files (#2679)",
2019-05-06).

See also commit d2e10f2 ("vim: update list of syscalls", 2021-05-29) /
PR #4318.

Cc: @laomaiweng @reinerh (from #2679 and #4318)

kmk3 added 4 commits January 9, 2023 02:44
POSIX tr understands '\n', so use that instead of the less portable
$'\n'.

Commands used to search and replace:

    $ f=contrib/vim/syntax/firejail.vim; \
      printf '%s\n' "$(sed -E \
        "s/tr +\\\$'\\\\n'/tr '\\\\n'/g" "$f")" >"$f"

Added on commit a1cc4a5 ("Add vim syntax and ftdetect files (netblue30#2679)",
2019-05-06).
It seems to be equivalent to just delimiting the beginning and the end
of the line with `^foo$`.

Also, put the regex mode (-E) first.

Commands used to search and replace:

    $ f=contrib/vim/syntax/firejail.vim; \
      printf '%s\n' "$(sed -E \
        "s|grep -vEx '([^']+)'|grep -Ev '^\\1\$'|" "$f")" >"$f"

Added on commit a1cc4a5 ("Add vim syntax and ftdetect files (netblue30#2679)",
2019-05-06).
Only a single script is passed by argument in each invocation.

Added on commit a1cc4a5 ("Add vim syntax and ftdetect files (netblue30#2679)",
2019-05-06) and on commit d2e10f2 ("vim: update list of syscalls",
2021-05-29) / PR netblue30#4318.
To avoid depending on an extra package without need.

Commands used to search and replace:

    $ f=contrib/vim/syntax/firejail.vim; \
      printf '%s\n' "$(sed -E \
        "s|rg -o '([^']+)' -r '\\\$1'|sed -En 's/.*\\1.*/\\\\1/p'|" "$f")" >"$f"

Note: `sed -E` is not in POSIX.1-2017 (Issue 7), but it has been
accepted into the upcoming POSIX standard version[1] and is supported by
at least GNU, busybox and OpenBSD grep.

Added on commit a1cc4a5 ("Add vim syntax and ftdetect files (netblue30#2679)",
2019-05-06).

[1] https://www.austingroupbugs.net/view.php?id=528
@netblue30 netblue30 merged commit c0eee56 into netblue30:master Jan 12, 2023
@netblue30
Copy link
Owner

merged, thanks!

@kmk3 kmk3 deleted the build-vim-sh-portability branch January 12, 2023 13:33
kmk3 added a commit that referenced this pull request Jan 12, 2023
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 28, 2023
Changes:

* Use the commands from contrib/vim/syntax/firejail.vim to create
  makefile targets to generate syntax lists in contrib/syntax/lists
* Add contrib/syntax/files/example.in as an example of how to generate
  syntax files
* Generate and add the syntax lists, to make it easier to spot if they
  are properly updated when a new command is added or if their recipes
  also need changes
* Add "syntax" and "contrib" makefile targets

Note: The generation commands are executed mostly silently to avoid
generating too much noise when also making other targets.

Note2: In some generation commands, a `$$` escape is used to pass `$` to
the shell, to avoid being interpreted by make as the start of a macro.

Note3: `@make_input@` is used in example.in to make it clear that the
file is generated (and that it is generated by make rather than
configure), similarly to how `@configure_input@` is used in configure
input files.  See also apparmor.vim:

    $ head -n 2 /usr/share/vim/vimfiles/syntax/apparmor.vim
    " generated from apparmor.vim.in by create-apparmor.vim.py
    " do not edit this file - edit apparmor.vim.in or create-apparmor.vim.py instead

Environment: apparmor 3.1.2-1 on Artix Linux.

Relates to netblue30#2679 netblue30#5502 netblue30#5577 netblue30#5612.
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 28, 2023
Changes:

* Generate firejail.vim from firejail.vim.in
* Generate firejail-profile.lang from firejail-profile.lang.in
* Update the manual syntax file steps on the new command checklist on
  CONTRIBUTING.md to use `make syntax` instead

Relates to netblue30#2679 netblue30#5502 netblue30#5577 netblue30#5612.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done (on RELNOTES)
Development

Successfully merging this pull request may close these issues.

3 participants