This repository was archived by the owner on Jun 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
129 lines (99 loc) · 3.6 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# frozen_string_literal: true
require "digest/sha1"
require "mini_portile2"
require "rake/clean"
require "rake/packagetask"
require "yaml"
# extend MiniPortile for local compilation
require_relative "src/custom_portile"
HAVERSACK_VERSION = "0.6.1"
directory "downloads"
directory "lib"
directory "tmp"
CLEAN.concat(["lib", "tmp"])
CLOBBER.concat(["downloads", "pkg"])
# load libs.yml
libs = YAML.safe_load(File.read("libs.yml"))
# build list of platforms from `libs`
SUPPORTED_PLATFORMS = Set.new
libs.each do |lib|
lib["binaries"].each do |binary|
SUPPORTED_PLATFORMS << binary["platform"]
end
end
# define tasks for download of each platform
libs.each do |lib|
binaries = lib["binaries"]
SUPPORTED_PLATFORMS.each do |platform|
port = CustomPortile.new(lib["name"], lib["version"])
port.host = platform
downloads_dir = "downloads/#{platform}"
lib_dir = "lib/#{platform}"
pkg_dir = File.join(lib_dir, "pkgconfig")
directory downloads_dir
directory pkg_dir
if found = binaries.find { |b| b["platform"] == platform }
short_platform = platform.split("-").first
# save path before changing target
tmp_port_path = File.join("tmp", port.port_path)
port.target = downloads_dir
task "fetch:#{platform}:#{lib["name"]}" => ["tmp", downloads_dir, pkg_dir] do
# determine single or multiple files present
if url = found["url"]
port.files << {
url: found["url"],
sha256: found["sha256"],
}
end
urls = found["urls"]
if urls && !urls.empty?
urls.each do |entry|
port.files << {
url: entry["url"],
sha256: entry["sha256"],
}
end
end
checkpoint_download = "tmp/.#{port.host}-#{port.name}-#{port.version}.download"
unless File.exist?(checkpoint_download)
port.download unless port.downloaded?
mkdir_p tmp_port_path
port.files.each do |file|
file_path = File.expand_path(File.basename(file[:url]), port.archives_path)
sh "tar -tf #{file_path} 2>#{IO::NULL} | grep -E '#{lib["files"].join("|")}' | xargs -I '{}' tar -xf #{file_path} -C #{tmp_port_path} --no-anchored '{}' 2>#{IO::NULL}"
end
FileUtils.touch(checkpoint_download)
end
# collect SHA1 of all `.a` and `.pc` extracted files
files_digest = Digest::SHA1.new
port_files = Dir.glob("#{tmp_port_path}/**/*.{a,pc}")
port_files.each do |file|
files_digest.update File.binread(file)
end
checkpoint_extract = "tmp/.#{port.host}-#{port.name}-#{port.version}-#{files_digest.hexdigest}.extract"
unless File.exist?(checkpoint_extract)
port_files.each do |file|
path = File.extname(file) == ".pc" ? pkg_dir : lib_dir
target_file = File.join(path, File.basename(file))
if File.exist?(target_file) && !FileUtils.compare_file(file, target_file)
rm target_file, force: true
end
cp file, target_file
end
FileUtils.touch(checkpoint_extract)
end
end
end
desc "Fetch all for '#{platform}'"
task "fetch:#{platform}" => ["fetch:#{platform}:#{port.name}"]
desc "Fetch all"
task "fetch:all" => ["fetch:#{platform}"]
end
end
Rake::PackageTask.new("magic-haversack", HAVERSACK_VERSION) do |t|
t.need_tar_xz = true
globs = SUPPORTED_PLATFORMS.map { |platform| "lib/#{platform}/**/*.{a,pc}" }
t.package_files.include(globs)
t.package_files.include("bin/*-cc")
end
task "package" => ["fetch:all"]