Module: Ocran::BuildHelper

Includes:
BuildConstants, CommandOutput
Defined in:
lib/ocran/build_helper.rb

Constant Summary collapse

EMPTY_SOURCE =
File.expand_path("empty_source", __dir__).freeze

Constants included from BuildConstants

Ocran::BuildConstants::BINDIR, Ocran::BuildConstants::EXTRACT_ROOT, Ocran::BuildConstants::GEMDIR, Ocran::BuildConstants::LIBDIR, Ocran::BuildConstants::SRCDIR

Instance Method Summary collapse

Methods included from CommandOutput

#error, #say, #verbose, #warning

Instance Method Details

#copy_to_bin(source, target) ⇒ Object



41
42
43
# File 'lib/ocran/build_helper.rb', line 41

def copy_to_bin(source, target)
  cp(source, BINDIR / target)
end

#copy_to_gem(source, target) ⇒ Object



45
46
47
# File 'lib/ocran/build_helper.rb', line 45

def copy_to_gem(source, target)
  cp(source, GEMDIR / target)
end

#copy_to_lib(source, target) ⇒ Object



49
50
51
# File 'lib/ocran/build_helper.rb', line 49

def copy_to_lib(source, target)
  cp(source, LIBDIR / target)
end

#cp(source, target) ⇒ Object



20
21
22
23
# File 'lib/ocran/build_helper.rb', line 20

def cp(source, target)
  verbose "cp #{source} #{target}"
  super
end

#duplicate_to_exec_prefix(source) ⇒ Object



53
54
55
# File 'lib/ocran/build_helper.rb', line 53

def duplicate_to_exec_prefix(source)
  cp(source, Pathname(source).relative_path_from(HostConfigHelper.exec_prefix))
end

#duplicate_to_gem_home(source, gem_path) ⇒ Object



57
58
59
# File 'lib/ocran/build_helper.rb', line 57

def duplicate_to_gem_home(source, gem_path)
  copy_to_gem(source, Pathname(source).relative_path_from(gem_path))
end

#exec(image, script, *argv) ⇒ Object



25
26
27
28
29
# File 'lib/ocran/build_helper.rb', line 25

def exec(image, script, *argv)
  args = argv.map { |s| replace_placeholder(s) }.join(" ")
  verbose "exec #{image} #{script} #{args}"
  super
end

#export(name, value) ⇒ Object



31
32
33
34
# File 'lib/ocran/build_helper.rb', line 31

def export(name, value)
  verbose "export #{name}=#{replace_placeholder(value)}"
  super
end

#mkdir(target) ⇒ Object



15
16
17
18
# File 'lib/ocran/build_helper.rb', line 15

def mkdir(target)
  verbose "mkdir #{target}"
  super
end

#resolve_source_path(source, root_prefix) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ocran/build_helper.rb', line 61

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

#set_env_path(name, *paths) ⇒ Object

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 them into absolute paths. The converted paths are then joined into a single string using the system’s path separator.

Example:

set_env_path("RUBYLIB", "lib", "ext", "vendor/lib")
# This sets RUBYLIB to a string such as "C:/ProjectRoot/lib;C:/ProjectRoot/ext;C:/ProjectRoot/vendor/lib"
# assuming each path is correctly converted to an absolute path through a placeholder.

Parameters:

  • name (String)

    the name of the environment variable to set.

  • paths (Array<String, Pathname>)

    an array of path arguments which can be either absolute or relative.



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ocran/build_helper.rb', line 88

def set_env_path(name, *paths)
  value = paths.map { |path|
    if File.absolute_path?(path)
      path
    else
      File.join(EXTRACT_ROOT, path)
    end
  }.join(File::PATH_SEPARATOR)

  export(name, value)
end

#touch(target) ⇒ Object



100
101
102
103
# File 'lib/ocran/build_helper.rb', line 100

def touch(target)
  verbose "touch #{target}"
  cp(EMPTY_SOURCE, target)
end