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

bash: use libtree-sitter-bash.so from system if available #367

Closed
wants to merge 6 commits into from

Conversation

laumann
Copy link
Contributor

@laumann laumann commented Apr 24, 2022

Prefer to load a shared library already installed for tree-sitter-bash.
Tested on Gentoo by emerging dev-libs/tree-sitter-bash.

Signed-off-by: Thomas Bracht Laumann Jespersen t@laumann.xyz

@laumann
Copy link
Contributor Author

laumann commented Apr 24, 2022

A few things I thought about

  • should it be a user-configurable thing to choose which tree-sitter-bash version to use?
  • should it limit this to specific systems? (as @radhermit pointed out: the issues you may have debundling it are broken OS X support and broken pip builds) I would need to figure out how best to identify systems where the vendored approach is preferred.
  • it really should check that the version of tree-sitter-bash on the system is >=0.19.0 (the current version bundled). EDIT: The language version is 13, the release is v0.19.0. The language version is available in the TSLanguage struct, so all that's really needed is to fish it out (I think).

@codecov
Copy link

codecov bot commented Apr 24, 2022

Codecov Report

Merging #367 (78a604a) into master (76ea79d) will increase coverage by 0.00%.
The diff coverage is 80.00%.

@@           Coverage Diff           @@
##           master     #367   +/-   ##
=======================================
  Coverage   95.50%   95.50%           
=======================================
  Files          54       54           
  Lines        7366     7368    +2     
  Branches     1785     1785           
=======================================
+ Hits         7035     7037    +2     
  Misses        204      204           
  Partials      127      127           
Impacted Files Coverage Δ
src/pkgcheck/bash/__init__.py 86.11% <80.00%> (+0.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76ea79d...78a604a. Read the comment docs.

@laumann laumann force-pushed the treesitter-try-systemlib branch 3 times, most recently from 66aedcb to 349e03e Compare April 25, 2022 12:21
@laumann
Copy link
Contributor Author

laumann commented Apr 25, 2022

Hey, there's even a bug for it: https://bugs.gentoo.org/834135

@laumann
Copy link
Contributor Author

laumann commented Apr 26, 2022

@arthurzam @radhermit any feedback on this?

@laumann
Copy link
Contributor Author

laumann commented Apr 26, 2022

Document tree-sitter-bash as a dependency.

@mgorny
Copy link
Contributor

mgorny commented Apr 26, 2022

Could you update the CI test matrix to test both building against system and bundled tree-sitter-bash?

@laumann
Copy link
Contributor Author

laumann commented Apr 26, 2022

Could you update the CI test matrix to test both building against system and bundled tree-sitter-bash?

Sure.

@MatthewGentoo
Copy link

it really should check that the version of tree-sitter-bash on the system is >=0.19.0 (the current version bundled). EDIT: The language version is 13, the release is v0.19.0. The language version is available in the TSLanguage struct, so all that's really needed is to fish it out (I think).

The language version (13) determines which versions of tree-sitter the grammar is compatible with. I don't think we need to worry about it too much because newer tree-sitter versions are backwards compatible with old grammars.

I think the problem is if a new version renames or removes any node types because this would break pkgcheck's queries. Unsure on what upstream's policy for that is, but if you look at the commit history for the grammar it seems stable.

@laumann
Copy link
Contributor Author

laumann commented Apr 27, 2022

The language version (13) determines which versions of tree-sitter the grammar is compatible with. I don't think we need to worry about it too much because newer tree-sitter versions are backwards compatible with old grammars.

OK, I won't worry about it then, thanks :-)

@laumann
Copy link
Contributor Author

laumann commented Apr 27, 2022

Could you update the CI test matrix to test both building against system and bundled tree-sitter-bash?

@mgorny I started looking at this, but it turns out that it'll require fetching a snapshot of tree-sitter-bash, building and manually installing it to get it working as ubuntu doesn't package libtree-sitter-bash yet (only libtree-sitter-dev exists afaict).

I can do it (I think), but it's gonna take a bit more work than I anticipated.

@laumann laumann force-pushed the treesitter-try-systemlib branch 6 times, most recently from 5f9ecf0 to 8bcf5ee Compare April 27, 2022 10:32
.github/workflows/test.yml Outdated Show resolved Hide resolved
Comment on lines +82 to +89
objects=( parser.o scanner.o )
make CFLAGS="-I${PWD}" CXXFLAGS="-I${PWD}" "${objects[@]}"
g++ -Wl,-O1 -Wl,--as-needed -shared parser.o scanner.o -Wl,--soname=libtree-sitter-bash.so.13 -o libtree-sitter-bash.so.13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is heavily inspired by tree-sitter-grammar.eclass.

@laumann laumann force-pushed the treesitter-try-systemlib branch 3 times, most recently from f566ca0 to cf27177 Compare April 27, 2022 13:41
@laumann laumann force-pushed the treesitter-try-systemlib branch 3 times, most recently from c7b0757 to ac7ab90 Compare April 27, 2022 19:46
Prefer to load a shared library already installed for tree-sitter-bash.
Tested on Gentoo by emerging dev-libs/tree-sitter-bash.

Bug: https://bugs.gentoo.org/834135
Signed-off-by: Thomas Bracht Laumann Jespersen <t@laumann.xyz>
@laumann laumann force-pushed the treesitter-try-systemlib branch 3 times, most recently from 0faff44 to ee28d80 Compare April 27, 2022 20:48
If the environment variable USE_SYSTEM_TREE_SITTER_BASH is set then the
bundled version is not build or installed.
The upstream version (0.19.0) that this is vendored from deleted this
file.

Signed-off-by: Thomas Bracht Laumann Jespersen <t@laumann.xyz>
Signed-off-by: Thomas Bracht Laumann Jespersen <t@laumann.xyz>
@laumann
Copy link
Contributor Author

laumann commented Apr 28, 2022

I think this is as far as I'll take it for now. @mgorny has suggested that setup.py be replaced, maybe by flit, but I'd prefer to do that in another PR if that's OK.

Just to summarize:

  • bundled tree-sitter-bash is only built if bool(USE_SYSTEM_TREE_SITTER_BASH) env var is False (default is False)
  • when running from checkout, the dynamic building only happens if the system lib isn't detected
  • CI is expanded to compile and "install" (ie set LD_LIBRARY_PATH) tree-sitter-bash - notably doesn't require libtree-sitter-dev ubuntu package. Only tested on ubuntu
  • document tree-sitter-bash as a dependency in README

.github/workflows/test.yml Outdated Show resolved Hide resolved
.github/workflows/test.yml Outdated Show resolved Hide resolved
@laumann laumann force-pushed the treesitter-try-systemlib branch 7 times, most recently from 77b669b to fef7bc6 Compare April 28, 2022 20:57
Also fail the build if the bundled tree-sitter-bash isn't built when
it's supposed to.
Copy link
Contributor

@mgorny mgorny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But let's wait some in case @radhermit has any comments.

Copy link
Member

@arthurzam arthurzam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @laumann

@mgorny mgorny closed this in bcb3a74 May 2, 2022
@thesamesam
Copy link
Member

@laumann You can do that PR for 9999 now 😉

@laumann laumann deleted the treesitter-try-systemlib branch August 1, 2022 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants