go4rake 1.5.7 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/go4rake/new.rb +154 -153
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '029845c95d728b7ba040be28eeae6dc761e1aaca0410fc9ce64e42a18bdc8d38'
4
- data.tar.gz: 45f524f451459ef570ab83a479b2760b50e775e3e77e2123045be2928d3ba543
3
+ metadata.gz: 2d1a32828da5d99c21b33c9b3816a9eff3c34ddba43538c601300a61e28deb9c
4
+ data.tar.gz: d17cdd8691aa2977bfc9c72f2a837e6a026cde64f93f6a52c9923773b979b326
5
5
  SHA512:
6
- metadata.gz: 4fd85f9dcc4ad561c5c9747fa5e6d4f3baafdf95c2dace93ad81b3cfd68045bccbf2259090e0a341a5a89d2fdbf72a52ae5a61dbb488d444e967f1e0aa5c8a58
7
- data.tar.gz: 020da2972138e0312e4cfdeef7071eaf61fe3db2c1f51fee217c48cdfaef1e25ee261b817b828145022f6cc131d12535e052ef00e22c66a0330e7c79759228a0
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
- begin
22
- @yaml_file = yml
23
- @config = YAML.load_file(@yaml_file)
24
- @config['out'] ||= '~/Downloads' # Default to ~/Downloads, if 'out' is not specified.
25
-
26
- init_tasks
27
- rescue(Errno::ENOENT) => e
28
- warn "WARNING: Skipping `build` and `zip` tasks: #{e}"
29
- end
30
- # `build`, `zip` and `clean` depend on config, `test` doesn't.
31
- task_test
32
- end
33
-
34
- private
35
-
36
- def init_tasks
37
- task_build
38
- task_zip
39
- task_clean
40
- end
41
-
42
- # Initialize `build`, `zip` and `clean` tasks.
43
- def task_build
44
- desc "Build this project for the platforms in #{@yaml_file}"
45
- task :build do
46
- @config['platforms'].each { |os|
47
- if os['arch'].respond_to?('each')
48
- os['arch'].each { |arch|
49
- build(os['name'], arch)
50
- }
51
- else
52
- build(os['name'], os['arch'])
53
- end
54
- }
55
- end
56
- end
57
-
58
- def task_zip
59
- desc 'ZIP this project binaries'
60
- task zip: %i[build test] do
61
- @config['platforms'].each { |os|
62
- if os['arch'].respond_to?('each')
63
- os['arch'].each { |arch|
64
- zip(os['name'], arch, @config['out'], @config['files'],
65
- os['zip'] ? "#{os['zip']}_#{arch}" : "#{os['name']}_#{arch}")
66
- }
67
- else
68
- zip(os['name'], os['arch'], @config['out'], @config['files'],
69
- os['zip'] || "#{os['name']}_#{os['arch']}")
70
- end
71
- }
72
- end
73
- end
74
-
75
- def task_clean
76
- desc 'Delete ZIP files'
77
- task :clean do
78
- @config['platforms'].each { |os|
79
- if os['arch'].respond_to?('each')
80
- os['arch'].each { |arch|
81
- clean(@config['out'], os['zip'] ? "#{os['zip']}_#{arch}" : "#{os['name']}_#{arch}")
82
- }
83
- else
84
- clean(@config['out'], os['zip'] || "#{os['name']}_#{os['arch']}")
85
- end
86
- }
87
- end
88
- end
89
-
90
- # Initialize `test` task.
91
- def task_test
92
- desc 'Run `go test` for the native platform'
93
- task :test do
94
- setenv(nil, nil)
95
- system('go test') || die('Tests')
96
- end
97
- end
98
-
99
- # Set GOARCH and GOOS.
100
- def setenv(os, arch)
101
- ENV['GOARCH'] = arch ? arch.to_s : nil
102
- ENV['GOOS'] = os
103
- end
104
-
105
- # Exit with an error.
106
- def die(task)
107
- abort("#{task} failed. Exiting") # Rake returns 1 in something fails.
108
- end
109
-
110
- # Execute `go install` for the specified os/arch.
111
- def build(os, arch)
112
- setenv(os, arch)
113
- puts("Building #{os}_#{arch}")
114
- system('go install') || die('Build')
115
- end
116
-
117
- # Zip the compiled files.
118
- def zip(os, arch, dir, files, file)
119
- setenv(os, arch)
120
- bin = `go list -f '{{.Target}}'`.chomp.delete_prefix("'").delete_suffix("'")
121
- return unless bin
122
-
123
- zip_file = File.expand_path(dir) + '/' + file + '.zip'
124
- name = File.basename(bin)
125
- unless files
126
- files = []
127
- # `NOTICE` file is required by Apache license.
128
- files.push('NOTICE') if File.exist?('NOTICE')
129
- end
130
-
131
- File.delete(zip_file) if File.exist?(zip_file)
132
- Zip::File.open(zip_file, Zip::File::CREATE) do |zip|
133
- [*files].each { |i|
134
- t = File.basename(i)
135
- zip.add(t, i)
136
- }
137
-
138
- # The executable file.
139
- zip.add(name, bin)
140
- zip.file.chmod(0o755, name)
141
- end
142
- puts("Wrote #{zip_file}")
143
- end
144
-
145
- # Remove the ZIP file (specify path and basename).
146
- def clean(dir, file)
147
- zip_file = File.expand_path(dir) + '/' + file + '.zip'
148
- return unless File.exist?(zip_file)
149
-
150
- puts("Removing #{zip_file}")
151
- File.delete(zip_file)
152
- end
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.7
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: 2020-07-07 00:00:00.000000000 Z
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.1.2
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: []