File indexing completed on 2022-09-27 21:08:10

0001 #!/usr/bin/env ruby
0002 # frozen_string_literal: true
0003 #
0004 # Copyright (C) 2017 Harald Sitter <sitter@kde.org>
0005 #
0006 # This library is free software; you can redistribute it and/or
0007 # modify it under the terms of the GNU Lesser General Public
0008 # License as published by the Free Software Foundation; either
0009 # version 2.1 of the License, or (at your option) version 3, or any
0010 # later version accepted by the membership of KDE e.V. (or its
0011 # successor approved by the membership of KDE e.V.), which shall
0012 # act as a proxy defined in Section 6 of version 3 of the license.
0013 #
0014 # This library is distributed in the hope that it will be useful,
0015 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017 # Lesser General Public License for more details.
0018 #
0019 # You should have received a copy of the GNU Lesser General Public
0020 # License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0021 
0022 require 'json'
0023 
0024 # For each part build a list of all packages that snapcraft would have put into
0025 # the part, then expand the existing content lists with the recursive listing.
0026 # This allows stricter staging in apps as they will know ALL packages in the
0027 # content share (so long as they came from snapcraft anyway).
0028 class Content
0029   PARTS_FILE_MAP = {
0030     'kf5' => 'stage-content.json',
0031     'kf5-dev' => 'stage-dev.json'
0032   }.freeze
0033 
0034   def self.packages_for_part(part)
0035     Dir.glob("parts/#{part}/ubuntu/download/*.deb").collect do |debfile|
0036       warn debfile
0037       debfile = File.basename(debfile)
0038       match = debfile.match(/^(.+)_([^_]+)_([^_]+)\.deb$/) || raise
0039       match[1] # Package name
0040     end
0041   end
0042 
0043   def self.extend
0044     warn 'Extending content files'
0045     PARTS_FILE_MAP.each do |part, file|
0046       pkgs = packages_for_part(part)
0047       raise "couldn't find packages of #{part}" if pkgs.empty?
0048       pkgs += JSON.parse(File.read(file))
0049       File.write(file, JSON.generate(pkgs.uniq.compact))
0050     end
0051   end
0052 end
0053 
0054 Content.extend if __FILE__ == $0