Module: PhusionPassenger::PlatformInfo::Depcheck

Defined in:
lib/phusion_passenger/platform_info/depcheck.rb

Overview

Almost all software require other software in order to run. We call those other software ‘dependencies’. Reliably checking for dependencies can be difficult. Helping the user in case a dependency is not installed (or doesn’t seem to be installed) is more difficult still.

The Depcheck framework seeks to make all this easier. It allows the programmer to write “specs” which contain dependency checking code in a structured way. The programmer defines a dependency’s basic information (name, website, etc), defines installation instructions (which may be customized per platform) and defines code for checking whether the dependency actually exists. The Depcheck framework:

* Provides helpers for checking for the existance of commands, libraries,
  headers, etc.
* Registers all dependency specs in a way that can be easily accessed
  structurally.
* Allows user-friendly display of dependency checking progress and user help
  instructions.

Most dependency checking code (e.g. autoconf) is very straightforward: they just check for the existance of a command, library, header, etc and either report “found” or “not found”. In our experience the world is unfortunately not that simple. Users can have multiple versions of a dependency installed, where some dependencies are suitable while others are not. Therefore specs should print as many details about the dependency as possible (location, version, etc) so that the user can override any decisions if necessary.

Defined Under Namespace

Classes: ConsoleRunner, Dependency

Constant Summary collapse

THIS_DIR =
File.expand_path(File.dirname(__FILE__))
@@loaded =
{}
@@database =
{}

Class Method Summary collapse

Class Method Details

.define(identifier, &block) ⇒ Object



51
52
53
# File 'lib/phusion_passenger/platform_info/depcheck.rb', line 51

def self.define(identifier, &block)
	@@database[identifier.to_s] = block
end

.find(identifier) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/phusion_passenger/platform_info/depcheck.rb', line 55

def self.find(identifier)
	# We lazy-initialize everything in order to save resources. This also
	# allows blocks to perform relatively expensive checks without hindering
	# startup time.
	identifier = identifier.to_s
	result = @@database[identifier]
	if result.is_a?(Proc)
		result = Dependency.new(&result)
		@@database[identifier] = result
	end
	result
end

.load(partial_filename) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/phusion_passenger/platform_info/depcheck.rb', line 42

def self.load(partial_filename)
	if !@@loaded[partial_filename]
		filename = "#{THIS_DIR}/#{partial_filename}.rb"
		content = File.read(filename)
		instance_eval(content, filename)
		@@loaded[partial_filename] = true
	end
end