ruby-magic-static 0.3.4 → 0.3.5

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: 6a118fb30baf8efe6609c2c53be2ee97293223e676b5f0e701b74b3df2750623
4
- data.tar.gz: 6899ed5eff8e728bb59454f10c2f27337d66085602085300addb256defc8e0a6
3
+ metadata.gz: d2c030798a63296efab456780eb4c3007d726a6b1d4e476eeb3dc75d0b841a38
4
+ data.tar.gz: f6160d4cbd9f4b06f258c4520c053a8547fdba2f19929379a5f9f6838027eeb8
5
5
  SHA512:
6
- metadata.gz: 364aa9324170513fe9ed7b1dd785920196c62c22cb12fc6d29507ad5526fd9861f35f6781b9b06324511eb1f7a1a660135718a74eb8e13aa7d70a52e24a99a03
7
- data.tar.gz: '0922f85efb9ca3ad786d4ab167812963254e17b790a066e45765e4fcfe944c23bae149379c23b92a954b003ebd1e6662e043cfa6dbd02cce9eb9938b8e9babd9'
6
+ metadata.gz: 33b1443a54625b4743970a2993306847cf87b5746c05062f1b078340291d3cb7694308ed7c8805b6228dc1ca41de13565e038f637e52f88361e173943fd7e7e9
7
+ data.tar.gz: cc704e577a836cab16a29fe05426e0a7ca1971591b0578095ba5c998c0a05a3a952e990b6756491c62ec769e56399d8e3d6c6e3e1d582b4fd864dc931651a550
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
data/ext/magic/extconf.rb CHANGED
@@ -1,42 +1,152 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'find'
3
4
  require 'mkmf'
4
- require 'digest'
5
- require 'open-uri'
6
-
7
- LIBMAGIC_TAG = '5.39'.freeze
8
-
9
- workdir = Dir.pwd
10
- libdir = File.join(workdir, 'file-' + LIBMAGIC_TAG)
11
- gemdir = File.expand_path(File.join(__dir__, '../..'))
12
- gem_ext_dir = File.join(gemdir, 'lib', 'ext')
13
- gem_include_dir = File.join(gem_ext_dir, 'include')
14
- gem_lib_dir = File.join(gem_ext_dir, 'lib')
15
- build_lib_dir = File.join(libdir, 'src', '.libs')
16
-
17
- expected_sha256 = 'f05d286a76d9556243d0cb05814929c2ecf3a5ba07963f8f70bfaaa70517fad1'
18
- filename = "#{workdir}/file.tar.gz"
19
-
20
- unless File.exist?(filename)
21
- File.open(filename, 'wb') do |target_file|
22
- URI.open("https://gitlab.com/gitlab-org/file-mirror/-/package_files/8589820/download", 'rb') do |read_file|
23
- target_file.write(read_file.read)
5
+ require 'pathname'
6
+
7
+ LIBMAGIC_TAG = '5.39'
8
+ LIBIMAGE_SHA256 = 'f05d286a76d9556243d0cb05814929c2ecf3a5ba07963f8f70bfaaa70517fad1'
9
+
10
+ # helpful constants
11
+ PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
12
+
13
+ # The gem version constraint in the Rakefile is not respected at install time.
14
+ # Keep this version in sync with the one in the Rakefile !
15
+ REQUIRED_MINI_PORTILE_VERSION = "~> 2.5.0"
16
+
17
+ MAGIC_HELP_MESSAGE = <<~HELP
18
+ USAGE: ruby #{$0} [options]
19
+
20
+ Flags that are always valid:
21
+
22
+ --use-system-libraries
23
+ --enable-system-libraries
24
+ Use system libraries instead of building and using the packaged libraries.
25
+
26
+ --disable-system-libraries
27
+ Use the packaged libraries, and ignore the system libraries. This is the default on most
28
+ platforms, and overrides `--use-system-libraries` and the environment variable
29
+ `RB_MAGIC_USE_SYSTEM_LIBRARIES`.
30
+
31
+ --disable-clean
32
+ Do not clean out intermediate files after successful build.
33
+
34
+ Flags only used when building and using the packaged libraries:
35
+
36
+ --disable-static
37
+ Do not statically link packaged libraries, instead use shared libraries.
38
+
39
+ --enable-cross-build
40
+ Enable cross-build mode. (You probably do not want to set this manually.)
41
+
42
+ Flags only used when using system libraries:
43
+
44
+ Related to libmagic:
45
+
46
+ --with-magic-dir=DIRECTORY
47
+ Look for libmagic headers and library in DIRECTORY.
48
+
49
+ --with-magic-lib=DIRECTORY
50
+ Look for libmagic library in DIRECTORY.
51
+
52
+ --with-magic-include=DIRECTORY
53
+ Look for libmagic headers in DIRECTORY.
54
+
55
+ Environment variables used:
56
+
57
+ CC
58
+ Use this path to invoke the compiler instead of `RbConfig::CONFIG['CC']`
59
+
60
+ CPPFLAGS
61
+ If this string is accepted by the C preprocessor, add it to the flags passed to the C preprocessor
62
+
63
+ CFLAGS
64
+ If this string is accepted by the compiler, add it to the flags passed to the compiler
65
+
66
+ LDFLAGS
67
+ If this string is accepted by the linker, add it to the flags passed to the linker
68
+
69
+ LIBS
70
+ Add this string to the flags passed to the linker
71
+ HELP
72
+
73
+ def process_recipe(name, version, static_p, cross_p)
74
+ require 'rubygems'
75
+ gem('mini_portile2', REQUIRED_MINI_PORTILE_VERSION)
76
+ require 'mini_portile2'
77
+ message("Using mini_portile version #{MiniPortile::VERSION}\n")
78
+
79
+ MiniPortile.new(name, version).tap do |recipe|
80
+ # Prefer host_alias over host in order to use i586-mingw32msvc as
81
+ # correct compiler prefix for cross build, but use host if not set.
82
+ recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
83
+ recipe.target = File.join(PACKAGE_ROOT_DIR, "ports")
84
+ recipe.configure_options << "--libdir=#{File.join(recipe.path, 'lib')}"
85
+
86
+ yield recipe
87
+
88
+ env = Hash.new do |hash, key|
89
+ hash[key] = (ENV[key]).to_s
90
+ end
91
+
92
+ recipe.configure_options.flatten!
93
+
94
+ recipe.configure_options = [
95
+ "--disable-silent-rules",
96
+ "--disable-dependency-tracking",
97
+ "--enable-fsect-man5"
98
+ ]
99
+
100
+ if static_p
101
+ recipe.configure_options += [
102
+ "--disable-shared",
103
+ "--enable-static",
104
+ ]
105
+ env["CFLAGS"] = concat_flags(env["CFLAGS"], "-fPIC")
106
+ else
107
+ recipe.configure_options += [
108
+ "--enable-shared",
109
+ "--disable-static",
110
+ ]
111
+ end
112
+
113
+ if cross_p
114
+ recipe.configure_options += [
115
+ "--target=#{recipe.host}",
116
+ "--host=#{recipe.host}",
117
+ ]
24
118
  end
