pngcheck 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3108a01f5219fca06fb7a8c20da83f2c022e434a03992ad0fd9490acae9b9f7d
4
- data.tar.gz: d959ab0ef00e06b62d4a610ed6ea8cd2250e92fbdc2679bdc1325e9f08f08882
3
+ metadata.gz: b46f8298766a5691098beee1733d47a4c37b06ab7fcdf4511f078bebb1d9e15f
4
+ data.tar.gz: 5b26e812f7e8dc20732b412ff9098e59180471df599cc11b66f46dc34452083e
5
5
  SHA512:
6
- metadata.gz: 5525ee60d5c00b76fd9991d06e64f9ded140d2a88f238a7130abcb2c0e7bc96b53d4d5fda926a044198d02d2fe0ae790b0cc63a47acecaf1a9925c915b66290d
7
- data.tar.gz: d210466936f5539db834065e3a5348b6e6ba2befeac712127d565bb7c05b23b06d3889a281399634c949f0193cf54182ee85324548ece65f8ce098b49690dc1b
6
+ metadata.gz: 596fce166e537433851addc9995afc423203ea2941793fda34753957e42621d38be640046845bcfc515d096bf67359c984e495576cc784e1d5380562b2af1402
7
+ data.tar.gz: f812521885e69d17e85eef191491ba0b04d93ba19c5b63cf28b80e541d9b07aa05c2ee257416c22e495f7d9deb2410619456bf3190a117d567c2571f672a22c6
data/.cross_rubies ADDED
@@ -0,0 +1,6 @@
1
+ x64-mingw32
2
+ x86_64-linux
3
+ aarch64-linux
4
+ x86_64-darwin
5
+ arm64-darwin
6
+ x64-mingw-ucrt
data/.hound.yml ADDED
@@ -0,0 +1,3 @@
1
+ ruby:
2
+ enabled: true
3
+ config_file: .rubocop.yml
data/Gemfile CHANGED
@@ -4,5 +4,3 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in pngcheck.gemspec
6
6
  gemspec
7
-
8
- gem "rake", "~> 13.0"
data/Rakefile CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
8
  RuboCop::RakeTask.new
10
9
 
11
10
  task default: %i[spec rubocop]
@@ -15,3 +14,45 @@ task :compile do
15
14
  end
16
15
 
17
16
  task spec: :compile
17
+
18
+ desc "Build install-compilation gem"
19
+ task "gem:native:any" do
20
+ sh "rake platform:any gem"
21
+ end
22
+
23
+ require "rubygems/package_task"
24
+
25
+ desc "Define the gem task to build on any platform (compile on install)"
26
+ task "platform:any" do
27
+ spec = Gem::Specification::load("pngcheck.gemspec").dup
28
+ task = Gem::PackageTask.new(spec)
29
+ task.define
30
+ end
31
+
32
+ File.readlines(".cross_rubies", chomp: true).each do |platform|
33
+ desc "Build pre-compiled gem for the #{platform} platform"
34
+ task "gem:native:#{platform}" do
35
+ sh "rake compile platform:#{platform} gem target_platform=#{platform}"
36
+ end
37
+
38
+ desc "Define the gem task to build on the #{platform} platform (binary gem)"
39
+ task "platform:#{platform}" do
40
+ spec = Gem::Specification::load("pngcheck.gemspec").dup
41
+ spec.platform = Gem::Platform.new(platform)
42
+ spec.files += Dir.glob("lib/pngcheck/*.{dll,so,dylib}")
43
+ spec.extensions = []
44
+ spec.dependencies.reject! { |d| d.name == "mini_portile2" }
45
+
46
+ task = Gem::PackageTask.new(spec)
47
+ task.define
48
+ end
49
+ end
50
+
51
+ require "rake/clean"
52
+
53
+ CLOBBER.include("pkg")
54
+ CLEAN.include("ports",
55
+ "tmp",
56
+ "lib/pngcheck/*.dll",
57
+ "lib/pngcheck/*.dylib",
58
+ "lib/pngcheck/*.so")
@@ -1,29 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rbconfig"
3
4
  require "mini_portile2"
4
5
  require "pathname"
6
+ require "tmpdir"
7
+ require "shellwords"
8
+ require "open3"
9
+ require_relative "version"
5
10
 
6
11
  module PngCheck
7
12
  class Recipe < MiniPortile
8
13
  ROOT = Pathname.new(File.expand_path("../..", __dir__))
