On 12/18/24 8:11 PM, John Ralls wrote:
On Dec 18, 2024, at 15:56, AP <gnuc...@inml.grue.cc> wrote:
On Tue, Dec 17, 2024 at 08:01:01PM -0800, John Ralls wrote:
I’d made an error when I wrote bit in the bundler script that derives the
version to pass to the setup-generator: It gets the release instal directories,
sorts them, and grabs the last one. The problem with that is that it’s a
lexical sort so if say 5.8, 5.9. and 5.10 directories exist then the sort order
is
Gnucash-5.10
Gnucash-5.8
Gnucash-5.9
And the last one is 5.9.
https://github.com/Gnucash/gnucash-on-windows/commit/317b10b7d99a4ae8281e866efc4403b9b7624320
changes it to sort them by creation date. That’s still not perfect, of course,
because someone might come along and builds an earlier version by hand it will
have the last time stamp.
I asked the Lord God AI (as I'm not a powershell user) and it came up with this:
--- 8<---
# Define an array of strings with non-version related text before the version
numbers
$versionStrings = @(
'ProductA v1.2.3',
'ProductB v1.10.0',
'ProductC v1.3.5',
'ProductD v2.0.0'
)
# Extract the version part using a regular expression and sort by the extracted
version
$sortedVersions = $versionStrings | Sort-Object {
if ($_ -match 'v([\d\.]+)$') {
[version]$matches[1]
}
}
# Display the sorted versions
$sortedVersions
--- 8<---
Don't know how right it is but if it's not right in and of itself then, maybe,
it's right enough to get you most of the way there. :)
You don’t show the output, but the result of the regex match is still a string
so I think it will still sort lexically, i.e. 1.10.0, 1.2.3, 1.3.5, 2.0.0.
This S-O suggests using a function called System.Version:
https://stackoverflow.com/questions/711107/sorting-powershell-versions. Dunno
if it works on two-digit version numbers. My default approach in most languages
would be to do two captures, ‘(\d+).(\d+)$’ and cast each to int and do a
two-level sort.
https://stackoverflow.com/questions/71232189/how-to-sort-multilevel-list
suggests how to do the multi-level sort part.
Regards,
John Ralls
_______________________________________________
gnucash-user mailing list
gnucash-u...@gnucash.org
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-----
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.
John,
The PowerShell's System.Version object supports the form of:
Major . Minor . Build . Revision
The cast maps the missing elements to -1.
|
For example:
PS C:\Users\sherlock> [version]"1.0"
Major Minor Build Revision
----- ----- ----- --------
1 0 -1 -1
The sort implemented is an appropriate multi-level numeric order: Major,
then Minor, then Build, and finally Revision.
If you really want to select the gnucash folder with the greatest
version suffix in bundle-mingw64.ps1 (assuming there is such a folder),
the following should suffice:
$gnucash = get-childitem -path $target_dir\build | sort-object {
[Version] $(if ($_.Name -match "^gnucash-([0-9\.]+)$") { $matches[1] }
else { "0.0.0.0" }) } | select-object -last 1
You may want to add some logic in bundle-mingw64.ps1 to verify the
package version subsequently derived from the config.h contained within
the selected folder is a match.
Regards,
Sherlock
_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel