Skip to content

Commit

Permalink
Merge pull request #126 from flavorjones/flavorjones-better-config-fa…
Browse files Browse the repository at this point in the history
…ilure-log

fix: source_directory option on windows
  • Loading branch information
flavorjones authored Apr 30, 2023
2 parents 5f14c02 + b944100 commit 79341fc
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions lib/mini_portile2/mini_portile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def initialize(name, version, **kwargs)
end

def source_directory=(path)
@source_directory = File.expand_path(path)
@source_directory = posix_path(path)
end

def prepare_build_directory
raise "source_directory is not set" if source_directory.nil?
output "Building #{@name} #{@version} from source at '#{source_directory}'"
output "Building #{@name} from source at '#{source_directory}'"
FileUtils.mkdir_p(File.join(tmp_path, [name, version].join("-")))
FileUtils.rm_rf(port_path) # make sure we always re-install
end
Expand Down Expand Up @@ -137,7 +137,7 @@ def configure
# Windows doesn't recognize the shebang.
command.unshift("sh")
end
execute('configure', command + computed_options)
execute('configure', command + computed_options, altlog: "config.log")
end

def compile
Expand Down Expand Up @@ -200,10 +200,7 @@ def activate

output "Activating #{@name} #{@version} (from #{port_path})..."
vars.each do |var, path|
full_path = File.expand_path(path)

# turn into a valid Windows path (if required)
full_path.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR
full_path = native_path(path)

# save current variable value
old_value = ENV[var] || ''
Expand Down Expand Up @@ -237,7 +234,25 @@ def make_cmd
(ENV["MAKE"] || @make_command || ENV["make"] || "make").dup
end

private
private

def native_path(path)
path = File.expand_path(path)
if File::ALT_SEPARATOR
path.tr(File::SEPARATOR, File::ALT_SEPARATOR)
else
path
end
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
end

def tmp_path
"tmp/#{@host}/ports/#{@name}/#{@version}"
Expand Down Expand Up @@ -420,6 +435,7 @@ def execute(action, command, command_opts={})
opt_debug = command_opts.fetch(:debug, false)
opt_cd = command_opts.fetch(:cd) { work_path }
opt_env = command_opts.fetch(:env) { Hash.new }
opt_altlog = command_opts.fetch(:altlog, nil)

log_out = log_file(action)

Expand Down Expand Up @@ -450,12 +466,12 @@ def execute(action, command, command_opts={})
output "OK"
return true
else
if File.exist? log_out
output "ERROR, review '#{log_out}' to see what happened. Last lines are:"
output("=" * 72)
log_lines = File.readlines(log_out)
output(log_lines[-[log_lines.length, 20].min .. -1])
output("=" * 72)
output "ERROR. Please review logs to see what happened:\n"
[log_out, opt_altlog].compact.each do |log|
next unless File.exist?(log)
output("----- contents of '#{log}' -----")
output(File.read(log))
output("----- end of file -----")
end
raise "Failed to complete #{action} task"
end
Expand Down

0 comments on commit 79341fc

Please sign in to comment.