go4rake 1.5.8 → 1.5.9

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