Method: Licensed::Sources::Cabal#cabal_file_dependencies

Defined in:
lib/licensed/sources/cabal.rb

#cabal_file_dependenciesObject

Returns a set of the top-level dependencies found in cabal files



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/licensed/sources/cabal.rb', line 160

def cabal_file_dependencies
  @cabal_file_dependencies ||= cabal_files.each_with_object(Set.new) do |cabal_file, targets|
    content = File.read(cabal_file)
    next if content.nil? || content.empty?

    # add any dependencies for matched targets from the cabal file.
    # by default this will find executable and library dependencies
    content.scan(cabal_file_regex).each do |match|
      # match[1] is a string of "," separated dependencies.
      # dependency packages might have a version specifier, remove them
      # to get the full id specifier for each package
      dependencies = match[1].split(",").map(&:strip)
      targets.merge(dependencies)
    end
  end
end