Debian Codegraph @

ext/mimemagic/Rakefile

raw
1 require "rubygems"
2 require "rake/clean"
3
4 def locate_mime_database
5 possible_paths = [
6 (File.expand_path(ENV["FREEDESKTOP_MIME_TYPES_PATH"]) if ENV["FREEDESKTOP_MIME_TYPES_PATH"]),
7 "/usr/local/share/mime/packages/freedesktop.org.xml",
8 "/opt/homebrew/share/mime/packages/freedesktop.org.xml",
9 "/opt/local/share/mime/packages/freedesktop.org.xml",
10 "/usr/share/mime/packages/freedesktop.org.xml"
11 ].compact
12 path = possible_paths.find { |candidate| File.exist?(candidate) }
13
14 return path unless path.nil?
15 raise(<<-ERROR.gsub(/^ {3}/, ""))
16 Could not find MIME type database in the following locations: #{possible_paths}
17
18 Ensure you have either installed the shared-mime-info package for your distribution, or
19 obtain a version of freedesktop.org.xml and set FREEDESKTOP_MIME_TYPES_PATH to the location
20 of that file.
21 ERROR
22 end
23
24 desc "Build a file pointing at the database"
25 task :default do
26 mime_database_path = locate_mime_database
27 target_dir = "#{ENV.fetch("RUBYARCHDIR")}/mimemagic"
28 mkdir_p target_dir
29
30 open("#{target_dir}/path.rb", "w") do |f|
31 f.print(<<~SOURCE
32 class MimeMagic
33 DATABASE_PATH="#{mime_database_path}"
34 end
35 SOURCE
36 )
37 end
38 end