Class: MilkTea::VendoredTool

Inherits:
Object
  • Object
show all
Defined in:
lib/milk_tea/bindings/vendored_tool.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, source_dir:, build_dir:, output_binary_name:, cmake_args: []) ⇒ VendoredTool

Returns a new instance of VendoredTool.



9
10
11
12
13
14
15
# File 'lib/milk_tea/bindings/vendored_tool.rb', line 9

def initialize(name:, source_dir:, build_dir:, output_binary_name:, cmake_args: [])
  @name = name
  @source_dir = File.expand_path(source_dir)
  @build_dir = File.expand_path(build_dir)
  @output_binary_name = output_binary_name
  @cmake_args = cmake_args.dup.freeze
end

Instance Attribute Details

#build_dirObject (readonly)

Returns the value of attribute build_dir.



7
8
9
# File 'lib/milk_tea/bindings/vendored_tool.rb', line 7

def build_dir
  @build_dir
end

#cmake_argsObject (readonly)

Returns the value of attribute cmake_args.



7
8
9
# File 'lib/milk_tea/bindings/vendored_tool.rb', line 7

def cmake_args
  @cmake_args
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/milk_tea/bindings/vendored_tool.rb', line 7

def name
  @name
end

#output_binary_nameObject (readonly)

Returns the value of attribute output_binary_name.



7
8
9
# File 'lib/milk_tea/bindings/vendored_tool.rb', line 7

def output_binary_name
  @output_binary_name
end

#source_dirObject (readonly)

Returns the value of attribute source_dir.



7
8
9
# File 'lib/milk_tea/bindings/vendored_tool.rb', line 7

def source_dir
  @source_dir
end

Instance Method Details

#binary_pathObject



17
18
19
# File 'lib/milk_tea/bindings/vendored_tool.rb', line 17

def binary_path
  File.join(@build_dir, @output_binary_name)
end

#build!Object

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/milk_tea/bindings/vendored_tool.rb', line 29

def build!
  return binary_path if built?

  FileUtils.mkdir_p(@build_dir)

  run_cmake!
  run_make!

  raise Error, "tool #{@name} built but binary not found at #{binary_path}" unless built?

  binary_path
end

#built?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/milk_tea/bindings/vendored_tool.rb', line 25

def built?
  File.file?(binary_path) && File.executable?(binary_path)
end

#install_path(root: MilkTea.root) ⇒ Object



21
22
23
# File 'lib/milk_tea/bindings/vendored_tool.rb', line 21

def install_path(root: MilkTea.root)
  File.join(root, "bin", @output_binary_name)
end