Skip to content

Commit

Permalink
re #980. Ensure @requires is absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmelt committed Jun 27, 2019
1 parent b216354 commit f6faff7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/cosmos/system/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# attribution addendums as found in the LICENSE.txt

require 'cosmos/config/config_parser'
require 'pathname'

module Cosmos
# Target encapsulates the information about a COSMOS target. Targets are
Expand Down Expand Up @@ -150,6 +151,18 @@ def process_file(filename)
rescue Exception => err
raise parser.error(err.message)
end

# This code resolves any relative paths to absolute before putting into the @requires array
unless Pathname.new(filename).absolute?
$:.each do |search_path|
test_filename = File.join(search_path, filename).gsub("\\", "/")
if File.exist?(test_filename)
filename = test_filename
break
end
end
end

@requires << filename

when 'IGNORE_PARAMETER', 'IGNORE_ITEM'
Expand Down
5 changes: 4 additions & 1 deletion spec/system/target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'cosmos'
require 'cosmos/system/target'
require 'tempfile'
require 'pathname'

module Cosmos

Expand Down Expand Up @@ -167,8 +168,10 @@ module Cosmos

# Initial require in target lib shouldn't be reported as error
expect(Logger).to_not receive(:error)
Target.new("INST").process_file(tf.path)
target = Target.new("INST")
target.process_file(tf.path)
expect { SystemFile.new }.to_not raise_error
expect(Pathname.new(target.requires[0]).absolute?).to be true
File.delete filename
tf.unlink
end
Expand Down

0 comments on commit f6faff7

Please sign in to comment.