mini_portile2 2.1.0 → 2.8.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,119 @@
1
+ require 'mini_portile2/mini_portile'
2
+ require 'open3'
3
+
4
+ class MiniPortileCMake < MiniPortile
5
+ attr_accessor :system_name
6
+
7
+ def configure_prefix
8
+ "-DCMAKE_INSTALL_PREFIX=#{File.expand_path(port_path)}"
9
+ end
10
+
11
+ def initialize(name, version, **kwargs)
12
+ super(name, version, **kwargs)
13
+ @cmake_command = kwargs[:cmake_command]
14
+ @cmake_build_type = kwargs[:cmake_build_type]
15
+ end
16
+
17
+ def configure_defaults
18
+ [
19
+ generator_defaults,
20
+ cmake_compile_flags,
21
+ ].flatten
22
+ end
23
+
24
+ def configure
25
+ return if configured?
26
+
27
+ cache_file = File.join(tmp_path, 'configure.options_cache')
28
+ File.open(cache_file, "w") { |f| f.write computed_options.to_s }
29
+
30
+ execute('configure', [cmake_cmd] + computed_options + ["."])
31
+ end
32
+
33
+ def configured?
34
+ configure = File.join(work_path, 'configure')
35
+ makefile = File.join(work_path, 'CMakefile')
36
+ cache_file = File.join(tmp_path, 'configure.options_cache')
37
+
38
+ stored_options = File.exist?(cache_file) ? File.read(cache_file) : ""
39
+ current_options = computed_options.to_s
40
+
41
+ (current_options == stored_options) && newer?(makefile, configure)
42
+ end
43
+
44
+ def make_cmd
45
+ return "nmake" if MiniPortile.mswin?
46
+ super
47
+ end
48
+
49
+ def cmake_cmd
50
+ (ENV["CMAKE"] || @cmake_command || "cmake").dup
51
+ end
52
+
53
+ def cmake_build_type
54
+ (ENV["CMAKE_BUILD_TYPE"] || @cmake_build_type || "Release").dup
55
+ end
56
+
57
+ private
58
+
59
+ def generator_defaults
60
+ if MiniPortile.mswin? && generator_available?('NMake')
61
+ ['-G', 'NMake Makefiles']
62
+ elsif MiniPortile.mingw? && generator_available?('MSYS')
63
+ ['-G', 'MSYS Makefiles']
64
+ else
65
+ []
66
+ end
67
+ end
68
+
69
+ def cmake_compile_flags
70
+ # RbConfig::CONFIG['CC'] and RbConfig::CONFIG['CXX'] can contain additional flags, for example
71
+ # "clang++ -std=gnu++11" or "clang -fdeclspec". CMake is just looking for the command name.
72
+ cc_compiler = cc_cmd.split.first
73
+ cxx_compiler = cxx_cmd.split.first
74
+
75
+ # needed to ensure cross-compilation with CMake targets the right CPU and compilers
76
+ [
77
+ "-DCMAKE_SYSTEM_NAME=#{cmake_system_name}",
78
+ "-DCMAKE_SYSTEM_PROCESSOR=#{cpu_type}",
79
+ "-DCMAKE_C_COMPILER=#{cc_compiler}",
80
+ "-DCMAKE_CXX_COMPILER=#{cxx_compiler}",
81
+ "-DCMAKE_BUILD_TYPE=#{cmake_build_type}",
82
+ ]
83
+ end
84
+
85
+ # Full list: https://gitlab.kitware.com/cmake/cmake/-/blob/v3.26.4/Modules/CMakeDetermineSystem.cmake?ref_type=tags#L12-31
86
+ def cmake_system_name
87
+ return system_name if system_name
88
+
89
+ if MiniPortile.linux?
90
+ 'Linux'
91
+ elsif MiniPortile.darwin?
92
+ 'Darwin'
93
+ elsif MiniPortile.windows?
94
+ 'Windows'
95
+ elsif MiniPortile.freebsd?
96
+ 'FreeBSD'
97
+ elsif MiniPortile.openbsd?
98
+ 'OpenBSD'
99
+ elsif MiniPortile.solaris?
100
+ 'SunOS'
101
+ else
102
+ raise "Unable to set CMAKE_SYSTEM_NAME for #{MiniPortile.target_os}"
103
+ end
104
+ end
105
+
106
+ def generator_available?(generator_type)
107
+ stdout_str, status = Open3.capture2("#{cmake_cmd} --help")
108
+
109
+ raise 'Unable to determine whether CMake supports #{generator_type} Makefile generator' unless status.success?
110
+
111
+ stdout_str.include?("#{generator_type} Makefiles")
112
+ end
113
+
114
+ def cpu_type
115
+ return 'x86_64' if MiniPortile.target_cpu == 'x64'
116
+
117
+ MiniPortile.target_cpu
118
+ end
119
+ end
@@ -1,3 +1,3 @@
1
1
  class MiniPortile
