-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathRakefile
More file actions
172 lines (142 loc) · 4.41 KB
/
Copy pathRakefile
File metadata and controls
172 lines (142 loc) · 4.41 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# frozen_string_literal: true
require 'rake/testtask'
require 'rbconfig'
require 'fileutils'
require 'zip'
require 'bundler/gem_tasks'
require_relative 'lib/libui/version'
require_relative 'lib/libui/platform'
# Configuration
COMMIT_HASH = ENV['LIBUI_NG_COMMIT_HASH'] || 'e9a11ba-experimental'
# Path constants
BUILD_DIR = 'builddir'
MESON_OUT_DIR = "#{BUILD_DIR}/meson-out"
DEBUG_DIR = 'libui/debug'
# Test configuration
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end
task default: :test
# Utility functions
def log_message(message)
puts "[Rake] #{message}"
end
def detect_platform_config_key
if ENV['GEM_PLATFORM']
platform_key = LibUI::Platform.normalize_platform_key(ENV['GEM_PLATFORM'])
return platform_key if LibUI::Platform.config_for(platform_key)
end
LibUI::Platform.detect_platform_key
end
def url_for_libui_ng_commit(file_name)
"https://github.com/kojix2/libui-ng/releases/download/commit-#{COMMIT_HASH}/#{file_name}"
end
def download_file(file_name, url)
log_message "Running: curl -L -o #{file_name} #{url}"
curl_status = system("curl -L -o #{file_name} #{url}")
return true if curl_status && File.exist?(file_name)
warn "Warning: Failed to download #{file_name} from #{url}"
false
end
def extract_zip_files(file_name, lib_paths)
return unless file_name.end_with?('.zip')
Zip::File.open(file_name) do |zip_file|
zip_file.each do |entry|
# Extract only exact matches for shared libraries
next unless lib_paths.include?(entry.name)
print "Extracting #{entry.name} from #{file_name}..."
# Preserve complete directory structure
target_path = entry.name
FileUtils.mkdir_p(File.dirname(target_path)) unless entry.directory?
unless entry.directory?
entry.extract(target_path) { true } # Overwrite if exists
end
puts 'done'
end
end
end
def download_and_place(zip_name, src, dest)
url = url_for_libui_ng_commit(zip_name)
success = download_file(zip_name, url)
unless success
warn "Error: Failed to download #{zip_name}"
exit 1
end
extract_zip_files(zip_name, [src])
FileUtils.mkdir_p File.dirname(dest)
FileUtils.cp src, dest
ensure
File.delete(zip_name) if File.exist?(zip_name)
end
# High-level processing functions
def process_config_entry(entry)
# Standard download and place for shared libraries only
download_and_place(entry[:release_zip], entry[:release_src], entry[:vendor])
end
def process_platform(platform_entries)
platform_entries.each do |entry|
process_config_entry(entry)
end
end
# Platform gem building
platforms = LibUI::Platform.config_keys
task :build_platform do
platforms.each do |platform|
sh 'gem', 'build', '--platform', platform
end
FileUtils.mkdir_p('pkg')
Dir['*.gem'].each do |file|
FileUtils.move(file, 'pkg')
end
end
task :release_platform do
Dir["pkg/libui-#{LibUI::VERSION}-*.gem"].each do |file|
sh 'gem', 'push', file
end
end
# Vendor tasks
namespace 'vendor' do
desc 'Download pre-built libraries for every supported platform'
task :all do
Rake::Task['vendor:clean'].invoke
platform_configs = LibUI::Platform.config_keys.map { |key| LibUI::Platform.config_for(key) }
log_message "Processing all platforms: #{LibUI::Platform.config_keys.join(', ')}"
process_platform(platform_configs)
ensure
Rake::Task['vendor:cleanup'].invoke
end
desc 'Download pre-built libraries for current platform'
task :auto do
platform_key = detect_platform_config_key
platform_config = LibUI::Platform.config_for(platform_key)
if platform_config
log_message "Processing platform: #{platform_key}"
process_platform([platform_config])
else
current_platform = Gem::Platform.local
log_message "No configuration found for current platform: #{current_platform}"
log_message "Available platforms: #{LibUI::Platform.config_keys.join(', ')}"
exit 1
end
ensure
# Clean up temporary directory after processing
Rake::Task['vendor:cleanup'].invoke
end
desc 'Clean vendor directory'
task :clean do
vendor_files = Dir['vendor/*'] - Dir['vendor/{LICENSE,README}.md']
vendor_files.each do |f|
FileUtils.rm_rf(f)
log_message "Removed #{f}"
end
end
# Clean up temporary directory
task :cleanup do
if Dir.exist?(BUILD_DIR)
FileUtils.rm_rf BUILD_DIR
log_message "Cleaned up #{BUILD_DIR}"
end
end
end