forked from rapid7/mettle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
95 lines (82 loc) · 2.36 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
require 'fileutils'
require 'bundler/gem_tasks'
task default: 'mettle:build'
task check: 'mettle:check'
namespace :mettle do
desc 'Remove all build artifacts and tools'
task :ultraclean => :clobber do
FileUtils.rm_rf 'build/'
FileUtils.rm Dir.glob 'musl-cross*.xz'
end
desc 'Make mettle for all architectures'
task :build do
each_arch do |tuple|
puts "Building target #{tuple}"
unless system "make TARGET=#{tuple} -j4"
$stderr.puts "Failed to build #{tuple}"
exit false
end
end
end
desc 'Sanity check for mettle artifacts'
task :check do
success = true
each_arch do |tuple|
file = "build/#{tuple}/bin/mettle"
if File.exist? "#{file}.exe"
next
end
unless File.exist? file
insane tuple, 'mettle executable does not exist'
success = false
next
end
unless File.size(file) < 1024 * 2048
insane tuple, 'mettle executable looks too big'
success = false
end
unless File.exist? "#{file}.bin"
insane tuple, 'mettle.bin (memory image) does not exist'
success = false
end
objdump = "build/tools/musl-cross/bin/#{tuple}-objdump"
needed = `#{objdump} -p #{file} | grep NEEDED`.strip
addr = `#{objdump} -p #{file} | grep LOAD | head -1`.strip.
match(/.* vaddr (0x[0]*) .*/)[0]
if needed != ""
# We need external shared objects
insane tuple, 'does not look static'
success = false
end
if addr == nil
# The first load section has a virtual address other than zero
insane tuple, 'does not look PIE'
success = false
end
end
$stderr.puts 'All binaries look sane' if success
exit success
end
end
def each_arch(&block)
File.readlines('ARCHES').each do |tuple|
block.call tuple.strip
end
end
def insane(tuple, why)
$stderr.puts "Sanity check failed for #{tuple}: #{why}"
end
# Override tag_version in bundler-#.#.#/lib/bundler/gem_helper.rb to force signed tags
module Bundler
class GemHelper
def tag_version
sh "git tag -m \"Version #{version}\" -s #{version_tag}"
Bundler.ui.confirm "Tagged #{version_tag}."
yield if block_given?
rescue
Bundler.ui.error "Untagging #{version_tag} due to error."
sh_with_code "git tag -d #{version_tag}"
raise
end
end
end