14
+ COMMON_FLAGS = "-shared -fPIC -Wall -O -DUSE_ZLIB"
9
15
 
10
- def initialize
11
- super("pngcheck", "3.0.3")
12
-
16
+ def files_to_load
13
17
  @files << {
14
18
  url: "http://www.libpng.org/pub/png/src/pngcheck-3.0.3.tar.gz",
15
19
  sha256: "c36a4491634af751f7798ea421321642f9590faa032eccb0dd5fb4533609dee6", # rubocop:disable Layout/LineLength
16
20
  }
21
+ if target_platform.eql?("aarch64-linux")
22
+ @files << {
23
+ url: "http://ports.ubuntu.com/pool/main/z/zlib/zlib1g-dev_1.2.11.dfsg-2ubuntu1.3_arm64.deb", # rubocop:disable Layout/LineLength
24
+ sha256: "0ebadc1ff2a70f0958d4e8e21ffa97d9fa4da23555eaae87782e963044a26fcf", # rubocop:disable Layout/LineLength
25
+ }
26
+ end
27
+ end
17
28
 
29
+ def initialize
30
+ super("pngcheck", "3.0.3")
31
+ files_to_load
18
32
  @target = ROOT.join(@target).to_s
19
33
  @printed = {}
20
34
  end
21
35
 
22
36
  def make_cmd
23
37
  if MiniPortile.windows?
24
- +"gcc -shared -fPIC -Wall -O -DUSE_ZLIB -o pngcheck.dll wrapper.c -lz"
38
+ "gcc #{COMMON_FLAGS} -o pngcheck.dll wrapper.c -lz"
25
39
  else
26
- +"gcc -shared -fPIC -Wall -O -DUSE_ZLIB -o pngcheck.so wrapper.c -lz"
40
+ "#{cc} #{cflags} #{COMMON_FLAGS} -o pngcheck.so wrapper.c -lz"
27
41
  end
28
42
  end
29
43
 
@@ -42,6 +56,29 @@ module PngCheck
42
56
 
43
57
  def configure
44
58
  FileUtils.cp(ROOT.join("ext", "wrapper.c"), work_path, verbose: false)
59
+ if target_platform.eql?("aarch64-linux")
60
+ extract_file("#{work_path}/../data.tar.xz", work_path.to_s)
61
+ end
62
+ end
63
+
64
+ def libs_to_verify
65
+ Dir.glob(ROOT.join("lib", "pngcheck",
66
+ "pngcheck.{so,dylib,dll}"))
67
+ end
68
+
69
+ def verify_libs
70
+ libs_to_verify.each do |l|
71
+ out, st = Open3.capture2("file #{l}")
72
+ out = out.strip
73
+
74
+ raise "Failed to query file #{l}: #{out}" unless st.exitstatus.zero?
75
+
76
+ if out.include?(target_format)
77
+ message("Verifying #{l} ... OK\n")
78
+ else
79
+ raise "Invalid file format '#{out}', '#{@target_format}' expected"
80
+ end
81
+ end
45
82
  end
46
83
 
47
84
  def install
@@ -49,6 +86,7 @@ module PngCheck
49
86
  .grep(%r{/(?:lib)?[a-zA-Z0-9\-]+\.(?:so|dylib|dll)$})
50
87
 
51
88
  FileUtils.cp_r(libs, ROOT.join("lib", "pngcheck"), verbose: false)
89
+ verify_libs
52
90
  end
53
91
 
54
92
  def execute(action, command, command_opts = {})
@@ -65,5 +103,87 @@ module PngCheck
65
103
  @printed[pattern] = true
66
104
  super
67
105
  end
