Message ID | 20190605121911.3324-1-bjorn@mork.no |
---|---|
State | Accepted |
Delegated to: | John Crispin |
Headers | show |
Series | [OpenWrt-Devel,v2] scripts/feeds: add src-include method | expand |
On 05/06/2019 14:19, Bjørn Mork wrote: > The src-include method allows recursive inclusion of feeds.conf snippets. > > This can for example be used for adding static local feeds to > feeds.conf.default without ever having to update the local feeds.conf: > > src-include defaults feeds.conf.default > src-link custom /usr/local/src/lede/custom > > Signed-off-by: Bjørn Mork <bjorn@mork.no> > --- > > It would of course be nice of me if I had tested my patches, even > if they are only meant for discussion. > > This version actually works. Changes in v2: > - use a variable for the file handle so we can open files recursively > - match on the real 'src-include' keyword > > > Bjørn Hi Bjørn that would again involve carrying extra files around, which is what I am trying to avoid John > > scripts/feeds | 37 ++++++++++++++++++++++++++----------- > 1 file changed, 26 insertions(+), 11 deletions(-) > > diff --git a/scripts/feeds b/scripts/feeds > index 304ef6cbafd1..a4dfd9e260a8 100755 > --- a/scripts/feeds > +++ b/scripts/feeds > @@ -41,34 +41,49 @@ my $feed_src = {}; > my $feed_target = {}; > my $feed_vpackage = {}; > > -sub parse_config() { > +sub parse_file($$); > + > +sub parse_file($$) { > + my ($fname, $name) = @_; > my $line = 0; > - my %name; > + my $fh; > > - open FEEDS, "feeds.conf" or > - open FEEDS, "feeds.conf.default" or > - die "Unable to open feeds configuration"; > - while (<FEEDS>) { > + open $fh, $fname or return undef; > + while (<$fh>) { > chomp; > s/#.+$//; > + $line++; > next unless /\S/; > my @line = split /\s+/, $_, 3; > my @src; > - $line++; > > my $valid = 1; > $line[0] =~ /^src-[\w-]+$/ or $valid = 0; > $line[1] =~ /^\w+$/ or $valid = 0; > @src = split /\s+/, ($line[2] or ''); > @src = ('') if @src == 0; > - $valid or die "Syntax error in feeds.conf, line: $line\n"; > + $valid or die "Syntax error in $fname, line: $line\n"; > > - $name{$line[1]} and die "Duplicate feed name '$line[1]', line: $line\n"; > - $name{$line[1]} = 1; > + $name->{$line[1]} and die "Duplicate feed name '$line[1]' in '$fname' line: $line\n"; > + $name->{$line[1]} = 1; > + > + if ($line[0] eq "src-include") { > + parse_file($line[2], $name) or > + die "Unable to open included file '$line[2]'"; > + next; > + } > > push @feeds, [$line[0], $line[1], \@src]; > } > - close FEEDS; > + close $fh; > + return 1; > +} > + > +sub parse_config() { > + my %name; > + parse_file("feeds.conf", \%name) or > + parse_file("feeds.conf.default", \%name) or > + die "Unable to open feeds configuration"; > } > > sub update_location($$)
John Crispin <john@phrozen.org> writes: > On 05/06/2019 14:19, Bjørn Mork wrote: >> The src-include method allows recursive inclusion of feeds.conf snippets. >> >> This can for example be used for adding static local feeds to >> feeds.conf.default without ever having to update the local feeds.conf: >> >> src-include defaults feeds.conf.default >> src-link custom /usr/local/src/lede/custom >> >> Signed-off-by: Bjørn Mork <bjorn@mork.no> >> --- >> >> It would of course be nice of me if I had tested my patches, even >> if they are only meant for discussion. >> >> This version actually works. Changes in v2: >> - use a variable for the file handle so we can open files recursively >> - match on the real 'src-include' keyword >> >> >> Bjørn > > > Hi Bjørn > > that would again involve carrying extra files around, which is what I > am trying to avoid Well, you can say that it replaces the command scripts/feeds setup -b src-link,custom,/usr/local/src/lede/custom with the alternative command echo -e "src-include defaults feeds.conf.default\nsrc-link custom /usr/local/src/lede/custom" > feeds.conf :-) I am obviously missing your point. I do see the problem having to *maintain* local files. But I don't see the problem with some static local file which is used unmodified for every build regardless of version. It seems much easier than maintaining additional local build rules to generate or update that local file. My main problem with a feeds.conf which doesn't auto-depend on feeds.conf.default, is that it will always be stale. Having some new command to update it does not help me more than having cat or sed does today. I've found myself more than once building a development branch with a feeds.conf generated from some released feeds.conf.default, and vice versa. I need a way to make sure I remember to refresh the defaults when switching branches. Or better: Not having to remember it. Bjørn
diff --git a/scripts/feeds b/scripts/feeds index 304ef6cbafd1..a4dfd9e260a8 100755 --- a/scripts/feeds +++ b/scripts/feeds @@ -41,34 +41,49 @@ my $feed_src = {}; my $feed_target = {}; my $feed_vpackage = {}; -sub parse_config() { +sub parse_file($$); + +sub parse_file($$) { + my ($fname, $name) = @_; my $line = 0; - my %name; + my $fh; - open FEEDS, "feeds.conf" or - open FEEDS, "feeds.conf.default" or - die "Unable to open feeds configuration"; - while (<FEEDS>) { + open $fh, $fname or return undef; + while (<$fh>) { chomp; s/#.+$//; + $line++; next unless /\S/; my @line = split /\s+/, $_, 3; my @src; - $line++; my $valid = 1; $line[0] =~ /^src-[\w-]+$/ or $valid = 0; $line[1] =~ /^\w+$/ or $valid = 0; @src = split /\s+/, ($line[2] or ''); @src = ('') if @src == 0; - $valid or die "Syntax error in feeds.conf, line: $line\n"; + $valid or die "Syntax error in $fname, line: $line\n"; - $name{$line[1]} and die "Duplicate feed name '$line[1]', line: $line\n"; - $name{$line[1]} = 1; + $name->{$line[1]} and die "Duplicate feed name '$line[1]' in '$fname' line: $line\n"; + $name->{$line[1]} = 1; + + if ($line[0] eq "src-include") { + parse_file($line[2], $name) or + die "Unable to open included file '$line[2]'"; + next; + } push @feeds, [$line[0], $line[1], \@src]; } - close FEEDS; + close $fh; + return 1; +} + +sub parse_config() { + my %name; + parse_file("feeds.conf", \%name) or + parse_file("feeds.conf.default", \%name) or + die "Unable to open feeds configuration"; } sub update_location($$)
The src-include method allows recursive inclusion of feeds.conf snippets. This can for example be used for adding static local feeds to feeds.conf.default without ever having to update the local feeds.conf: src-include defaults feeds.conf.default src-link custom /usr/local/src/lede/custom Signed-off-by: Bjørn Mork <bjorn@mork.no> --- It would of course be nice of me if I had tested my patches, even if they are only meant for discussion. This version actually works. Changes in v2: - use a variable for the file handle so we can open files recursively - match on the real 'src-include' keyword Bjørn scripts/feeds | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-)