2
- VERSION = "2.1.0"
2
+ VERSION = "2.8.7"
3
3
  end
data/lib/mini_portile2.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require "mini_portile2/version"
2
2
  require "mini_portile2/mini_portile"
3
+ require "mini_portile2/mini_portile_cmake"
@@ -1,37 +1,43 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'mini_portile2/version'
1
+ require_relative "lib/mini_portile2/version"
5
2
 
6
3
  Gem::Specification.new do |spec|
7
- spec.name = "mini_portile2"
8
- spec.version = MiniPortile::VERSION
4
+ spec.name = "mini_portile2"
5
+ spec.version = MiniPortile::VERSION
9
6
 
10
- spec.authors = ['Luis Lavena', 'Mike Dalessio', 'Lars Kanis']
11
- spec.email = 'mike.dalessio@gmail.com'
7
+ spec.authors = ["Luis Lavena", "Mike Dalessio", "Lars Kanis"]
8
+ spec.email = "mike.dalessio@gmail.com"
12
9
 
13
- spec.summary = "Simplistic port-like solution for developers"
14
- spec.description = "Simplistic port-like solution for developers. It provides a standard and simplified way to compile against dependency libraries without messing up your system."
10
+ spec.summary = "Simple autoconf and cmake builder for developers"
11
+ spec.description = <<~TEXT
12
+ Simple autoconf and cmake builder for developers. It provides a standard way to compile against
13
+ dependency libraries without requiring system-wide installation. It also simplifies
14
+ vendoring and cross-compilation by providing a consistent build interface.
15
+ TEXT
15
16
 
16
- spec.homepage = 'http://github.com/flavorjones/mini_portile'
17
- spec.licenses = ['MIT']
17
+ spec.homepage = "https://github.com/flavorjones/mini_portile"
18
+ spec.licenses = ["MIT"]
18
19
 
19
- spec.files = `git ls-files -z`.split("\x0")
20
+ begin
21
+ spec.files = `git ls-files -z`.split("\x0")
22
+ rescue Exception => e
23
+ warn "WARNING: could not set spec.files: #{e.class}: #{e}"
24
+ end
20
25
 
21
26
  # omit the `examples` directory from the gem, because it's large and
22
27
  # not necessary to be packaged in the gem.
23
- example_files = spec.files.grep(%r{^examples/})
28
+ example_files = spec.files.grep(%r{^examples/})
24
29
  spec.files -= example_files
25
30
 
26
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
- spec.test_files = spec.files.grep(%r{^(test|spec|features|examples)/})
31
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
32
+ spec.test_files = spec.files.grep(%r{^(test|spec|features|examples)/})
28
33
  spec.require_paths = ["lib"]
29
34
 
30
- spec.add_development_dependency "bundler", "~> 1.7"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency "minitest", "~> 5.8.0"
33
- spec.add_development_dependency "minitest-hooks", "~> 1.4.0"
34
- spec.add_development_dependency "minitar", "~> 0.5.4"
35
+ spec.required_ruby_version = ">= 2.3.0"
35
36
 
36
- spec.required_ruby_version = ">= 1.9.2"
37
+ spec.add_development_dependency "bundler", "~> 2.2"
38
+ spec.add_development_dependency "minitar", "~> 0.9"
39
+ spec.add_development_dependency "minitest", "~> 5.15"
40
+ spec.add_development_dependency "minitest-hooks", "~> 1.5"
41
+ spec.add_development_dependency "rake", "~> 13.0"
42
+ spec.add_development_dependency "webrick", "~> 1.7"
37
43
  end
