We need a better name for this feature. But basically, this allows for creating kde-project repository-wide "branch groups". For instance, you could list the git branch to use for the "stable Qt/KDE 4" release/maintenance branch, the "new development Qt/KDE 4" development branch (typically master, but that has been changing), and the "upcoming next major release" branch (for us, this means 'frameworks' sometimes, means 'master' sometimes, other modules may have different ideas). By using the 'branch-group' option (which remains to be further documented) you can say that you want to defer to the metadata about the repository branches stored in kde-build-metadata/logical-module-structure. kdesrc-build should even track branches for you as they are updated by the Release Team, if you simply want to hang out on stable but compile your own stuff. Note that this support requires Perl's JSON module (which should come with Perl 5.14 if I understand it right, but you probably want to install JSON::XS from CPAN). JSON support is only required for this feature, it is not a new overall dependency. See also: http://community.kde.org/Infrastructure/Project_Metadatawilder
parent
377a5d4bf6
commit
1805a95195
7 changed files with 183 additions and 3 deletions
@ -0,0 +1,89 @@ |
|||||||
|
package ksb::Module::BranchGroupResolver; |
||||||
|
|
||||||
|
# This provides an object that can be used to lookup the appropriate git branch |
||||||
|
# to use for a given KDE project module and given desired logical branch group, using |
||||||
|
# supplied JSON data (from kde-build-metadata). |
||||||
|
# |
||||||
|
# See also http://community.kde.org/Infrastructure/Project_Metadata |
||||||
|
|
||||||
|
use strict; |
||||||
|
use warnings; |
||||||
|
use v5.10; |
||||||
|
|
||||||
|
our $VERSION = '0.10'; |
||||||
|
|
||||||
|
use List::Util qw(first); |
||||||
|
|
||||||
|
sub new |
||||||
|
{ |
||||||
|
my ($class, $jsonData) = @_; |
||||||
|
|
||||||
|
my $self = { }; |
||||||
|
my @keys = qw/layers groups/; |
||||||
|
|
||||||
|
# Copy just the objects we want over. |
||||||
|
@{$self}{@keys} = @{$jsonData}{@keys}; |
||||||
|
|
||||||
|
# Extract wildcarded groups separately as they are handled separately |
||||||
|
# later. Note that the specific catch-all group '*' is itself handled |
||||||
|
# as a special case in findModuleBranch. This is important so that |
||||||
|
# findModuleBranch can assume all these groups have at least '/*'. |
||||||
|
|
||||||
|
$self->{wildcardedGroups} = { |
||||||
|
map { ($_, $self->{groups}->{$_}) } |
||||||
|
grep { substr($_,-2) eq '/*' } |
||||||
|
keys %{$self->{groups}} |
||||||
|
}; |
||||||
|
|
||||||
|
bless $self, $class; |
||||||
|
return $self; |
||||||
|
} |
||||||
|
|
||||||
|
# Returns the branch for the given logical group and module specifier. This |
||||||
|
# function should not be called if the module specifier does not actually |
||||||
|
# exist. |
||||||
|
sub _findLogicalGroup |
||||||
|
{ |
||||||
|
my ($self, $module, $logicalGroup) = @_; |
||||||
|
|
||||||
|
# Using defined-or and still returning undef is on purpose, silences |
||||||
|
# warning about use of undefined value. |
||||||
|
return $self->{groups}->{$module}->{$logicalGroup} // undef; |
||||||
|
} |
||||||
|
|
||||||
|
sub findModuleBranch |
||||||
|
{ |
||||||
|
my ($self, $module, $logicalGroup) = @_; |
||||||
|
|
||||||
|
if (exists $self->{groups}->{$module}) { |
||||||
|
return $self->_findLogicalGroup($module, $logicalGroup); |
||||||
|
} |
||||||
|
|
||||||
|
my %catchAllGroupStats = map { |
||||||
|
# Map module search spec to prefix string that is required for a match |
||||||
|
$_ => substr($_, 0, rindex ($_, '/') + 1) |
||||||
|
} keys %{$self->{wildcardedGroups}}; |
||||||
|
|
||||||
|
# Sort longest required-prefix to the top... first match that is valid will |
||||||
|
# then also be the right match. |
||||||
|
my @orderedCandidates = sort { |
||||||
|
$catchAllGroupStats{$b} cmp $catchAllGroupStats{$a} |
||||||
|
} keys %catchAllGroupStats; |
||||||
|
|
||||||
|
my $match = first { |
||||||
|
substr($module, 0, length $catchAllGroupStats{$_}) eq |
||||||
|
$catchAllGroupStats{$_} |
||||||
|
} @orderedCandidates; |
||||||
|
|
||||||
|
if ($match) { |
||||||
|
return $self->_findLogicalGroup($match, $logicalGroup); |
||||||
|
} |
||||||
|
|
||||||
|
if (exists $self->{groups}->{'*'}) { |
||||||
|
return $self->_findLogicalGroup('*', $logicalGroup); |
||||||
|
} |
||||||
|
|
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
1; |
||||||
Loading…
Reference in new issue