Module: L::Util

Defined in:
lib/rub/l/util.rb

Overview

General purpose build tools.

Defined Under Namespace

Classes: TargetUninstall

Class Method Summary collapse

Class Method Details

.install(what, where, mode: nil, require: []) ⇒ Array<Pathname>

Install a file

Installs what into the directory where. Source files are added to the =all tag and installed files are added to the =install tag.

Examples:

exe = L::C.program(srcs, ['pthread'], 'bitmonitor-test')
L::Util.install exe, 'bin/', mode: 755

Parameters:

  • what (Set<Pathname,String>, Array<Pathname,String>, Pathname, String)

    The files to install.

  • where (Pathname, String)

    The directory to install them to. If not absolute it is relative to D:prefix

  • mode (Numeric) (defaults to: nil)

    The permissions (specified in base ten) for the file. If nil the current permissions are kept.

  • require (Set<Pathname,String>, Array<Pathname,String>, Pathname, String) (defaults to: [])

    Files that must be present before installing the file.

Returns:

  • (Array<Pathname>)

    The installed files.



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/rub/l/util.rb', line 150

def self.install(what, where, mode: nil, require: [])
	what = R::Tool.make_set_paths what
	where = Pathname.new(where)
	require = R::Tool.make_set_paths require
	
	what.map do |f|
		if f.directory?
			install(f.children, where+f.basename)
		else
			install_to(f, where+f.basename)
		end
	end.flatten.to_set
end

.install_to(from, to, mode: nil, require: []) ⇒ Array<Pathname>

Install a file to a specific location.

Similar to #install but the basename is not used as the name in the new location. If from is a dirtectory it is installed and renamed but it’s contents are preserved with the same names.

Parameters:

  • from (Set<Pathname,String>, Array<Pathname,String>, Pathname, String)

    The files to install.

  • to (Pathname, String)

    Where to install them. If not absolute it is relative to D:prefix

  • mode (Numeric) (defaults to: nil)

    The permissions (specified in base ten) for the file. If nil the current permissions are kept.

  • require (Set<Pathname,String>, Array<Pathname,String>, Pathname, String) (defaults to: [])

    Files that must be present before installing the file.

Returns:

  • (Array<Pathname>)

    The installed files.

See Also:

  • #install


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rub/l/util.rb', line 109

def self.install_to(from, to, mode: nil, require: [])
	from = C.path(from)
	to   = Pathname.new(to).expand_path(D :prefix)
	
	if from.directory?
		return install(from.children, to)
	end
	
	C.generator(
		Set[from].merge(require),
		['install', "-D#{mode!=nil ? "m#{mode}" : "" }", from, to],
		to,
		desc: 'Installing'
	).each do |o|
		C.tag(:all    ).require(from)
		C.tag(:install).require(to)
	end
	uninstall to
	
	Set[from]
end

Create a link

Parameters:

  • target (Pathname, String)

    The file the link points to.

  • name (Pathname, String)

    The location of the link.

  • type (:sym, :hard) (defaults to: :sym)

    The type of link to create.

  • expand_target (true, false) (defaults to: true)

    Whether or not to make target an absolute path. This allows the creation of relative links.

Returns:

  • (Pathname)

    The path of the link.



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rub/l/util.rb', line 79

def self.link(target, name, type = :sym, expand_target: true)
	target = expand_target ? C.path(target) : target
	name   = C.path name
	
	C.generator(
		[], #target,
		['ln', '-f', (type == :sym ? '-s' : nil), target, name].compact,
		name,
		desc: 'Linking'
	)
	name
end

.uninstall(what) ⇒ void

This method returns an undefined value.

Uninstall a file.

Adds the file to the :uninstall tag.

Parameters:

  • what (Set<Pathname,String>, Array<Pathname,String>, Pathname, String)

    The files to remove.



62
63
64
65
66
67
68
# File 'lib/rub/l/util.rb', line 62

def self.uninstall(what)
	what = R::Tool.make_set_paths what
	
	what.each do |f|
		TargetUninstall.instance.add f
	end
end