|
| 1 | +################################################################ |
| 2 | +# |
| 3 | +# Copyright (c) 2026 SUSE LLC |
| 4 | +# |
| 5 | +# This program is free software; you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License version 2 or 3 as |
| 7 | +# published by the Free Software Foundation. |
| 8 | +# |
| 9 | +# This program is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU General Public License |
| 15 | +# along with this program (see the file COPYING); if not, write to the |
| 16 | +# Free Software Foundation, Inc., |
| 17 | +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 18 | +# |
| 19 | +################################################################ |
| 20 | + |
| 21 | +package PBuild::Manifest; |
| 22 | + |
| 23 | +use PBuild::Util; |
| 24 | +use PBuild::Source; |
| 25 | + |
| 26 | +sub read_manifest { |
| 27 | + my ($dir) = @_; |
| 28 | + eval { require YAML::XS; $YAML::XS::LoadBlessed = 0; }; |
| 29 | + die("Need YAML::XS to parse the _manifest file\n") unless defined &YAML::XS::LoadFile; |
| 30 | + my $manifest = eval { YAML::XS::LoadFile("$dir/_manifest") }; |
| 31 | + die("Could not parse _manifest file: $@") if $@; |
| 32 | + die("Bad _manifest file\n") unless ref($manifest) eq 'HASH'; |
| 33 | + return $manifest; |
| 34 | +} |
| 35 | + |
| 36 | +sub find_packages { |
| 37 | + my ($root_dir, $pkg_dirs) = @_; |
| 38 | + $seend_sd ||= {}; |
| 39 | + my $manifest = read_manifest($root_dir); |
| 40 | + my @pkgs; |
| 41 | + my @skippkgs; |
| 42 | + if (ref($manifest->{'packages'}) eq 'ARRAY') { |
| 43 | + for my $pkg (@{$manifest->{'packages'}}) { |
| 44 | + next if !defined($pkg) || ref($pkg) || $pkg eq '' || $pkg eq '.' || $pkg eq '..' || $pkg =~ /^\//; |
| 45 | + my $pkgdir = "$root_dir/$pkg"; |
| 46 | + push @skippkgs, $1 if $pkg =~ /^([^\/]+)\//; |
| 47 | + $pkg =~ s/.*\///; |
| 48 | + next if $pkg eq '' || $pkg =~ /^[\._]/; |
| 49 | + next if $pkg_dirs->{$pkg} || !-d $pkgdir; |
| 50 | + push @pkgs, $pkg; |
| 51 | + $pkg_dirs->{$pkg} = $pkgdir; |
| 52 | + } |
| 53 | + } |
| 54 | + if (ref($manifest->{'subdirectories'}) eq 'ARRAY') { |
| 55 | + for my $sd (@{$manifest->{'subdirectories'}}) { |
| 56 | + next if !defined($sd) || ref($sd) || $sd eq '' || $sd eq '.' || $sd eq '..' || $sd =~ /^\//; |
| 57 | + next unless -d "$root_dir/$sd"; |
| 58 | + push @skippkgs, $1 if $sd =~ /^([^\/]+)/; |
| 59 | + push @pkgs, find_packages("$root_dir/$sd", $pkg_dirs); |
| 60 | + } |
| 61 | + } |
| 62 | + if (!exists($manifest->{'packages'})) { |
| 63 | + @skippkgs = grep {!$pkg_dirs->{$_}} PBuild::Util::unify(@skippkgs); |
| 64 | + $pkg_dirs->{$_} = 1 for @skippkgs; |
| 65 | + push @pkgs, PBuild::Source::find_packages($root_dir, $pkg_dirs); |
| 66 | + delete $pkg_dirs->{$_} for @skippkgs; |
| 67 | + } |
| 68 | + return @pkgs; |
| 69 | +} |
| 70 | + |
| 71 | +1; |
0 commit comments