-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
103 lines (86 loc) · 2.29 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
require "fileutils"
PICO_SDK_TAG = "1.5.1"
def mruby_config
ENV['BOARD']&.downcase == 'pico_w' ? 'r2p2_w-cortex-m0plus' : 'r2p2-cortex-m0plus'
end
def select_flags
flags = []
flags << (ENV['MSC']&.downcase == 'sd' ? "PICORUBY_MSC_SD=yes" : "PICORUBY_MSC_FLASH=yes")
flags << (ENV['BOARD']&.downcase == 'pico_w' ? "PICO_W=yes" : "")
flags.join(" ")
end
def def_board
ENV['BOARD']&.downcase == 'pico_w' ? '-DPICO_BOARD=pico_w' : ''
end
task :default => :all
desc "build production"
task :all => [:libmruby, :cmake_production, :build]
desc "clean then build debug"
task :debug => [:clean, :libmruby, :cmake_debug, :build]
file "lib/picoruby" do
sh "git submodule update --init --recursive"
end
task :libmruby => "lib/picoruby" do
FileUtils.cd "lib/picoruby" do
sh "rake test"
sh "MRUBY_CONFIG=#{mruby_config} rake"
end
end
def cmake_cmd(env)
"#{select_flags} cmake #{def_board} -DCMAKE_BUILD_TYPE=#{env} -B build"
end
task :cmake_debug do
sh cmake_cmd("Debug")
end
task :cmake_production do
sh cmake_cmd("Release")
end
task :check_pico_sdk => :check_pico_sdk_path do
%w(PICO_SDK_PATH PICO_EXTRAS_PATH).each do |env|
FileUtils.cd ENV[env] do
unless `git status --branch`.split("\n")[0].end_with?(PICO_SDK_TAG)
raise <<~MSG
pico-sdk #{PICO_SDK_TAG} is not checked out!\n
Tips for dealing with:\n
cd $PICO_SDK_PATH && git pull && git checkout #{PICO_SDK_TAG} && git submodule update --recursive\n
MSG
end
end
end
end
task :check_pico_sdk_path do
%w(PICO_SDK_PATH PICO_EXTRAS_PATH).each do |env|
unless ENV[env]
raise <<~MSG
Environment variable `#{env}` does not exist!
MSG
end
end
end
desc "build without cmake preparation"
task :build => :check_pico_sdk do
sh "cmake --build build"
end
desc "deep clean built"
task :deep_clean do
FileUtils.cd "lib/picoruby" do
sh "MRUBY_CONFIG=#{mruby_config} rake deep_clean"
end
FileUtils.cd "build" do
FileUtils.rm_rf "*"
end
end
desc "clean built"
task :clean do
FileUtils.cd "lib/picoruby" do
sh "MRUBY_CONFIG=#{mruby_config} rake clean"
end
FileUtils.cd "build" do
FileUtils.rm_rf Dir.glob("R2P2*.*")
end
begin
sh "cmake --build build --target clean"
rescue => e
puts "Ignoring an error: #{e.message}"
end
end