25
- end
26
119
 
27
- checksum = Digest::SHA256.hexdigest(File.read(filename))
120
+ recipe.configure_options += env.map do |key, value|
121
+ "#{key}=#{value.strip}"
122
+ end
28
123
 
29
- if checksum != expected_sha256
30
- raise "SHA256 of #{filename} does not match: got #{checksum}, expected #{expected_sha256}"
124
+ recipe.cook
125
+ recipe.activate
31
126
  end
32
127
  end
33
128
 
34
- system("tar -xzf #{filename}") || raise('ERROR')
35
- system("cd #{libdir} && ./configure --prefix=#{gem_ext_dir} && make install") || raise('ERROR')
129
+ #
130
+ # utility functions
131
+ #
132
+ def config_clean?
133
+ enable_config('clean', true)
134
+ end
135
+
136
+ def config_static?
137
+ default_static = !truffle?
138
+ enable_config("static", default_static)
139
+ end
140
+
141
+ def config_cross_build?
142
+ enable_config("cross-build")
143
+ end
36
144
 
37
- $LOCAL_LIBS << '-lmagic'
38
- $LIBPATH << gem_lib_dir
39
- $CFLAGS << " -I #{libdir}/src"
145
+ def config_system_libraries?
146
+ enable_config("system-libraries", ENV.key?("RB_MAGIC_USE_SYSTEM_LIBRARIES")) do |_, default|
147
+ arg_config('--use-system-libraries', default)
148
+ end
149
+ end
40
150
 
41
151
  def darwin?
42
152
  RbConfig::CONFIG['target_os'] =~ /darwin/
@@ -46,6 +156,89 @@ def windows?
46
156
  RbConfig::CONFIG['target_os'] =~ /mswin|mingw32|windows/
47
157
  end
48
158
 