@@ -0,0 +1 @@
1
+ test
@@ -0,0 +1,9 @@
1
+ -----BEGIN PGP SIGNATURE-----
2
+ Version: GnuPG v1
3
+
4
+ iJwEAAECAAYFAlcFOD8ACgkQZeg+SWTDcLNIswP/XvVRoJ+eQ2u2v+WjXdBBKBSW
5
+ pzM216aJPRBxPl98xNUUKjqga+tjKmIHJn5T4CIxHqis1toPxtE5tKnc6cVO1aqY
6
+ bCUfkWyt/A3qRHQuniRUWSBKZWdk+j3AopTpd3i/r/s0pDj3bMHJ7bDOTsEskNcM
7
+ KpgFfNM1ieFRQmIWPWg=
8
+ =kbKc
9
+ -----END PGP SIGNATURE-----
@@ -0,0 +1,9 @@
1
+ -----BEGIN PGP SIGNATURE-----
2
+ Version: GnuPG v1
3
+
4
+ iJwEAQECAAYFAlcFLEgACgkQZeg+SWTDcLPVwgQAg8KTI91Ryx38YplzgWV9tUPj
5
+ o7J7IEzb8faE7m2mgtq8m62DvA4h/PJzmbh1EJJ4VkO+A4O2LVh/bTgnyYXv+kMu
6
+ sEmvK35PnAC8r7pv98VSbMEXyV/rK3+uGhTvnXZYkULvMVYkN/EHIh2bCQJ3R14X
7
+ MY8El95QST8/dR/yBkw=
8
+ =qbod
9
+ -----END PGP SIGNATURE-----
@@ -0,0 +1,13 @@
1
+ prefix=/foo/libxml2/2.11.5
2
+ exec_prefix=${prefix}
3
+ libdir=/foo/libxml2/2.11.5/lib
4
+ includedir=${prefix}/include
5
+ modules=1
6
+
7
+ Name: libXML
8
+ Version: 2.11.5
9
+ Description: libXML library version2.
10
+ Requires:
11
+ Libs: -L${libdir} -lxml2
12
+ Libs.private: -L/foo/zlib/1.3/lib -lz -lm
13
+ Cflags: -I${includedir}/libxml2 -ggdb3
@@ -0,0 +1,13 @@
1
+ prefix=/foo/libxslt/1.1.38
2
+ exec_prefix=${prefix}
3
+ libdir=/foo/libxslt/1.1.38/lib
4
+ includedir=${prefix}/include
5
+
6
+
7
+ Name: libexslt
8
+ Version: 0.8.21
9
+ Description: EXSLT Extension library
10
+ Requires: libxml-2.0, libxslt
11
+ Cflags: -I${includedir}
12
+ Libs: -L${libdir} -lexslt
13
+ Libs.private: -lm
@@ -0,0 +1,13 @@
1
+ prefix=/foo/libxslt/1.1.38
2
+ exec_prefix=${prefix}
3
+ libdir=/foo/libxslt/1.1.38/lib
4
+ includedir=${prefix}/include
5
+
6
+
7
+ Name: libxslt
8
+ Version: 1.1.38
9
+ Description: XSLT library version 2.
10
+ Requires: libxml-2.0
11
+ Cflags: -I${includedir} -Wno-deprecated-enum-enum-conversion
12
+ Libs: -L${libdir} -lxslt
13
+ Libs.private: -lm
@@ -0,0 +1,7 @@
1
+ # CMakeLists files in this project can
2
+ # refer to the root source directory of the project as ${HELLO_SOURCE_DIR} and
3
+ # to the root binary directory of the project as ${HELLO_BINARY_DIR}.
4
+ cmake_minimum_required (VERSION 2.8.7)
5
+ project (HELLO)
6
+ add_executable (hello hello.c)
7
+ install (TARGETS hello DESTINATION bin)
@@ -0,0 +1,4 @@
1
+ int main(int argc, char** argv)
2
+ {
3
+ return 0 ;
4
+ }
data/test/helper.rb CHANGED
@@ -9,6 +9,12 @@ require 'archive/tar/minitar'
9
9
  require 'fileutils'
