Class: Teapot::Build::Targets::External

Inherits:
Teapot::Build::Target show all
Defined in:
lib/teapot/build/targets/external.rb

Constant Summary collapse

ENVIRONMENT_CHECKSUM_FILE =

This file contains a checksum of the build environment. If it changes, even though the source code hasn’t changed, it means that we need to recompile.

".teapot-environment-checksum"

Instance Attribute Summary

Attributes inherited from Teapot::Build::Target

#parent

Instance Method Summary collapse

Methods inherited from Teapot::Build::Target

#configure, #execute, target

Constructor Details

#initialize(parent, directory, &block) ⇒ External

Returns a new instance of External.



31
32
33
34
35
36
37
38
# File 'lib/teapot/build/targets/external.rb', line 31

def initialize(parent, directory, &block)
  super parent
  
  @directory = directory
  
  # Callback for preparing the target and compiling/installing the target.
  @install = block
end

Instance Method Details

#install(values) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/teapot/build/targets/external.rb', line 44

def install(values)
  return unless @install
  
  source_path = @parent.root + @directory
  build_source_path = values[:build_prefix] + @directory
  build_source_checksum_path = build_source_path + ENVIRONMENT_CHECKSUM_FILE
  
  fresh = false
  
  # Check the environment checksum to catch any changes to the build environment:
  if build_source_checksum_path.exist? and File.read(build_source_checksum_path.to_s) != checksum(values)
    FileUtils.rm_rf(build_source_path.to_s) if build_source_path.exist?
  end
  
  if !build_source_path.exist?
    build_source_path.mkpath
    
    FileUtils.cp_r(source_path.children, build_source_path.to_s)
    
    # Write the environment checksum out to a file:
    File.write(build_source_checksum_path, checksum(values))
    
    fresh = true
  end
  
  # Convert the hash to suit typical shell specific arguments:
  shell_environment = Environment::System::convert_to_shell(values)
  
  Dir.chdir(build_source_path) do
    RExec.env(shell_environment) do
      @install.call(Environment::Evaluator.new(values), fresh)
    end
  end
end

#rootObject



40
41
42
# File 'lib/teapot/build/targets/external.rb', line 40

def root
  @parent.root + @directory
end