159
+ def truffle?
160
+ ::RUBY_ENGINE == 'truffleruby'
161
+ end
162
+
163
+ def concat_flags(*args)
164
+ args.compact.join(" ")
165
+ end
166
+
167
+ def do_help
168
+ print(MAGIC_HELP_MESSAGE)
169
+ exit!(0)
170
+ end
171
+
172
+ def do_clean
173
+ root = Pathname(PACKAGE_ROOT_DIR)
174
+ pwd = Pathname(Dir.pwd)
175
+
176
+ # Skip if this is a development work tree
177
+ unless (root + '.git').exist?
178
+ message("Cleaning files only used during build.\n")
179
+
180
+ # (root + 'tmp') cannot be removed at this stage because
181
+ # libmagic.so is yet to be copied to lib.
182
+
183
+ # clean the ports build directory
184
+ Pathname.glob(pwd.join('tmp', '*', 'ports')) do |dir|
185
+ FileUtils.rm_rf(dir, verbose: true)
186
+ end
187
+
188
+ FileUtils.rm_rf(root + 'ports' + 'archives', verbose: true)
189
+
190
+ # Remove everything but share/ directory
191
+ remove_paths = %w[bin include]
192
+ remove_paths << 'lib' if config_static?
193
+
194
+ Pathname.glob(File.join(root, 'ports', '*', 'libmagic', '*')) do |dir|
195
+ remove_paths.each do |path|
196
+ remove_dir = File.join(dir, path)
197
+ FileUtils.rm_rf(remove_dir, verbose: true)
198
+ end
199
+ end
200
+ end
201
+
202
+ exit!(0)
203
+ end
204
+
205
+ #
206
+ # main
207
+ #
208
+ do_help if arg_config('--help')
209
+ do_clean if arg_config('--clean')
210
+
211
+ if config_system_libraries?
212
+ message "Building ruby-magic using system libraries.\n"
213
+
214
+ dir_config('magic')
215
+ else
216
+ message "Building ruby-magic using packaged libraries.\n"
217
+
218
+ static_p = config_static?
219
+ message "Static linking is #{static_p ? 'enabled' : 'disabled'}.\n"
220
+ cross_build_p = config_cross_build?
221
+ message "Cross build is #{cross_build_p ? 'enabled' : 'disabled'}.\n"
222
+
223
+ libmagic_recipe = process_recipe('libmagic', LIBMAGIC_TAG, static_p, cross_build_p) do |recipe|
224
+ recipe.files = [{
225
+ url: "https://gitlab.com/gitlab-org/file-mirror/-/package_files/8589820/download",
226
+ sha256: LIBIMAGE_SHA256
227
+ }]
228
+ end
229
+
230
+ $LIBPATH = [File.join(libmagic_recipe.path, 'lib')]
231
+ $CFLAGS << " -I#{File.join(libmagic_recipe.path, 'include')} "
232
+ $LDFLAGS += " -Wl,-rpath,#{libmagic_recipe.path}/lib"
233
+
234
+ if static_p
235
+ ENV['PKG_CONFIG_PATH'] = "#{libmagic_recipe.path}/lib/pkgconfig"
236
+ # mkmf appends -- to the first option
237
+ $LIBS += " " + pkg_config('libmagic', 'libs --static')
238
+ $LIBS += " " + File.join(libmagic_recipe.path, 'lib', "libmagic.#{$LIBEXT}")
239
+ end
240
+ end
241
+
49
242
  if ENV['CC']
50
243
  RbConfig::CONFIG['CC'] = RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC']
51
244
  end
@@ -188,7 +381,17 @@ end
188
381
  have_func(f)
189
382
  end
190
383
 
191
- dir_config('magic', [gem_include_dir], [gem_lib_dir])
192
-
193
384
  create_header
194
385
  create_makefile('magic/magic')
386
+
387
+ if config_clean?
388
+ # Do not clean if run in a development work tree.
389
+ File.open('Makefile', 'at') do |mk|
390
+ mk.print(<<~EOF)
391
+
392
+ all: clean-ports
393
+ clean-ports: $(DLLIB)
394
+ \t-$(Q)$(RUBY) $(srcdir)/extconf.rb --clean --#{static_p ? 'enable' : 'disable'}-static
395
+ EOF
396
+ end
397
+ end
data/lib/magic/version.rb CHANGED
@@ -4,7 +4,7 @@ class Magic
4
4
  #
5
5
  # Current version of _Magic_.
6
6
  #
7
- VERSION = '0.3.4'.freeze
7
+ VERSION = '0.3.5'.freeze
8
8
 
9
9
  class << self
10
10
  #
metadata CHANGED
@@ -1,16 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-magic-static
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Wilczyński
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - kwilczynski-public.pem
12
- date: 2021-03-25 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2021-03-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mini_portile2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 2.5.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.5.0
14
28
  description: |
15
29
  File Magic in Ruby.
16
30
 
@@ -49,7 +63,7 @@ metadata:
49
63
  documentation_uri: https://www.rubydoc.info/gems/ruby-magic-static
50
64
  post_install_message: 'Thank you for installing!
51
65
 
52
- '
66
+ '
53
67
  rdoc_options: []
54
68
  require_paths:
55
69
  - lib
@@ -66,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
80
  version: '0'
67
81
  requirements: []
68
82
  rubygems_version: 3.1.4
69
- signing_key:
83
+ signing_key:
70
84
  specification_version: 4
71
85
  summary: File Magic in Ruby
72
86
  test_files: []