10
10
  require 'erb'
11
11
  require 'mini_portile2'
12
+ require 'logger'
13
+
14
+ puts "#{__FILE__}:#{__LINE__}: relevant RbConfig::CONFIG values:"
15
+ %w[target_os target_cpu CC CXX].each do |key|
16
+ puts "- #{key}: #{RbConfig::CONFIG[key].inspect}"
17
+ end
12
18
 
13
19
  class TestCase < Minitest::Test
14
20
  include Minitest::Hooks
@@ -18,7 +24,12 @@ class TestCase < Minitest::Test
18
24
  attr_accessor :webrick
19
25
 
20
26
  def start_webrick(path)
21
- @webrick = WEBrick::HTTPServer.new(:Port => HTTP_PORT, :DocumentRoot => path).tap do |w|
27
+ @webrick = WEBrick::HTTPServer.new(
28
+ :Port => HTTP_PORT,
29
+ :DocumentRoot => path,
30
+ :Logger => Logger.new(File::NULL),
31
+ :AccessLog => [],
32
+ ).tap do |w|
22
33
  Thread.new do
23
34
  w.start
24
35
  end
@@ -37,11 +48,11 @@ class TestCase < Minitest::Test
37
48
  end
38
49
  end
39
50
 
40
- def create_tar(tar_path, assets_path)
51
+ def create_tar(tar_path, assets_path, directory)
41
52
  FileUtils.mkdir_p(File.dirname(tar_path))
42
53
  Zlib::GzipWriter.open(tar_path) do |fdtgz|
43
54
  Dir.chdir(assets_path) do
44
- Archive::Tar::Minitar.pack("test mini portile-1.0.0", fdtgz)
55
+ Archive::Tar::Minitar.pack(directory, fdtgz)
45
56
  end
46
57
  end
47
58
  end
@@ -49,4 +60,28 @@ class TestCase < Minitest::Test
49
60
  def work_dir(r=recipe)
50
61
  "tmp/#{r.host}/ports/#{r.name}/#{r.version}/#{r.name}-#{r.version}"
51
62
  end
63
+
64
+ def with_custom_git_dir(dir)
65
+ old = ENV['GIT_DIR']
66
+ ENV['GIT_DIR'] = dir
67
+ yield
68
+ ensure
69
+ ENV['GIT_DIR'] = old
70
+ end
71
+
72
+ def with_env(env)
73
+ before = ENV.to_h.dup
74
+ env.each { |k, v| ENV[k] = v }
75
+ yield
76
+ ensure
77
+ ENV.replace(before)
78
+ end
79
+
80
+ def without_env(*keys, &blk)
81
+ before = ENV.to_h.dup
82
+ keys.flatten.each { |k| ENV.delete(k) }
83
+ yield
84
+ ensure
85
+ ENV.replace(before)
86
+ end
52
87
  end
