diff --git a/examples/Rakefile b/examples/Rakefile index b55c8f0..74b9638 100644 --- a/examples/Rakefile +++ b/examples/Rakefile @@ -131,7 +131,7 @@ yaml.files = [{ }] recipes.push(yaml) recipe_hooks["yaml"] = lambda do |recipe| - expected = "-L" + File.join(recipe.path, "lib") + expected = "-L" + MiniPortile.native_path(File.join(recipe.path, "lib")) $LDFLAGS.split.include?(expected) or raise(<<~MSG) assertion failed: LDFLAGS not updated correctly: #{$LDFLAGS} diff --git a/lib/mini_portile2/mini_portile.rb b/lib/mini_portile2/mini_portile.rb index e16e02a..795435f 100644 --- a/lib/mini_portile2/mini_portile.rb +++ b/lib/mini_portile2/mini_portile.rb @@ -76,6 +76,24 @@ def self.target_cpu RbConfig::CONFIG['target_cpu'] end + def self.native_path(path) + path = File.expand_path(path) + if File::ALT_SEPARATOR + path.tr(File::SEPARATOR, File::ALT_SEPARATOR) + else + path + end + end + + def self.posix_path(path) + path = File.expand_path(path) + if File::ALT_SEPARATOR + "/" + path.tr(File::ALT_SEPARATOR, File::SEPARATOR).tr(":", File::SEPARATOR) + else + path + end + end + def initialize(name, version, **kwargs) @name = name @version = version @@ -240,7 +258,7 @@ def activate end if set_ldflags && File.exist?(lib_path) - full_lib_path = File.expand_path(lib_path) + full_lib_path = native_path(lib_path) flag = "-L#{full_lib_path}" # rely on LDFLAGS when cross-compiling @@ -278,21 +296,11 @@ def make_cmd private def native_path(path) - path = File.expand_path(path) - if File::ALT_SEPARATOR - path.tr(File::SEPARATOR, File::ALT_SEPARATOR) - else - path - end + MiniPortile.native_path(path) end def posix_path(path) - path = File.expand_path(path) - if File::ALT_SEPARATOR - "/" + path.tr(File::ALT_SEPARATOR, File::SEPARATOR).tr(":", File::SEPARATOR) - else - path - end + MiniPortile.posix_path(path) end def tmp_path diff --git a/test/test_activate.rb b/test/test_activate.rb index 84c3f96..9362c85 100644 --- a/test/test_activate.rb +++ b/test/test_activate.rb @@ -31,78 +31,78 @@ def teardown def test_PATH_env_var_when_bin_does_not_exist refute(Dir.exist?(bin_path)) - refute(path_elements('PATH').include?(bin_path)) + refute_includes(path_elements('PATH'), bin_path) recipe.activate - refute(path_elements('PATH').include?(bin_path)) + refute_includes(path_elements('PATH'), bin_path) end def test_PATH_env_var_when_bin_exists FileUtils.mkdir_p(bin_path) - refute(path_elements('PATH').include?(bin_path)) + refute_includes(path_elements('PATH'), bin_path) recipe.activate - assert(path_elements('PATH').include?(bin_path)) + assert_includes(path_elements('PATH'), bin_path) end def test_CPATH_env_var_when_include_does_not_exist refute(Dir.exist?(include_path)) - refute(path_elements('CPATH').include?(include_path)) + refute_includes(path_elements('CPATH'), include_path) recipe.activate - refute(path_elements('CPATH').include?(include_path)) + refute_includes(path_elements('CPATH'), include_path) end def test_CPATH_env_var_when_include_exists FileUtils.mkdir_p(include_path) - refute(path_elements('CPATH').include?(include_path)) + refute_includes(path_elements('CPATH'), include_path) recipe.activate - assert(path_elements('CPATH').include?(include_path)) + assert_includes(path_elements('CPATH'), include_path) end def test_LIBRARY_PATH_env_var_when_lib_does_not_exist refute(Dir.exist?(lib_path)) - refute(path_elements('LIBRARY_PATH').include?(lib_path)) + refute_includes(path_elements('LIBRARY_PATH'), lib_path) recipe.activate - refute(path_elements('LIBRARY_PATH').include?(lib_path)) + refute_includes(path_elements('LIBRARY_PATH'), lib_path) end def test_LIBRARY_PATH_env_var_when_lib_exists FileUtils.mkdir_p(lib_path) - refute(path_elements('LIBRARY_PATH').include?(lib_path)) + refute_includes(path_elements('LIBRARY_PATH'), lib_path) recipe.activate - assert(path_elements('LIBRARY_PATH').include?(lib_path)) + assert_includes(path_elements('LIBRARY_PATH'), lib_path) end def test_LDFLAGS_env_var_when_not_cross_compiling FileUtils.mkdir_p(lib_path) assert_equal(recipe.host, recipe.original_host) # assert on setup) - refute(flag_elements('LDFLAGS').include?("-L#{lib_path}")) + refute_includes(flag_elements('LDFLAGS'), "-L#{lib_path}") recipe.activate - refute(flag_elements('LDFLAGS').include?("-L#{lib_path}")) + refute_includes(flag_elements('LDFLAGS'), "-L#{lib_path}") end def test_LDFLAGS_env_var_when_cross_compiling recipe.host = recipe.original_host + "-x" # make them not-equal FileUtils.mkdir_p(lib_path) - refute(flag_elements('LDFLAGS').include?("-L#{lib_path}")) + refute_includes(flag_elements('LDFLAGS'), "-L#{lib_path}") recipe.activate - assert(flag_elements('LDFLAGS').include?("-L#{lib_path}")) + assert_includes(flag_elements('LDFLAGS'), "-L#{lib_path}") end def test_LDFLAGS_global_when_not_set @@ -120,7 +120,7 @@ def test_LDFLAGS_global_when_set recipe.activate - assert($LDFLAGS.split.include?("-L#{lib_path}")) + assert_includes($LDFLAGS.split, "-L#{lib_path}") end def test_LDFLAGS_global_when_set_but_option_is_turned_off @@ -130,7 +130,7 @@ def test_LDFLAGS_global_when_set_but_option_is_turned_off recipe.set_ldflags = false recipe.activate - refute($LDFLAGS.split.include?("-L#{lib_path}")) + refute_includes($LDFLAGS.split, "-L#{lib_path}") end private @@ -144,14 +144,14 @@ def flag_elements(varname) end def bin_path - File.join(recipe.path, "bin") + MiniPortile.native_path(File.join(recipe.path, "bin")) end def include_path - File.join(recipe.path, "include") + MiniPortile.native_path(File.join(recipe.path, "include")) end def lib_path - File.join(recipe.path, "lib") + MiniPortile.native_path(File.join(recipe.path, "lib")) end end