[RFC] [WIP] use bash arrays for some template fields#42656
[RFC] [WIP] use bash arrays for some template fields#42656classabbyamp wants to merge 4 commits into
Conversation
|
I haven't checked if there's any convenient mechanism for concatenating arrays, which would be nice in python packages as an alternative to
EDIT: sorry I skimmed through the part where you already say it's optional by design. |
for the same array, just $ foo=(foo bar baz)
$ bar=("${foo[@]}" idk)
$ declare -p foo
declare -a foo=([0]="foo" [1]="bar" [2]="baz")
$ declare -p bar
declare -a bar=([0]="foo" [1]="bar" [2]="baz" [3]="idk") |
Hm, for me the added explicitness of |
ahesford
left a comment
There was a problem hiding this comment.
Of all the xbps-src improvement proposals, this is the one I most strongly support. Bash arrays will solve a lot of problems in a lot of templates and we should move any variable currently space-separated to an array for proper handling. This includes:
*depends*argsdistfileschecksumnostrip_filesignore_elf*make_dirs(either one value per entry to simplify iteration, or just split every component so that space handling in paths would work as expected... not sure yet)subpackagesnopie_filesshlib_{provides,requires}revertsalternativesfont_dirsdkms_modulesregister_shelltagsperl_configure_dirsarchsconf_filesmutable_filesskip_extractionmake_check_premake_*_targetbuild_helpermake_cmdconfigure_scriptconflictsreplaces
We can do this by attrition, but relatively quickly, with a linter that fails if any of the should-be-arrays is a string that will split into an array with more than one element. Thus, the only time we accept the current syntax in future template updates is as a shorthand for a one-element array.
|
this might be for another issue/PR, but we might also want to consider using associative arrays for build_options like this: if this was declared before buildopts are used (= usually before configure_args), we could parse the template only once instead of twice if we also used functions for accessing build options instead of variables like currently (because buildopts has to be combined with options from cli args and the config). The only disadvantage I can think of is that it would be ugly to have declare -A right at the top of the template. |
|
I think that should be out of scope for this PR, but it may be useful to do |
I like this, and I've done this in the array conversion function directly, instead of e.g. changing xlint. I feel that using xlint for that would just be a mess |
|
I'm not a big fan of these 0,1,2 parameter... could we use |
|
or 1 and n ;) |
|
i think |
|
We have nothing really to gain from making licenses an array, at the moment its free text that is not interpreted by anything, making it a shell array now might cause conflicts if we would want to actually use SPDX expressions where you can have nesting and AND/OR operators ( https://spdx.github.io/spdx-spec/v2-draft/SPDX-license-expressions/ |
i've made it a bit more readable, but I suspect the code will change more once more things are arrays |
7e0ab2b to
b5a2bff
Compare
|
I think the best way to go about this will be:
|
b5a2bff to
c9508dd
Compare
|
Pull Requests become stale 90 days after last activity and are closed 14 days after that. If this pull request is still relevant bump it or assign it. |
`ensure_array` will ensure the named variables are arrays if defined. This allows us to not need to convert all packages to arrays immediately, as they can be migrated the next time someone builds them. `ensure_array_subpkg` does the same thing as `ensure_array`, but is also passed the subpkg for better error message context. `array_contains` is a helper function to make checking if an array contains a value easier.
this will allow select variables to be defined as arrays or strings. if a string is specified, it will be converted to an array for internal usage. if it is an array, it passes through untouched. this should allow for a smooth transition to using more arrays inside xbps-src, and should solve issues with shell quoting in things like configure_args, make_check_args, etc.
to start, I've only done this with configure_args, and fixed some templates
would like to get some feedback before continuing, as this will be a fairly massive undertaking. what fields would be valuable as arrays? (I'm thinking mostly the
*_argsvariables) should the internal string -> array conversion happen or should we just go all-in?Testing the changes
[ci skip]