maxirmx_test_gem 0.2.1-x86_64-linux → 0.3.0-x86_64-linux
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.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +59 -0
- data/.github/workflows/release.yml +137 -0
- data/.gitignore +17 -0
- data/Gemfile +5 -1
- data/LICENSE.txt +21 -53
- data/README.md +9 -0
- data/Rakefile +14 -41
- data/bin/console +1 -1
- data/ext/maxirmx_test_gem/extconf.rb +5 -0
- data/ext/maxirmx_test_gem/maxirmx_test_gem.cpp +20 -0
- data/ext/maxirmx_test_gem/maxirmx_test_gem.h +7 -0
- data/lib/maxirmx_test_gem/maxirmx_test_gem.so +0 -0
- data/lib/maxirmx_test_gem/version.rb +5 -0
- data/lib/maxirmx_test_gem.rb +9 -0
- data/maxirmx_test_gem.gemspec +34 -0
- metadata +31 -77
- data/.cross_rubies +0 -6
- data/.hound.yml +0 -3
- data/.rspec +0 -1
- data/.rubocop.yml +0 -9
- data/README.adoc +0 -161
- data/ext/Makefile +0 -4
- data/ext/extconf.rb +0 -8
- data/ext/wrapper.c +0 -106
- data/lib/pngcheck/pngcheck.so +0 -0
- data/lib/pngcheck/recipe.rb +0 -189
- data/lib/pngcheck/version.rb +0 -5
- data/lib/pngcheck.rb +0 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8b11d4df2c11638b208478a847b9283fd8981bc0d16560328689a73f0d02870
|
4
|
+
data.tar.gz: 01d1b5ee7d9b45ed1cea6b50227628b306c5f404a171f3fedd9fbf2233c3b03b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce1e7fe4c997ae7934b46f69a8dcd21e745e0b03c48bede020e70285bb7d148a610d93d8f1e237edbb110146cfd8ba7f6aedff089f8a57a95976b6a390182beb
|
7
|
+
data.tar.gz: 37f816a43fa0f92110a443cff6b7da918d2c3dee45e3b8f588b2f2e350a650ffab1ae35127ade3d4e5541370fafa1ee3890f40ca32a285ee82de742193302a45
|
@@ -0,0 +1,59 @@
|
|
1
|
+
name: build
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
pull_request:
|
7
|
+
workflow_dispatch:
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
ubuntu:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- name: Checkout
|
15
|
+
uses: actions/checkout@v4
|
16
|
+
|
17
|
+
- name: Install Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
bundler-cache: true
|
21
|
+
ruby-version: 3.3
|
22
|
+
|
23
|
+
- name: Install bundle
|
24
|
+
run: bundle install
|
25
|
+
|
26
|
+
- name: Build gem
|
27
|
+
run: bundle exec rake build
|
28
|
+
|
29
|
+
- uses: actions/upload-artifact@v4
|
30
|
+
with:
|
31
|
+
name: pkg-ruby
|
32
|
+
path: pkg/*.gem
|
33
|
+
|
34
|
+
- name: Build gem with native extension
|
35
|
+
run: |
|
36
|
+
rm pkg/*.gem
|
37
|
+
bundle exec rake gem:native:$(ruby -e "puts RUBY_PLATFORM")
|
38
|
+
|
39
|
+
alpine:
|
40
|
+
runs-on: ubuntu-latest
|
41
|
+
container:
|
42
|
+
image: alpine:latest
|
43
|
+
|
44
|
+
steps:
|
45
|
+
- name: Install packages
|
46
|
+
run: |
|
47
|
+
apk --no-cache --upgrade add build-base cmake git bash ruby-dev
|
48
|
+
git config --global --add safe.directory /__w/test-gem/test-gem
|
49
|
+
|
50
|
+
- name: Checkout
|
51
|
+
uses: actions/checkout@v4
|
52
|
+
|
53
|
+
- name: Install bundle
|
54
|
+
run: |
|
55
|
+
gem install bundler
|
56
|
+
bundle install
|
57
|
+
|
58
|
+
- name: Build gem with native extension
|
59
|
+
run: bundle exec rake gem:native:$(ruby -e "puts RUBY_PLATFORM")
|
@@ -0,0 +1,137 @@
|
|
1
|
+
name: release
|
2
|
+
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
inputs:
|
6
|
+
next_version:
|
7
|
+
description: |
|
8
|
+
Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
|
9
|
+
required: true
|
10
|
+
default: 'patch'
|
11
|
+
# push:
|
12
|
+
# tags: [ v* ]
|
13
|
+
permissions:
|
14
|
+
contents: write
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
bump:
|
18
|
+
runs-on: ubuntu-22.04
|
19
|
+
steps:
|
20
|
+
- name: Checkout
|
21
|
+
uses: actions/checkout@v4
|
22
|
+
|
23
|
+
- uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: 3.3
|
26
|
+
|
27
|
+
- if: ${{ github.event_name == 'workflow_dispatch' }}
|
28
|
+
run: |
|
29
|
+
git config user.name maxirmx
|
30
|
+
git config user.email maxirmx@sw.consulting
|
31
|
+
gem install gem-release
|
32
|
+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git
|
33
|
+
gem bump --version ${{ github.event.inputs.next_version }} --tag --push
|
34
|
+
|
35
|
+
ubuntu:
|
36
|
+
runs-on: ubuntu-latest
|
37
|
+
needs: bump
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout
|
41
|
+
uses: actions/checkout@v4
|
42
|
+
|
43
|
+
- name: Install Ruby
|
44
|
+
uses: ruby/setup-ruby@v1
|
45
|
+
with:
|
46
|
+
bundler-cache: true
|
47
|
+
ruby-version: 3.3
|
48
|
+
|
49
|
+
- name: Install bundle
|
50
|
+
run: bundle install
|
51
|
+
|
52
|
+
- name: Build gem
|
53
|
+
run: bundle exec rake build
|
54
|
+
|
55
|
+
- name: Upload artifacts
|
56
|
+
uses: actions/upload-artifact@v4
|
57
|
+
with:
|
58
|
+
name: pkg-ruby
|
59
|
+
path: pkg/*.gem
|
60
|
+
retention-days: 1
|
61
|
+
|
62
|
+
- name: Build gem with native extension
|
63
|
+
run: |
|
64
|
+
rm pkg/*.gem
|
65
|
+
bundle exec rake gem:native:$(ruby -e "puts RUBY_PLATFORM")
|
66
|
+
|
67
|
+
- name: Upload artifacts
|
68
|
+
uses: actions/upload-artifact@v4
|
69
|
+
with:
|
70
|
+
name: pkg-x86_64-linux
|
71
|
+
path: pkg/*.gem
|
72
|
+
retention-days: 1
|
73
|
+
|
74
|
+
alpine:
|
75
|
+
runs-on: ubuntu-latest
|
76
|
+
needs: bump
|
77
|
+
container:
|
78
|
+
image: alpine:latest
|
79
|
+
|
80
|
+
steps:
|
81
|
+
- name: Install packages
|
82
|
+
run: |
|
83
|
+
apk --no-cache --upgrade add build-base cmake git bash ruby-dev
|
84
|
+
git config --global --add safe.directory /__w/test-gem/test-gem
|
85
|
+
|
86
|
+
- name: Checkout
|
87
|
+
uses: actions/checkout@v4
|
88
|
+
|
89
|
+
- name: Install bundle
|
90
|
+
run: |
|
91
|
+
gem install bundler
|
92
|
+
bundle install
|
93
|
+
|
94
|
+
- name: Build gem with native extension
|
95
|
+
run: bundle exec rake gem:native:$(ruby -e "puts RUBY_PLATFORM")
|
96
|
+
|
97
|
+
- name: Upload artifacts
|
98
|
+
uses: actions/upload-artifact@v4
|
99
|
+
with:
|
100
|
+
name: pkg-x86_64-linux-musl
|
101
|
+
path: pkg/*.gem
|
102
|
+
retention-days: 1
|
103
|
+
|
104
|
+
publish:
|
105
|
+
runs-on: ubuntu-latest
|
106
|
+
needs: [ubuntu, alpine]
|
107
|
+
steps:
|
108
|
+
- name: Install Ruby
|
109
|
+
uses: ruby/setup-ruby@v1
|
110
|
+
with:
|
111
|
+
bundler-cache: true
|
112
|
+
ruby-version: 3.3
|
113
|
+
|
114
|
+
- name: Download artifacts
|
115
|
+
uses: actions/download-artifact@v4
|
116
|
+
with:
|
117
|
+
pattern: pkg-*
|
118
|
+
path: pkg
|
119
|
+
|
120
|
+
- name: List downloaded artifacts
|
121
|
+
run: find pkg -name "*.gem" | sort
|
122
|
+
|
123
|
+
- name: Publish to rubygems.org
|
124
|
+
env:
|
125
|
+
RUBYGEMS_API_KEY: ${{ secrets.MAXIRMX_TEST_GEM_API_KEY }}
|
126
|
+
run: |
|
127
|
+
mkdir -p ~/.gem
|
128
|
+
cat > ~/.gem/credentials << EOF
|
129
|
+
---
|
130
|
+
:rubygems_api_key: ${RUBYGEMS_API_KEY}
|
131
|
+
EOF
|
132
|
+
chmod 0600 ~/.gem/credentials
|
133
|
+
gem signin
|
134
|
+
for gem in $(find pkg -name "*.gem"); do
|
135
|
+
echo "Publishing $gem"
|
136
|
+
gem push $gem -V
|
137
|
+
done
|
data/.gitignore
ADDED
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,53 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Copyright (c) 2022
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
-
|
27
|
-
|
28
|
-
This module includes original pngcheck software [http://www.libpng.org/pub/png/apps/pngcheck.html]
|
29
|
-
that is distributed under the follwoing license:
|
30
|
-
|
31
|
-
Copyright 1995-2020 by Alexander Lehmann <lehmann@usa.net>,
|
32
|
-
Andreas Dilger <adilger@enel.ucalgary.ca>,
|
33
|
-
Glenn Randers-Pehrson <randeg@alum.rpi.edu>,
|
34
|
-
Greg Roelofs <newt@pobox.com>,
|
35
|
-
John Bowler <jbowler@acm.org>,
|
36
|
-
Tom Lane <tgl@sss.pgh.pa.us>
|
37
|
-
|
38
|
-
Permission to use, copy, modify, and distribute this software and its
|
39
|
-
documentation for any purpose and without fee is hereby granted, provided
|
40
|
-
that the above copyright notice appear in all copies and that both that
|
41
|
-
copyright notice and this permission notice appear in supporting
|
42
|
-
documentation. This software is provided "as is" without express or
|
43
|
-
implied warranty.
|
44
|
-
|
45
|
-
|
46
|
-
[This license applies to pngcheck.c and its associated makefiles and
|
47
|
-
documentation in the main directory. The files in the "gpl" subdirectory--
|
48
|
-
specifically, pngsplit.c and png-fix-IDAT-windowsize.c--are licensed under the
|
49
|
-
GNU General Public License. The files in "amiga" subdirectory are Copyright
|
50
|
-
2003 Simon Goodwin and were contributed without an explicit license statement,
|
51
|
-
but insofar as the "gpl" subdirectory didn't exist at the time, it's safe to
|
52
|
-
assume their intended license was similar to pngcheck's, just with Simon's
|
53
|
-
copyright replacing the one above.]
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022-2025 Maxim [maxirmx] Samsonov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
[](https://badge.fury.io/rb/maxirmx_test_gem)
|
2
|
+
|
3
|
+
# maxirmx test gem
|
4
|
+
|
5
|
+
This is a test gem. Nothing interesting, folks.
|
6
|
+
|
7
|
+
## License
|
8
|
+
|
9
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,58 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
|
+
require "rake/extensiontask"
|
4
5
|
require "rspec/core/rake_task"
|
5
|
-
require "rubocop/rake_task"
|
6
6
|
|
7
7
|
RSpec::Core::RakeTask.new(:spec)
|
8
|
-
RuboCop::RakeTask.new
|
9
8
|
|
10
|
-
task
|
9
|
+
task build: :compile
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
Rake::ExtensionTask.new("maxirmx_test_gem") do |ext|
|
12
|
+
ext.lib_dir = "lib/maxirmx_test_gem"
|
14
13
|
end
|
15
14
|
|
16
|
-
task
|
15
|
+
task default: %i[compile spec]
|
17
16
|
|
18
|
-
desc "Build
|
19
|
-
task "gem:native
|
20
|
-
sh "rake platform
|
17
|
+
desc "Build pre-compiled gem for the #{RUBY_PLATFORM} platform"
|
18
|
+
task "gem:native:#{RUBY_PLATFORM}" do
|
19
|
+
sh "rake compile platform:#{RUBY_PLATFORM} gem target_platform=#{RUBY_PLATFORM}"
|
21
20
|
end
|
22
21
|
|
23
|
-
|
22
|
+
desc "Build pre-compiled gem for #{RUBY_PLATFORM} platform (internal task)"
|
23
|
+
task "platform:#{RUBY_PLATFORM}" do
|
24
|
+
spec = Gem::Specification::load("maxirmx_test_gem.gemspec").dup
|
25
|
+
spec.platform = Gem::Platform.new(RUBY_PLATFORM)
|
26
|
+
spec.files += Dir.glob("lib/maxirmx_test_gem/*.{dll,so,dylib}")
|
27
|
+
spec.extensions = []
|
24
28
|
|
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
29
|
task = Gem::PackageTask.new(spec)
|
29
30
|
task.define
|
30
31
|
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/bin/console
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
#include "maxirmx_test_gem.h"
|
2
|
+
|
3
|
+
using namespace Rice;
|
4
|
+
|
5
|
+
class Hello
|
6
|
+
{
|
7
|
+
public:
|
8
|
+
Hello() { };
|
9
|
+
std::string hello() { return "=== Hello ==="; };
|
10
|
+
};
|
11
|
+
|
12
|
+
extern "C"
|
13
|
+
void Init_maxirmx_test_gem(void)
|
14
|
+
{
|
15
|
+
Module rb_mTestGem = define_module("TestGem");
|
16
|
+
Data_Type<Hello> rb_cHello =
|
17
|
+
define_class_under<Hello>(rb_mTestGem, "Hello")
|
18
|
+
.define_constructor(Constructor<Hello>())
|
19
|
+
.define_method("hello", &Hello::hello);
|
20
|
+
}
|
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/maxirmx_test_gem/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "maxirmx_test_gem"
|
7
|
+
spec.version = TestGem::VERSION
|
8
|
+
spec.authors = ["Maxim [maxirmx] Samsonov"]
|
9
|
+
spec.email = ["maxirmx@sw.consulting"]
|
10
|
+
|
11
|
+
spec.summary = "Test gem"
|
12
|
+
spec.description = "Test gem"
|
13
|
+
spec.homepage = "https://github.com/sw-consulting/maxirmx_test_gem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
16
|
+
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.test_files = `git ls-files -- {spec}/*`.split("\n")
|
25
|
+
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
spec.extensions = ["ext/maxirmx_test_gem/extconf.rb"]
|
30
|
+
|
31
|
+
spec.add_runtime_dependency "rice", "~> 4.0"
|
32
|
+
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.11"
|
34
|
+
end
|
metadata
CHANGED
@@ -1,119 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maxirmx_test_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: x86_64-linux
|
6
6
|
authors:
|
7
7
|
- Maxim [maxirmx] Samsonov
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rice
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: libpng-ruby
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.6'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.6'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '13.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '13.0'
|
26
|
+
version: '4.0'
|
55
27
|
- !ruby/object:Gem::Dependency
|
56
28
|
name: rspec
|
57
29
|
requirement: !ruby/object:Gem::Requirement
|
58
30
|
requirements:
|
59
31
|
- - "~>"
|
60
32
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.4'
|
33
|
+
version: '3.11'
|
76
34
|
type: :development
|
77
35
|
prerelease: false
|
78
36
|
version_requirements: !ruby/object:Gem::Requirement
|
79
37
|
requirements:
|
80
38
|
- - "~>"
|
81
39
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
83
|
-
description:
|
40
|
+
version: '3.11'
|
41
|
+
description: Test gem
|
84
42
|
email:
|
85
|
-
-
|
86
|
-
executables:
|
87
|
-
- console
|
88
|
-
- setup
|
43
|
+
- maxirmx@sw.consulting
|
44
|
+
executables: []
|
89
45
|
extensions: []
|
90
46
|
extra_rdoc_files: []
|
91
47
|
files:
|
92
|
-
- ".
|
93
|
-
- ".
|
94
|
-
- ".
|
95
|
-
- ".rubocop.yml"
|
48
|
+
- ".github/workflows/build.yml"
|
49
|
+
- ".github/workflows/release.yml"
|
50
|
+
- ".gitignore"
|
96
51
|
- Gemfile
|
97
52
|
- LICENSE.txt
|
98
|
-
- README.
|
53
|
+
- README.md
|
99
54
|
- Rakefile
|
100
55
|
- bin/console
|
101
56
|
- bin/setup
|
102
|
-
- ext/
|
103
|
-
- ext/
|
104
|
-
- ext/
|
105
|
-
- lib/
|
106
|
-
- lib/
|
107
|
-
- lib/
|
108
|
-
-
|
109
|
-
homepage: https://github.com/
|
57
|
+
- ext/maxirmx_test_gem/extconf.rb
|
58
|
+
- ext/maxirmx_test_gem/maxirmx_test_gem.cpp
|
59
|
+
- ext/maxirmx_test_gem/maxirmx_test_gem.h
|
60
|
+
- lib/maxirmx_test_gem.rb
|
61
|
+
- lib/maxirmx_test_gem/maxirmx_test_gem.so
|
62
|
+
- lib/maxirmx_test_gem/version.rb
|
63
|
+
- maxirmx_test_gem.gemspec
|
64
|
+
homepage: https://github.com/sw-consulting/maxirmx_test_gem
|
110
65
|
licenses:
|
111
|
-
-
|
66
|
+
- MIT
|
112
67
|
metadata:
|
113
|
-
homepage_uri: https://github.com/
|
114
|
-
source_code_uri: https://github.com/
|
115
|
-
|
116
|
-
post_install_message:
|
68
|
+
homepage_uri: https://github.com/sw-consulting/maxirmx_test_gem
|
69
|
+
source_code_uri: https://github.com/sw-consulting/maxirmx_test_gem
|
70
|
+
post_install_message:
|
117
71
|
rdoc_options: []
|
118
72
|
require_paths:
|
119
73
|
- lib
|
@@ -128,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
82
|
- !ruby/object:Gem::Version
|
129
83
|
version: '0'
|
130
84
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
132
|
-
signing_key:
|
85
|
+
rubygems_version: 3.5.22
|
86
|
+
signing_key:
|
133
87
|
specification_version: 4
|
134
|
-
summary:
|
88
|
+
summary: Test gem
|
135
89
|
test_files: []
|
data/.cross_rubies
DELETED
data/.hound.yml
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--require spec_helper
|
data/.rubocop.yml
DELETED
data/README.adoc
DELETED
@@ -1,161 +0,0 @@
|
|
1
|
-
image:https://github.com/metanorma/pngcheck-ruby/actions/workflows/test-and-release.yml/badge.svg["test-and-release", link="https://github.com/metanorma/pngcheck-ruby/actions/workflows/test-and-release.yml"]
|
2
|
-
|
3
|
-
== PngCheck: PNG, JNG and MNG integrity checks
|
4
|
-
|
5
|
-
The `pngcheck` gem provides the `PngCheck` Ruby library, used to
|
6
|
-
|
7
|
-
* verify the integrity of PNG, JNG and MNG files, through
|
8
|
-
|
9
|
-
** checking the internal 32-bit CRCs ("checksums");
|
10
|
-
** decompressing the image data;
|
11
|
-
|
12
|
-
* dump *almost* all of the chunk-level information in the image in
|
13
|
-
human-readable form, including:
|
14
|
-
|
15
|
-
** print the basic statistics about an image (dimensions, bit depth, etc.);
|
16
|
-
** list the color and transparency info in its palette (assuming it has one); or
|
17
|
-
** to extract the embedded text annotations.
|
18
|
-
|
19
|
-
The `PngCheck` Ruby library is a wrapper around the original
|
20
|
-
http://www.libpng.org/pub/png/apps/pngcheck.html[`pngcheck`] tool
|
21
|
-
from the http://www.libpng.org/pub/png/libpng.html[`libpng`] project.
|
22
|
-
|
23
|
-
NOTE: `PngCheck` incorporates
|
24
|
-
http://www.libpng.org/pub/png/apps/pngcheck.html[`pngcheck`] version 3.0.3, as
|
25
|
-
provided on the official website:
|
26
|
-
http://www.libpng.org/pub/png/apps/pngcheck.html
|
27
|
-
|
28
|
-
NOTE: The `PngCheck` Ruby library does not distribute nor modify the `pngcheck`
|
29
|
-
GPL executables `pngsplit` and `png-fix-IDAT-windowsize`, and hence is not bound
|
30
|
-
under the GPL license.
|
31
|
-
|
32
|
-
=== Installation
|
33
|
-
|
34
|
-
Add this line to your application's Gemfile:
|
35
|
-
|
36
|
-
[source,ruby]
|
37
|
-
----
|
38
|
-
gem 'pngcheck'
|
39
|
-
----
|
40
|
-
|
41
|
-
And then execute:
|
42
|
-
|
43
|
-
[source,sh]
|
44
|
-
----
|
45
|
-
$ bundle install
|
46
|
-
----
|
47
|
-
|
48
|
-
Or install it yourself as:
|
49
|
-
[source,sh]
|
50
|
-
----
|
51
|
-
$ gem install pngcheck
|
52
|
-
----
|
53
|
-
|
54
|
-
=== Usage
|
55
|
-
|
56
|
-
==== PngCeck status codes
|
57
|
-
|
58
|
-
[source,ruby]
|
59
|
-
----
|
60
|
-
PngCheck::STATUS_OK = 0
|
61
|
-
PngCheck::STATUS_WARNING = 1 # an error in some circumstances but not in all
|
62
|
-
PngCheck::STATUS_MINOR_ERROR = 3 # minor spec errors (e.g., out-of-range values)
|
63
|
-
PngCheck::STATUS_MAJOR_ERROR = 4 # file corruption, invalid chunk length/layout, etc.
|
64
|
-
PngCheck::STATUS_CRITICAL_ERROR = 5 # unexpected EOF or other file(system) error
|
65
|
-
----
|
66
|
-
|
67
|
-
==== File processing
|
68
|
-
|
69
|
-
[source,ruby]
|
70
|
-
----
|
71
|
-
status, info = PngCheck.analyze_file("spec/examples/correct.png")
|
72
|
-
----
|
73
|
-
|
74
|
-
Where:
|
75
|
-
|
76
|
-
* `status` is file status code
|
77
|
-
* `info` is either file content information for correct files, or error message for corrupt files
|
78
|
-
|
79
|
-
[source,ruby]
|
80
|
-
----
|
81
|
-
valid = PngCheck.check_file("spec/examples/correct.png")
|
82
|
-
----
|
83
|
-
|
84
|
-
Where:
|
85
|
-
|
86
|
-
* `valid` is `true` if the file is correct
|
87
|
-
* otherwise an exception of type `PngCheck::CorruptPngError` is raised
|
88
|
-
|
89
|
-
|
90
|
-
==== Memory buffer processing
|
91
|
-
|
92
|
-
[source,ruby]
|
93
|
-
----
|
94
|
-
data = File.binread("spec/examples/correct.png")
|
95
|
-
status, info = PngCheck.analyze_buffer(data)
|
96
|
-
----
|
97
|
-
|
98
|
-
Where:
|
99
|
-
|
100
|
-
* `status` is the PngCheck status code
|
101
|
-
* `info` is either file content information for correct files, or the error
|
102
|
-
message for corrupt files
|
103
|
-
|
104
|
-
|
105
|
-
[source,ruby]
|
106
|
-
----
|
107
|
-
data = File.binread("spec/examples/correct.png")
|
108
|
-
valid = PngCheck.check_buffer(data)
|
109
|
-
----
|
110
|
-
|
111
|
-
Where:
|
112
|
-
|
113
|
-
* `valid` is `true` if the file is correct
|
114
|
-
* otherwise an exception of type `PngCheck::CorruptPngError` is raised
|
115
|
-
|
116
|
-
|
117
|
-
==== Pre-validation with libpng-ruby
|
118
|
-
|
119
|
-
`libpng-ruby` is the Ruby wrapper library around `libpng`, commonly used to
|
120
|
-
process PNG files in Ruby.
|
121
|
-
|
122
|
-
To prevent crashing libpng-ruby with corrupt PNG files, you may wish to
|
123
|
-
pre-verify integrity of the PNG file before loading it with `libpng-ruby`.
|
124
|
-
Any errors in the PNG will cause a `PngCheck::CorruptPngError` to be raised,
|
125
|
-
hence skipping the `libpng` code.
|
126
|
-
|
127
|
-
The mechanism to do so is demonstrated below:
|
128
|
-
|
129
|
-
[source,ruby]
|
130
|
-
----
|
131
|
-
require 'png'
|
132
|
-
encoded = File.binread("spec/examples/correct.png")
|
133
|
-
|
134
|
-
begin
|
135
|
-
PngCheck.check_buffer(encoded)
|
136
|
-
dec = PNG::Decoder.new
|
137
|
-
raw = dec << encoded
|
138
|
-
rescue PngCheck::CorruptPngError => e
|
139
|
-
puts "Exception #{e.message}"
|
140
|
-
end
|
141
|
-
----
|
142
|
-
|
143
|
-
|
144
|
-
=== Contributing
|
145
|
-
|
146
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/metanorma/pngcheck-ruby.
|
147
|
-
|
148
|
-
=== License
|
149
|
-
|
150
|
-
Open-sourced under the link:LICENSE.txt[Ribose BSD-2 clause license].
|
151
|
-
Copyright Ribose for all code excluding the `pngcheck` library.
|
152
|
-
|
153
|
-
The `pngcheck` library is provided under its original license as unmodified
|
154
|
-
code, its license is located
|
155
|
-
http://www.libpng.org/pub/png/src/pngcheck-3.0.3.LICENSE[here].
|
156
|
-
|
157
|
-
NOTE: The core code of the `pngcheck` library is licensed under the
|
158
|
-
http://www.libpng.org/pub/png/src/libpng-LICENSE.txt[libpng 3-clause BSD license],
|
159
|
-
while two additional executables `pngsplit` and `png-fix-IDAT-windowsize` are
|
160
|
-
offered under GPL. Since the `PngCheck` Ruby library does not offer the GPL
|
161
|
-
executables, the gem itself is offered under a BSD license instead of GPL.
|
data/ext/Makefile
DELETED
data/ext/extconf.rb
DELETED
data/ext/wrapper.c
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
#ifdef _WIN32
|
2
|
-
# include <windows.h>
|
3
|
-
# include <share.h>
|
4
|
-
# include <io.h>
|
5
|
-
# include <stdio.h>
|
6
|
-
#endif
|
7
|
-
|
8
|
-
#include <sys/stat.h>
|
9
|
-
#include <fcntl.h>
|
10
|
-
#include <errno.h>
|
11
|
-
|
12
|
-
#ifdef _WIN32
|
13
|
-
/* https://github.com/Arryboom/fmemopen_windows */
|
14
|
-
|
15
|
-
FILE *fmemopen(void *buf, size_t len, char *type) {
|
16
|
-
int fd;
|
17
|
-
FILE *fp;
|
18
|
-
char tp[MAX_PATH - 13];
|
19
|
-
char fn[MAX_PATH + 1];
|
20
|
-
int * pfd = &fd;
|
21
|
-
int retner = -1;
|
22
|
-
char tfname[] = "MemTF_";
|
23
|
-
if (!GetTempPathA(sizeof(tp), tp)) return NULL;
|
24
|
-
if (!GetTempFileNameA(tp, tfname, 0, fn)) return NULL;
|
25
|
-
retner = _sopen_s(pfd, fn, _O_CREAT | _O_SHORT_LIVED | _O_TEMPORARY | _O_RDWR | _O_BINARY | _O_NOINHERIT, _SH_DENYRW, _S_IREAD | _S_IWRITE);
|
26
|
-
if (retner != 0) return NULL;
|
27
|
-
if (fd == -1) return NULL;
|
28
|
-
fp = _fdopen(fd, "wb+");
|
29
|
-
if (!fp) {
|
30
|
-
_close(fd);
|
31
|
-
return NULL;
|
32
|
-
}
|
33
|
-
fwrite(buf, len, 1, fp);
|
34
|
-
rewind(fp);
|
35
|
-
return fp;
|
36
|
-
}
|
37
|
-
#endif
|
38
|
-
|
39
|
-
#include "pngcheck.c"
|
40
|
-
|
41
|
-
#define EXTRA_MESSAGE_SIZE 1024
|
42
|
-
|
43
|
-
void failed_to_open(char *extra_msg, char *fname) {
|
44
|
-
snprintf(extra_msg, EXTRA_MESSAGE_SIZE, "Failed to open %s: %s\n", fname, strerror(errno));
|
45
|
-
extra_msg[EXTRA_MESSAGE_SIZE-1] = 0;
|
46
|
-
}
|
47
|
-
|
48
|
-
void failed_to_dup(char *extra_msg, char *fmt) {
|
49
|
-
snprintf(extra_msg, EXTRA_MESSAGE_SIZE, fmt, strerror(errno));
|
50
|
-
extra_msg[EXTRA_MESSAGE_SIZE-1] = 0;
|
51
|
-
}
|
52
|
-
|
53
|
-
int pngcheck_inner(FILE* fp, char *fname, char *cname, char *extra_msg) {
|
54
|
-
int rc = kCriticalError;
|
55
|
-
int fd = open(cname, O_WRONLY);
|
56
|
-
if (fd == -1) {
|
57
|
-
failed_to_open(extra_msg, cname);
|
58
|
-
}
|
59
|
-
else {
|
60
|
-
int stdout_copy = dup(STDOUT_FILENO);
|
61
|
-
if (stdout_copy == -1) {
|
62
|
-
failed_to_dup(extra_msg, "Failed to save stdout: %s\n");
|
63
|
-
}
|
64
|
-
else {
|
65
|
-
if (dup2(fd, STDOUT_FILENO) == -1) {
|
66
|
-
failed_to_dup(extra_msg, "Failed to reassign stdout: %s\n");
|
67
|
-
}
|
68
|
-
else {
|
69
|
-
rc = pngcheck(fp, fname, 0, NULL);
|
70
|
-
fflush(stdout);
|
71
|
-
}
|
72
|
-
dup2(stdout_copy, STDOUT_FILENO);
|
73
|
-
}
|
74
|
-
close(fd);
|
75
|
-
}
|
76
|
-
return rc;
|
77
|
-
}
|
78
|
-
|
79
|
-
int pngcheck_file(char *fname, char *cname, char *extra_msg) {
|
80
|
-
int rc = kCriticalError;
|
81
|
-
extra_msg[0] = 0;
|
82
|
-
FILE* fp = fopen(fname, "rb");
|
83
|
-
if (fp == NULL) {
|
84
|
-
failed_to_open(extra_msg, fname);
|
85
|
-
}
|
86
|
-
else {
|
87
|
-
rc = pngcheck_inner(fp, fname, cname, extra_msg);
|
88
|
-
fclose(fp);
|
89
|
-
}
|
90
|
-
return rc;
|
91
|
-
}
|
92
|
-
|
93
|
-
int pngcheck_buffer(char *data, int size, char *cname, char *extra_msg) {
|
94
|
-
int rc = kCriticalError;
|
95
|
-
extra_msg[0] = 0;
|
96
|
-
char* fname = "[memory buffer]";
|
97
|
-
FILE* fp = fmemopen(data, size, "rb");
|
98
|
-
if (fp == NULL) {
|
99
|
-
failed_to_open(extra_msg, fname);
|
100
|
-
}
|
101
|
-
else {
|
102
|
-
rc = pngcheck_inner(fp, fname, cname, extra_msg);
|
103
|
-
fclose(fp);
|
104
|
-
}
|
105
|
-
return rc;
|
106
|
-
}
|
data/lib/pngcheck/pngcheck.so
DELETED
Binary file
|
data/lib/pngcheck/recipe.rb
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rbconfig"
|
4
|
-
require "mini_portile2"
|
5
|
-
require "pathname"
|
6
|
-
require "tmpdir"
|
7
|
-
require "shellwords"
|
8
|
-
require "open3"
|
9
|
-
require_relative "version"
|
10
|
-
|
11
|
-
module PngCheck
|
12
|
-
class Recipe < MiniPortile
|
13
|
-
ROOT = Pathname.new(File.expand_path("../..", __dir__))
|
14
|
-
COMMON_FLAGS = "-shared -fPIC -Wall -O -DUSE_ZLIB"
|
15
|
-
|
16
|
-
def files_to_load
|
17
|
-
@files << {
|
18
|
-
url: "http://www.libpng.org/pub/png/src/pngcheck-3.0.3.tar.gz",
|
19
|
-
sha256: "c36a4491634af751f7798ea421321642f9590faa032eccb0dd5fb4533609dee6", # rubocop:disable Layout/LineLength
|
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
|
28
|
-
|
29
|
-
def initialize
|
30
|
-
super("pngcheck", "3.0.3")
|
31
|
-
files_to_load
|
32
|
-
@target = ROOT.join(@target).to_s
|
33
|
-
@printed = {}
|
34
|
-
end
|
35
|
-
|
36
|
-
def make_cmd
|
37
|
-
if MiniPortile.windows?
|
38
|
-
"gcc #{COMMON_FLAGS} -o pngcheck.dll wrapper.c -lz"
|
39
|
-
else
|
40
|
-
"#{cc} #{cflags} #{COMMON_FLAGS} -o pngcheck.so wrapper.c -lz"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def cook_if_not
|
45
|
-
cook unless File.exist?(checkpoint)
|
46
|
-
end
|
47
|
-
|
48
|
-
def cook
|
49
|
-
super
|
50
|
-
FileUtils.touch(checkpoint)
|
51
|
-
end
|
52
|
-
|
53
|
-
def checkpoint
|
54
|
-
File.join(@target, "#{name}-#{version}-#{host}.installed")
|
55
|
-
end
|
56
|
-
|
57
|
-
def configure
|
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
|
82
|
-
end
|
83
|
-
|
84
|
-
def install
|
85
|
-
libs = Dir.glob(File.join(work_path, "*"))
|
86
|
-
.grep(%r{/(?:lib)?[a-zA-Z0-9\-]+\.(?:so|dylib|dll)$})
|
87
|
-
|
88
|
-
FileUtils.cp_r(libs, ROOT.join("lib", "pngcheck"), verbose: false)
|
89
|
-
verify_libs
|
90
|
-
end
|
91
|
-
|
92
|
-
def execute(action, command, command_opts = {})
|
93
|
-
super(action, command, command_opts.merge(debug: false))
|
94
|
-
end
|
95
|
-
|
96
|
-
def message(text)
|
97
|
-
return super unless text.start_with?("\rDownloading")
|
98
|
-
|
99
|
-
match = text.match(/(\rDownloading .*)\(\s*\d+%\)/)
|
100
|
-
pattern = match ? match[1] : text
|
101
|
-
return if @printed[pattern]
|
102
|
-
|
103
|
-
@printed[pattern] = true
|
104
|
-
super
|
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
|
188
|
-
end
|
189
|
-
end
|
data/lib/pngcheck/version.rb
DELETED
data/lib/pngcheck.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "ffi"
|
4
|
-
require "tempfile"
|
5
|
-
require_relative "pngcheck/version"
|
6
|
-
|
7
|
-
module PngCheck
|
8
|
-
class CorruptPngError < StandardError; end
|
9
|
-
|
10
|
-
STATUS_OK = 0
|
11
|
-
STATUS_WARNING = 1 # an error in some circumstances but not in all
|
12
|
-
STATUS_MINOR_ERROR = 3 # minor spec errors (e.g., out-of-range values)
|
13
|
-
STATUS_MAJOR_ERROR = 4 # file corruption, invalid chunk length/layout, etc.
|
14
|
-
STATUS_CRITICAL_ERROR = 5 # unexpected EOF or other file(system) error
|
15
|
-
|
16
|
-
EXTRA_MESSAGE_SIZE = 1024
|
17
|
-
|
18
|
-
extend FFI::Library
|
19
|
-
|
20
|
-
lib_filename = FFI::Platform.windows? ? "pngcheck.dll" : "pngcheck.so"
|
21
|
-
ffi_lib File.expand_path("pngcheck/#{lib_filename}", __dir__)
|
22
|
-
.gsub("/", File::ALT_SEPARATOR || File::SEPARATOR)
|
23
|
-
|
24
|
-
# int pngcheck_file(char *fname, char *cname, char *extra_message)
|
25
|
-
typedef :string, :file_path
|
26
|
-
typedef :pointer, :extra_message
|
27
|
-
typedef :int, :status
|
28
|
-
attach_function :pngcheck_file, %i[file_path file_path extra_message],
|
29
|
-
:status
|
30
|
-
# int pngcheck_string(char *data, int size, char *cname, char *extra_message)
|
31
|
-
typedef :pointer, :data
|
32
|
-
typedef :int, :size
|
33
|
-
attach_function :pngcheck_buffer, %i[data size file_path extra_message],
|
34
|
-
:status
|
35
|
-
|
36
|
-
@@semaphore = Mutex.new
|
37
|
-
|
38
|
-
class << self
|
39
|
-
def analyze_file(path)
|
40
|
-
Tempfile.open("captured-stream-") do |captured_stream|
|
41
|
-
extra_msg = FFI::Buffer.alloc_out(EXTRA_MESSAGE_SIZE, 1, false)
|
42
|
-
@@semaphore.lock
|
43
|
-
status = pngcheck_file(path, captured_stream.path, extra_msg)
|
44
|
-
@@semaphore.unlock
|
45
|
-
# we assume that pngcheck_file returns either captured_stream
|
46
|
-
# or extra message but not both
|
47
|
-
[status, captured_stream.read + extra_msg.get_string(16)]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def check_file(path)
|
52
|
-
status, info = analyze_file(path)
|
53
|
-
raise CorruptPngError.new info unless status == STATUS_OK
|
54
|
-
|
55
|
-
true
|
56
|
-
end
|
57
|
-
|
58
|
-
def analyze_buffer(data)
|
59
|
-
Tempfile.open("captured-stream-") do |captured_stream|
|
60
|
-
extra_msg = FFI::Buffer.alloc_out(EXTRA_MESSAGE_SIZE, 1, false)
|
61
|
-
mem_buf = FFI::MemoryPointer.new(:char, data.bytesize)
|
62
|
-
mem_buf.put_bytes(0, data)
|
63
|
-
@@semaphore.lock
|
64
|
-
status = pngcheck_buffer(mem_buf, data.bytesize, captured_stream.path,
|
65
|
-
extra_msg)
|
66
|
-
@@semaphore.unlock
|
67
|
-
[status, captured_stream.read + extra_msg.get_string(16)]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def check_buffer(data)
|
72
|
-
status, info = analyze_buffer(data)
|
73
|
-
raise CorruptPngError.new info unless status == STATUS_OK
|
74
|
-
|
75
|
-
true
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|