go4rake 1.5.7 → 1.5.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/go4rake/new.rb +154 -153
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d1a32828da5d99c21b33c9b3816a9eff3c34ddba43538c601300a61e28deb9c
|
4
|
+
data.tar.gz: d17cdd8691aa2977bfc9c72f2a837e6a026cde64f93f6a52c9923773b979b326
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45cb5d210da807689d94cf1423359b0ed011c98dfaac666f4ebdbab989f0bcc48548761f4d662e9274cdd170e29098bd9ffab9bd91760918fbc3e0125ed38be9
|
7
|
+
data.tar.gz: 53c4ed4a9fca37675a6efc1ebd7ce846a751985a2a7f5bdf7dc069c40d7f892a14f9643f45a432cc7343d01a367fcba51cdaf4fcc24af53c5406a351d2ed645a
|
data/lib/go4rake/new.rb
CHANGED
@@ -1,153 +1,154 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rake/tasklib'
|
4
|
-
require 'yaml'
|
5
|
-
require 'zip/filesystem'
|
6
|
-
|
7
|
-
# Rake tasks to cross-compile Go project and ZIP the binaries:
|
8
|
-
# `rake build`, `rake zip`, `rake test` and `rake clean`.
|
9
|
-
#
|
10
|
-
# Usage: `require 'go4rake'` in `Rakefile`. Settings are specified in a YAML file: `go4rake.yml`.
|
11
|
-
#
|
12
|
-
# Example config: https://github.com/chillum/go4rake/blob/master/examples/go4rake.yml
|
13
|
-
#
|
14
|
-
# Docs: https://github.com/chillum/go4rake/blob/master/README.md
|
15
|
-
#
|
16
|
-
# Offline copies of README and example config are also included in this gem.
|
17
|
-
#
|
18
|
-
class Go4Rake < ::Rake::TaskLib
|
19
|
-
# Load configuration file and initialize Rake tasks for cross-compiling Go programs.
|
20
|
-
def initialize(yml = 'go4rake.yml')
|
21
|
-
|
22
|
-
|
23
|
-
@
|
24
|
-
@config
|
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
|
-
ENV['
|
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
|
-
zip.
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake/tasklib'
|
4
|
+
require 'yaml'
|
5
|
+
require 'zip/filesystem'
|
6
|
+
|
7
|
+
# Rake tasks to cross-compile Go project and ZIP the binaries:
|
8
|
+
# `rake build`, `rake zip`, `rake test` and `rake clean`.
|
9
|
+
#
|
10
|
+
# Usage: `require 'go4rake'` in `Rakefile`. Settings are specified in a YAML file: `go4rake.yml`.
|
11
|
+
#
|
12
|
+
# Example config: https://github.com/chillum/go4rake/blob/master/examples/go4rake.yml
|
13
|
+
#
|
14
|
+
# Docs: https://github.com/chillum/go4rake/blob/master/README.md
|
15
|
+
#
|
16
|
+
# Offline copies of README and example config are also included in this gem.
|
17
|
+
#
|
18
|
+
class Go4Rake < ::Rake::TaskLib
|
19
|
+
# Load configuration file and initialize Rake tasks for cross-compiling Go programs.
|
20
|
+
def initialize(yml = 'go4rake.yml')
|
21
|
+
super()
|
22
|
+
begin
|
23
|
+
@yaml_file = yml
|
24
|
+
@config = YAML.load_file(@yaml_file)
|
25
|
+
@config['out'] ||= '~/Downloads' # Default to ~/Downloads, if 'out' is not specified.
|
26
|
+
|
27
|
+
init_tasks
|
28
|
+
rescue(Errno::ENOENT) => e
|
29
|
+
warn "WARNING: Skipping `build` and `zip` tasks: #{e}"
|
30
|
+
end
|
31
|
+
# `build`, `zip` and `clean` depend on config, `test` doesn't.
|
32
|
+
task_test
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def init_tasks
|
38
|
+
task_build
|
39
|
+
task_zip
|
40
|
+
task_clean
|
41
|
+
end
|
42
|
+
|
43
|
+
# Initialize `build`, `zip` and `clean` tasks.
|
44
|
+
def task_build
|
45
|
+
desc "Build this project for the platforms in #{@yaml_file}"
|
46
|
+
task :build do
|
47
|
+
@config['platforms'].each { |os|
|
48
|
+
if os['arch'].respond_to?('each')
|
49
|
+
os['arch'].each { |arch|
|
50
|
+
build(os['name'], arch)
|
51
|
+
}
|
52
|
+
else
|
53
|
+
build(os['name'], os['arch'])
|
54
|
+
end
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def task_zip
|
60
|
+
desc 'ZIP this project binaries'
|
61
|
+
task zip: %i[build test] do
|
62
|
+
@config['platforms'].each { |os|
|
63
|
+
if os['arch'].respond_to?('each')
|
64
|
+
os['arch'].each { |arch|
|
65
|
+
zip(os['name'], arch, @config['out'], @config['files'],
|
66
|
+
os['zip'] ? "#{os['zip']}_#{arch}" : "#{os['name']}_#{arch}")
|
67
|
+
}
|
68
|
+
else
|
69
|
+
zip(os['name'], os['arch'], @config['out'], @config['files'],
|
70
|
+
os['zip'] || "#{os['name']}_#{os['arch']}")
|
71
|
+
end
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def task_clean
|
77
|
+
desc 'Delete ZIP files'
|
78
|
+
task :clean do
|
79
|
+
@config['platforms'].each { |os|
|
80
|
+
if os['arch'].respond_to?('each')
|
81
|
+
os['arch'].each { |arch|
|
82
|
+
clean(@config['out'], os['zip'] ? "#{os['zip']}_#{arch}" : "#{os['name']}_#{arch}")
|
83
|
+
}
|
84
|
+
else
|
85
|
+
clean(@config['out'], os['zip'] || "#{os['name']}_#{os['arch']}")
|
86
|
+
end
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Initialize `test` task.
|
92
|
+
def task_test
|
93
|
+
desc 'Run `go test` for the native platform'
|
94
|
+
task :test do
|
95
|
+
setenv(nil, nil)
|
96
|
+
system('go test') || die('Tests')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Set GOARCH and GOOS.
|
101
|
+
def setenv(os, arch)
|
102
|
+
ENV['GOARCH'] = arch ? arch.to_s : nil
|
103
|
+
ENV['GOOS'] = os
|
104
|
+
end
|
105
|
+
|
106
|
+
# Exit with an error.
|
107
|
+
def die(task)
|
108
|
+
abort("#{task} failed. Exiting") # Rake returns 1 in something fails.
|
109
|
+
end
|
110
|
+
|
111
|
+
# Execute `go install` for the specified os/arch.
|
112
|
+
def build(os, arch)
|
113
|
+
setenv(os, arch)
|
114
|
+
puts("Building #{os}_#{arch}")
|
115
|
+
system('go install') || die('Build')
|
116
|
+
end
|
117
|
+
|
118
|
+
# Zip the compiled files.
|
119
|
+
def zip(os, arch, dir, files, file)
|
120
|
+
setenv(os, arch)
|
121
|
+
bin = `go list -f '{{.Target}}'`.chomp.delete_prefix("'").delete_suffix("'")
|
122
|
+
return unless bin
|
123
|
+
|
124
|
+
zip_file = "#{File.expand_path(dir)}/#{file}.zip"
|
125
|
+
name = File.basename(bin)
|
126
|
+
unless files
|
127
|
+
files = []
|
128
|
+
# `NOTICE` file is required by Apache license.
|
129
|
+
files.push('NOTICE') if File.exist?('NOTICE')
|
130
|
+
end
|
131
|
+
|
132
|
+
File.delete(zip_file) if File.exist?(zip_file)
|
133
|
+
Zip::File.open(zip_file, Zip::File::CREATE) do |zip|
|
134
|
+
[*files].each { |i|
|
135
|
+
t = File.basename(i)
|
136
|
+
zip.add(t, i)
|
137
|
+
}
|
138
|
+
|
139
|
+
# The executable file.
|
140
|
+
zip.add(name, bin)
|
141
|
+
zip.file.chmod(0o755, name)
|
142
|
+
end
|
143
|
+
puts("Wrote #{zip_file}")
|
144
|
+
end
|
145
|
+
|
146
|
+
# Remove the ZIP file (specify path and basename).
|
147
|
+
def clean(dir, file)
|
148
|
+
zip_file = "#{File.expand_path(dir)}/#{file}.zip"
|
149
|
+
return unless File.exist?(zip_file)
|
150
|
+
|
151
|
+
puts("Removing #{zip_file}")
|
152
|
+
File.delete(zip_file)
|
153
|
+
end
|
154
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: go4rake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasily Korytov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -60,7 +60,7 @@ homepage: https://github.com/chillum/go4rake
|
|
60
60
|
licenses:
|
61
61
|
- Apache-2.0
|
62
62
|
metadata: {}
|
63
|
-
post_install_message:
|
63
|
+
post_install_message:
|
64
64
|
rdoc_options: []
|
65
65
|
require_paths:
|
66
66
|
- lib
|
@@ -75,8 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
-
signing_key:
|
78
|
+
rubygems_version: 3.2.3
|
79
|
+
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: Rake helper for cross-compiling Go programs
|
82
82
|
test_files: []
|