ruby-magic-static 0.3.0 → 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: e25b370819fbafc50a7ea88a29f26c42be0eed8823fe62750cf580587a77ddb2
4
- data.tar.gz: d9e4e9dd790db8a7ce9b3960df281b3ab45690a93780979e32faf39f17eb9e49
3
+ metadata.gz: d2c030798a63296efab456780eb4c3007d726a6b1d4e476eeb3dc75d0b841a38
4
+ data.tar.gz: f6160d4cbd9f4b06f258c4520c053a8547fdba2f19929379a5f9f6838027eeb8
5
5
  SHA512:
6
- metadata.gz: 527d6cf28036c92c87a4065897d19652d4b74c7ab54c7e7c54128e99d82bad98d232c1626a90c898a9810dd5a73419359fb72dfadb4f1fec86e1ad6b6759191b
7
- data.tar.gz: 94354ba381a33c3212d82a5d9d1cd00f692d27cc529709a5f96a4059407527525689b2547105b1c1651dbc93546d7a56a83577a3c12151529cb961a44391225c
6
+ metadata.gz: 33b1443a54625b4743970a2993306847cf87b5746c05062f1b078340291d3cb7694308ed7c8805b6228dc1ca41de13565e038f637e52f88361e173943fd7e7e9
7
+ data.tar.gz: cc704e577a836cab16a29fe05426e0a7ca1971591b0578095ba5c998c0a05a3a952e990b6756491c62ec769e56399d8e3d6c6e3e1d582b4fd864dc931651a550
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
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("ftp://ftp.astron.com/pub/file/file-#{LIBMAGIC_TAG}.tar.gz", '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
24
90
  end
25
- end
26
91
 
27
- checksum = Digest::SHA256.hexdigest(File.read(filename))
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
+ ]
118
+ end
119
+
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
36
135
 
37
- $LOCAL_LIBS << '-lmagic'
38
- $LIBPATH << gem_lib_dir
39
- $CFLAGS << " -I #{libdir}/src"
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
144
+
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
@@ -120,8 +313,6 @@ unless have_header('ruby.h')
120
313
  EOS
121
314
  end
122
315
 
123
- have_library('ruby')
124
-
125
316
  have_func('rb_thread_call_without_gvl')
126
317
  have_func('rb_thread_blocking_region')
127
318
 
@@ -190,7 +381,17 @@ end
190
381
  have_func(f)
191
382
  end
192
383
 
193
- dir_config('magic', [gem_include_dir], [gem_lib_dir])
194
-
195
384
  create_header
196
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.2.0'.freeze
7
+ VERSION = '0.3.5'.freeze
8
8
 
9
9
  class << self
10
10
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-magic-static
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Wilczyński
@@ -9,8 +9,22 @@ 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
 
@@ -39,15 +53,14 @@ files:
39
53
  - lib/magic/core/file.rb
40
54
  - lib/magic/core/string.rb
41
55
  - lib/magic/version.rb
42
- homepage: https://github.com/kwilczynski/ruby-magic
56
+ homepage: https://gitlab.com/gitlab-org/ruby-magic
43
57
  licenses:
44
58
  - Apache-2.0
45
59
  metadata:
46
- bug_tracker_uri: https://github.com/kwilczynski/ruby-magic/issues
60
+ bug_tracker_uri: https://gitlab.com/gitlab-org/ruby-magic/-/issues
47
61
  source_code_uri: https://gitlab.com/gitlab-org/ruby-magic
48
- changelog_uri: https://github.com/kwilczynski/ruby-magic/blob/master/CHANGELOG.md
49
- documentation_uri: https://www.rubydoc.info/gems/ruby-magic
50
- wiki_uri: https://github.com/kwilczynski/ruby-magic/wiki
62
+ changelog_uri: https://gitlab.com/gitlab-org/ruby-magic/-/blob/main/CHANGELOG.md
63
+ documentation_uri: https://www.rubydoc.info/gems/ruby-magic-static
51
64
  post_install_message: 'Thank you for installing!
52
65
 
53
66
  '