pngcheck 0.1.0 → 0.2.2

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: 3eae7d8aff8cd89dd6841d3fa4c841c978bdff7692bd2e86dfa925fbc56cf654
4
+ data.tar.gz: 11369956fe046f3831b65e318cede1351f473efe5d0f3122452765cfbd45f758
5
5
  SHA512:
6
- metadata.gz: 5525ee60d5c00b76fd9991d06e64f9ded140d2a88f238a7130abcb2c0e7bc96b53d4d5fda926a044198d02d2fe0ae790b0cc63a47acecaf1a9925c915b66290d
7
- data.tar.gz: d210466936f5539db834065e3a5348b6e6ba2befeac712127d565bb7c05b23b06d3889a281399634c949f0193cf54182ee85324548ece65f8ce098b49690dc1b
6
+ metadata.gz: b6fb8b8ab2ad2ad87d3b0eeb14350e7ca82e00c22ccdfe904385b498f70c157c54ed7f71fbcc4eb74e8d1832aeb185b88248c12d67057f68054be60811f4535d
7
+ data.tar.gz: 1ab780793b6518ed1581b569c7f07b1fe0f5456b1be90cbfe0b63a77d3afd863ba69ed2baed5ce81c9038dd5f088628c7d4559948f2f882e5aa7deba1741a952
data/.cross_rubies ADDED
@@ -0,0 +1,7 @@
1
+ x64-mingw32
2
+ x86_64-linux
3
+ x86_64-linux-musl
4
+ aarch64-linux
5
+ x86_64-darwin
6
+ arm64-darwin
7
+ 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")
data/ext/extconf.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
4
-
5
4
  require "pngcheck/recipe"
6
5
 
7
6
  recipe = PngCheck::Recipe.new
@@ -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,85 @@ 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 /\A(arm64|aarch64).*linux/
117
+ "aarch64-linux"
118
+ when /\Ax86_64.*(darwin|macos|osx)/
119
+ "x86_64-darwin"
120
+ when /\A(arm64|aarch64).*(darwin|macos|osx)/
121
+ "arm64-darwin"
122
+ else
123
+ @host
124
+ end
125
+ end
126
+
127
+ def target_platform
128
+ @target_platform ||=
129
+ case ENV.fetch("target_platform", nil)
130
+ when /\A(arm64|aarch64).*(darwin|macos|osx)/
131
+ "arm64-darwin"
132
+ when /\Ax86_64.*(darwin|macos|osx)/
133
+ "x86_64-darwin"
134
+ when /\A(arm64|aarch64).*linux/
135
+ "aarch64-linux"
136
+ else
137
+ ENV.fetch("target_platform", host_platform)
138
+ end
139
+ end
140
+
141
+ def target_format
142
+ @target_format ||=
143
+ case target_platform
144
+ when "arm64-darwin"
145
+ "Mach-O 64-bit dynamically linked shared library arm64"
146
+ when "x86_64-darwin"
147
+ "Mach-O 64-bit dynamically linked shared library x86_64"
148
+ when "aarch64-linux"
149
+ "ELF 64-bit LSB shared object, ARM aarch64"
150
+ when /\Ax86_64.*linux.*/
151
+ "ELF 64-bit LSB shared object, x86-64"
152
+ when /\Ax64-mingw(32|-ucrt)/
153
+ "PE32+ executable (DLL) (console) x86-64, for MS Windows"
154
+ else
155
+ "skip"
156
+ end
157
+ end
158
+
159
+ def cc
160
+ @cc ||=
161
+ if target_platform.eql?(host_platform)
162
+ "gcc"
163
+ else
164
+ case target_platform
165
+ when "aarch64-linux"
166
+ "aarch64-linux-gnu-gcc"
167
+ when "arm64-darwin"
168
+ "gcc -target arm64-apple-macos11"
169
+ else
170
+ "gcc"
171
+ end
172
+ end
173
+ end
174
+
175
+ def cflags
176
+ @cflags ||=
177
+ if target_platform.eql?(host_platform) ||
178
+ !target_platform.eql?("aarch64-linux")
179
+ ""
180
+ else
181
+ "-I./usr/include -L./usr/lib/#{target_platform}-gnu"
182
+ end
183
+ end
184
+ # rubocop:enable Metrics/CyclomaticComplexity
185
+ # rubocop:enable Metrics/MethodLength
68
186
  end
69
187
  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.2"
5
5
  end
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.2
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-08 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
@@ -103,7 +120,6 @@ files:
103
120
  - lib/pngcheck.rb
104
121
  - lib/pngcheck/recipe.rb
105
122
  - lib/pngcheck/version.rb
106
- - pngcheck.gemspec
107
123
  homepage: https://github.com/metanorma/pngcheck-ruby
108
124
  licenses:
109
125
  - BSD-2-Clause
@@ -126,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
142
  - !ruby/object:Gem::Version
127
143
  version: '0'
128
144
  requirements: []
129
- rubygems_version: 3.3.7
145
+ rubygems_version: 3.1.6
130
146
  signing_key:
131
147
  specification_version: 4
132
148
  summary: Ruby interface to pngcheck.
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")
data/pngcheck.gemspec DELETED
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/pngcheck/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "pngcheck"
7
- spec.version = PngCheck::VERSION
8
- spec.authors = ["Ribose Inc."]
9
- spec.email = ["open.source@ribose.com"]
10
-
11
- spec.summary = "Ruby interface to pngcheck."
12
- spec.homepage = "https://github.com/metanorma/pngcheck-ruby"
13
- spec.license = "BSD-2-Clause"
14
- spec.required_ruby_version = ">= 2.7.0"
15
-
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = spec.homepage
18
- spec.metadata["changelog_uri"] = spec.homepage
19
-
20
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
- `git ls-files -z`.split("\x0").reject do |f|
22
- (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|github|travis|circleci)|appveyor)}) # rubocop:disable Layout/LineLength
23
- end
24
- end
25
- spec.bindir = "bin"
26
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
28
-
29
- spec.add_runtime_dependency "ffi", "~> 1.0"
30
- spec.add_runtime_dependency "mini_portile2", "~> 2.7"
31
-
32
- spec.add_development_dependency "libpng-ruby", "~> 0.6"
33
- spec.add_development_dependency "rspec", "~> 3.0"
34
- spec.add_development_dependency "rubocop", "~> 1.4"
35
-
36
- spec.extensions = ["ext/extconf.rb"]
37
- end