Skip to content

Commit

Permalink
Implement resolve_source_path in BuildHelper
Browse files Browse the repository at this point in the history
- Implemented the resolve_source_path method in BuildHelper to determine the destination paths for source files when writing to the builder.
- Refactored the logic in the direction block that handles the writing of source files to the builder, making the process clearer and more maintainable.
- Separated the logic that extracts the path of the startup script from the source files, enhancing the modularity of the code.
  • Loading branch information
shinokaro committed Jul 22, 2024
1 parent 73daab1 commit fd703e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
18 changes: 5 additions & 13 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -452,22 +452,13 @@ module Ocran

# Add explicitly mentioned files
Ocran.msg "Adding user-supplied source files"
target_script = nil
source_files.each do |file|
if file.subpath?(exec_prefix)
target = file.relative_path_from(exec_prefix)
elsif file.subpath?(inst_src_prefix)
target = SRCDIR / file.relative_path_from(inst_src_prefix)
else
target = SRCDIR / file.basename
end

target_script ||= target
source_files.each do |source|
target = builder.resolve_source_path(source, inst_src_prefix)

if file.directory?
if source.directory?
builder.mkdir(target)
else
builder.cp(file, target)
builder.cp(source, target)
end
end

Expand All @@ -487,6 +478,7 @@ module Ocran

# Add the opcode to launch the script
installed_ruby_exe = BINDIR / Ocran.ruby_executable
target_script = builder.resolve_source_path(Ocran.script, inst_src_prefix)
builder.exec(installed_ruby_exe, target_script, *@option.argv)
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/ocran/build_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ def duplicate_to_gem_home(source, gem_path)
copy_to_gem(source, Pathname(source).relative_path_from(gem_path))
end

def resolve_source_path(source, root_prefix)
source = Pathname(source)

if source.subpath?(HostConfigHelper.exec_prefix)
source.relative_path_from(HostConfigHelper.exec_prefix)
elsif source.subpath?(root_prefix)
SRCDIR / source.relative_path_from(root_prefix)
else
SRCDIR / source.basename
end
end

# Sets an environment variable with a joined path value.
# This method processes an array of path strings or Pathname objects, accepts
# absolute paths as is, and appends a placeholder to relative paths to convert
Expand Down

0 comments on commit fd703e3

Please sign in to comment.