106
+
107
+ # rubocop:disable Metrics/MethodLength
108
+ # rubocop:disable Metrics/CyclomaticComplexity
109
+ def host_platform
110
+ @host_platform ||=
111
+ case @host
112
+ when /\Ax86_64-w64-mingw32/
113
+ "x64-mingw32"
114
+ when /\Ax86_64-w64-mingw-ucrt/
115
+ "x64-mingw-ucrt"
116
+ when /\Ax86_64.*linux/
117
+ "x86_64-linux"
118
+ when /\A(arm64|aarch64).*linux/
119
+ "aarch64-linux"
120
+ when /\Ax86_64.*(darwin|macos|osx)/
121
+ "x86_64-darwin"
122
+ when /\A(arm64|aarch64).*(darwin|macos|osx)/
123
+ "arm64-darwin"
124
+ else
125
+ @host
126
+ end
127
+ end
128
+
129
+ def target_platform
130
+ @target_platform ||=
131
+ case ENV.fetch("target_platform", nil)
132
+ when /\A(arm64|aarch64).*(darwin|macos|osx)/
133
+ "arm64-darwin"
134
+ when /\Ax86_64.*(darwin|macos|osx)/
135
+ "x86_64-darwin"
136
+ when /\A(arm64|aarch64).*linux/
137
+ "aarch64-linux"
138
+ else
139
+ ENV.fetch("target_platform", host_platform)
140
+ end
141
+ end
142
+
143
+ def target_format
144
+ @target_format ||=
145
+ case target_platform
146
+ when "arm64-darwin"
147
+ "Mach-O 64-bit dynamically linked shared library arm64"
148
+ when "x86_64-darwin"
149
+ "Mach-O 64-bit dynamically linked shared library x86_64"
150
+ when "aarch64-linux"
151
+ "ELF 64-bit LSB shared object, ARM aarch64"
152
+ when "x86_64-linux"
153
+ "ELF 64-bit LSB shared object, x86-64"
154
+ when /\Ax64-mingw(32|-ucrt)/
155
+ "PE32+ executable (DLL) (console) x86-64, for MS Windows"
156
+ else
157
+ "skip"
158
+ end
159
+ end
160
+
161
+ def cc
162
+ @cc ||=
163
+ if target_platform.eql?(host_platform)
164
+ "gcc"
165
+ else
166
+ case target_platform
167
+ when "aarch64-linux"
168
+ "aarch64-linux-gnu-gcc"
169
+ when "arm64-darwin"
170
+ "gcc -target arm64-apple-macos11"
171
+ else
172
+ "gcc"
173
+ end
174
+ end
175
+ end
176
+
177
+ def cflags
178
+ @cflags ||=
179
+ if target_platform.eql?(host_platform) ||
180
+ !target_platform.eql?("aarch64-linux")
181
+ ""
182
+ else
183
+ "-I./usr/include -L./usr/lib/#{target_platform}-gnu"
184
+ end
185
+ end
186
+ # rubocop:enable Metrics/CyclomaticComplexity
187
+ # rubocop:enable Metrics/MethodLength
68
188
  end
69
189
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PngCheck
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/pngcheck.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "lib/pngcheck/version"
4
4
 
5
- Gem::Specification.new do |spec|
5
+ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
6
6
  spec.name = "pngcheck"
7
7
  spec.version = PngCheck::VERSION
8
8
  spec.authors = ["Ribose Inc."]
@@ -23,13 +23,14 @@ Gem::Specification.new do |spec|
23
23
  end
24
24
  end
25
25
  spec.bindir = "bin"
26
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.add_runtime_dependency "ffi", "~> 1.0"
30
30
  spec.add_runtime_dependency "mini_portile2", "~> 2.7"
31
31
 
32
32
  spec.add_development_dependency "libpng-ruby", "~> 0.6"
33
+ spec.add_development_dependency "rake", "~> 13.0"
33
34
  spec.add_development_dependency "rspec", "~> 3.0"
34
35
  spec.add_development_dependency "rubocop", "~> 1.4"
35
36
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pngcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-22 00:00:00.000000000 Z
11
+ date: 2022-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -83,11 +97,15 @@ dependencies:
83
97
  description:
84
98
  email:
85
99
  - open.source@ribose.com
86
- executables: []
100
+ executables:
101
+ - console
102
+ - setup
87
103
  extensions:
88
104
  - ext/extconf.rb
89
105
  extra_rdoc_files: []
90
106
  files:
107
+ - ".cross_rubies"
108
+ - ".hound.yml"
91
109
  - ".rspec"
92
110
  - ".rubocop.yml"
93
111
  - Gemfile
@@ -95,7 +113,6 @@ files:
95
113
  - README.adoc
96
114
  - Rakefile
97
115
  - bin/console
98
- - bin/rspec
99
116
  - bin/setup
100
117
  - ext/Makefile
101
118
  - ext/extconf.rb
data/bin/rspec DELETED
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rspec' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("bundle", __dir__)
16
-
17
- if File.file?(bundle_binstub)
18
- if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
19
- load(bundle_binstub)
20
- else
21
- msg <<END_HEREDOC
22
- Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
23
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.
24
- END_HEREDOC
25
- abort(msg)
26
- end
27
- end
28
-
29
- require "rubygems"
30
- require "bundler/setup"
31
-
32
- load Gem.bin_path("rspec-core", "rspec")