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

Handle variable expansion and '#' inside shell, support inherit_defer directive #19

Conversation

idillon-sfl
Copy link
Contributor

@idillon-sfl idillon-sfl commented Feb 1, 2024

  1. This adds variable expansions to shell functions.

BitBake code:

foo(){
    echo ${BAR}
}

parsing:

(recipe [0, 0] - [2, 1]
  (function_definition [0, 0] - [2, 1]
    (identifier [0, 0] - [0, 3])`
    (shell_content [1, 4] - [1, 9])
    (variable_expansion [1, 9] - [1, 15]
      (identifier [1, 11] - [1, 14]))))

Real life example: https://git.yoctoproject.org/poky/tree/meta/recipes-core/busybox/busybox.inc?h=mickledore#n117

  1. This also fixes a bug where # was considered as a comment in a shell string. It simply ensures any # will be considered shell_content.
    Bitbake code:
foo () {
  '${}#'
}

parsing before:

(recipe [0, 0] - [2, 1]
  (ERROR [0, 0] - [2, 1]
    (function_definition [0, 0] - [1, 6]
      (identifier [0, 0] - [0, 3])
      (ERROR [0, 8] - [1, 5]
        (string_start [1, 2] - [1, 3])))
    (comment [1, 6] - [1, 8])))

parsing after:

(recipe [0, 0] - [2, 1]
  (function_definition [0, 0] - [2, 1]
    (identifier [0, 0] - [0, 3])
    (shell_content [1, 2] - [1, 7])
    (variable_expansion [1, 7] - [1, 10])
    (shell_content [1, 10] - [1, 12])

Real life example: https://git.yoctoproject.org/poky/tree/meta/recipes-core/base-files/base-files_3.0.14.bb#n126

  1. This also includes my colleague's PR in order to make the whole thing easier to merge

@amaanq
Copy link
Member

amaanq commented Feb 1, 2024

Hey, thanks for your PRs! I'll take a look at them and see if I can improve them, but also, I prefer one PR that might fix a few issues - for a few reasons

  • It allows us to generate the parser/grammar files in one go, instead of via multiple PRs that need to be rebased
  • It can be easier to review if the changes aren't too big

So I'll probably cherry pick this commit onto your other PR, since it's a bit bigger

@idillon-sfl
Copy link
Contributor Author

Hello!

If you don't mind, we'd really appreciate to have this merged. We'd like to avoid maintaining our own separate fork, and this functionality would help us with real life use cases.

Thank you a lot

@idillon-sfl idillon-sfl changed the title Handle variable expansion inside shell Handle variable expansion and '#' inside shell Feb 26, 2024
@idillon-sfl
Copy link
Contributor Author

I added a new fix. I described what it does in the first comment: #19 (comment)

@idillon-sfl idillon-sfl changed the title Handle variable expansion and '#' inside shell Handle variable expansion and '#' inside shell, support inherit_defer directive Mar 7, 2024
@idillon-sfl
Copy link
Contributor Author

Abandoned for #23.

We gave up trying to support shell variable expansions. This was too much trouble. We use tree-sitter-bash instead for shell regions.

@idillon-sfl idillon-sfl deleted the shell-variable-expansion branch July 18, 2024 17:13
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.

3 participants