@@ -0,0 +1,139 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestActivate < TestCase
4
+ attr_reader :recipe
5
+
6
+ def setup
7
+ super
8
+
9
+ @save_env = %w[PATH CPATH LIBRARY_PATH LDFLAGS].inject({}) do |env, var|
10
+ env.update(var => ENV[var])
11
+ end
12
+
13
+ FileUtils.rm_rf(["tmp", "ports"]) # remove any previous test files
14
+
15
+ @recipe = MiniPortile.new("foo", "1.0.0").tap do |recipe|
16
+ recipe.logger = StringIO.new
17
+ end
18
+ end
19
+
20
+ def teardown
21
+ FileUtils.rm_rf(["tmp", "ports"]) # remove any previous test files
22
+
23
+ @save_env.each do |var, val|
24
+ ENV[var] = val
25
+ end
26
+
27
+ super
28
+ end
29
+
30
+ def test_PATH_env_var_when_bin_does_not_exist
31
+ ENV["PATH"] = "foo"
32
+ refute(Dir.exist?(bin_path))
33
+ refute_includes(path_elements('PATH'), bin_path)
34
+
35
+ recipe.activate
36
+
37
+ refute_includes(path_elements('PATH'), bin_path)
38
+ end
39
+
40
+ def test_PATH_env_var_when_bin_exists
41
+ ENV["PATH"] = "foo"
42
+ FileUtils.mkdir_p(bin_path)
43
+ refute_includes(path_elements('PATH'), bin_path)
44
+
45
+ recipe.activate
46
+
47
+ assert_includes(path_elements('PATH'), bin_path)
48
+ assert_equal(path_elements('PATH').first, bin_path)
49
+ end
50
+
51
+ def test_CPATH_env_var_when_include_does_not_exist
52
+ ENV["CPATH"] = "foo"
53
+ refute(Dir.exist?(include_path))
54
+ refute_includes(path_elements('CPATH'), include_path)
55
+
56
+ recipe.activate
57
+
58
+ refute_includes(path_elements('CPATH'), include_path)
59
+ end
60
+
61
+ def test_CPATH_env_var_when_include_exists
62
+ ENV["CPATH"] = "foo"
63
+ FileUtils.mkdir_p(include_path)
64
+ refute_includes(path_elements('CPATH'), include_path)
65
+
66
+ recipe.activate
67
+
68
+ assert_includes(path_elements('CPATH'), include_path)
69
+ assert_equal(path_elements('CPATH').first, include_path)
70
+ end
71
+
72
+ def test_LIBRARY_PATH_env_var_when_lib_does_not_exist
73
+ ENV["LIBRARY_PATH"] = "foo"
74
+ refute(Dir.exist?(lib_path))
75
+ refute_includes(path_elements('LIBRARY_PATH'), lib_path)
76
+
77
+ recipe.activate
78
+
79
+ refute_includes(path_elements('LIBRARY_PATH'), lib_path)
80
+ end
81
+
82
+ def test_LIBRARY_PATH_env_var_when_lib_exists
83
+ ENV["LIBRARY_PATH"] = "foo"
84
+ FileUtils.mkdir_p(lib_path)
85
+ refute_includes(path_elements('LIBRARY_PATH'), lib_path)
86
+
87
+ recipe.activate
88
+
89
+ assert_includes(path_elements('LIBRARY_PATH'), lib_path)
90
+ assert_equal(path_elements('LIBRARY_PATH').first, lib_path)
91
+ end
92
+
93
+ def test_LDFLAGS_env_var_when_not_cross_compiling
94
+ ENV["LDFLAGS"] = "-lfoo"
95
+ FileUtils.mkdir_p(lib_path)
96
+ assert_equal(recipe.host, recipe.original_host) # assert on setup)
97
+
98
+ refute_includes(flag_elements('LDFLAGS'), "-L#{lib_path}")
99
+
100
+ recipe.activate
101
+
102
+ refute_includes(flag_elements('LDFLAGS'), "-L#{lib_path}")
103
+ end
104
+
105
+ def test_LDFLAGS_env_var_when_cross_compiling
106
+ ENV["LDFLAGS"] = "-lfoo"
107
+ recipe.host = recipe.original_host + "-x" # make them not-equal
108
+ FileUtils.mkdir_p(lib_path)
109
+
110
+ refute_includes(flag_elements('LDFLAGS'), "-L#{lib_path}")
111
+
112
+ recipe.activate
113
+
114
+ assert_includes(flag_elements('LDFLAGS'), "-L#{lib_path}")
115
+ assert_equal(flag_elements('LDFLAGS').first, "-L#{lib_path}")
116
+ end
117
+
118
+ private
119
+
120
+ def path_elements(varname)
121
+ ENV.fetch(varname, "").split(File::PATH_SEPARATOR)
122
+ end
123
+
124
+ def flag_elements(varname)
125
+ ENV.fetch(varname, "").split
126
+ end
127
+
128
+ def bin_path
129
+ MiniPortile.native_path(File.join(recipe.path, "bin"))
130
+ end
131
+
132
+ def include_path
133
+ MiniPortile.native_path(File.join(recipe.path, "include"))
134
+ end
135
+
136
+ def lib_path
137
+ MiniPortile.native_path(File.join(recipe.path, "lib"))
138
+ end
139
+ end