Class: Gear

Inherits:
Object
  • Object
show all
Defined in:
lib/gear.rb

Constant Summary collapse

@@install_path =
"#{Dir.getwd}/vendor"
@@initialized =
false

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGear

Returns a new instance of Gear.



47
48
49
50
51
52
53
54
55
# File 'lib/gear.rb', line 47

def initialize()
  puts "Gear install path set to: #{@@install_path}"
  @obtained = @built = @installed = @checked = false
  @build_path = _root_path() + "/build/#{name()}"
  _setup_paths()
  Dir.chdir(_root_path() + "/build")

  @@initialized = true
end

Class Attribute Details

.gear_nameObject

Returns the value of attribute gear_name.



22
23
24
# File 'lib/gear.rb', line 22

def gear_name
  @gear_name
end

Instance Attribute Details

#build_pathObject (readonly)

attribute list ========#

obtained: tracking flag indicating if sources have been obtained built: tracking flag indicating if the build has been completed installed: tracking flag indicating if installation/vendorization completed checked: tracking flag indicating if an installation check succeeded headers: an array of headers to check for (in include path) libs: an array of libs to check for build_path: the path where the build will occur



12
13
14
# File 'lib/gear.rb', line 12

def build_path
  @build_path
end

#builtObject (readonly)

attribute list ========#

obtained: tracking flag indicating if sources have been obtained built: tracking flag indicating if the build has been completed installed: tracking flag indicating if installation/vendorization completed checked: tracking flag indicating if an installation check succeeded headers: an array of headers to check for (in include path) libs: an array of libs to check for build_path: the path where the build will occur



12
13
14
# File 'lib/gear.rb', line 12

def built
  @built
end

#checkedObject (readonly)

attribute list ========#

obtained: tracking flag indicating if sources have been obtained built: tracking flag indicating if the build has been completed installed: tracking flag indicating if installation/vendorization completed checked: tracking flag indicating if an installation check succeeded headers: an array of headers to check for (in include path) libs: an array of libs to check for build_path: the path where the build will occur



12
13
14
# File 'lib/gear.rb', line 12

def checked
  @checked
end

#headersObject (readonly)

attribute list ========#

obtained: tracking flag indicating if sources have been obtained built: tracking flag indicating if the build has been completed installed: tracking flag indicating if installation/vendorization completed checked: tracking flag indicating if an installation check succeeded headers: an array of headers to check for (in include path) libs: an array of libs to check for build_path: the path where the build will occur



12
13
14
# File 'lib/gear.rb', line 12

def headers
  @headers
end

#installedObject (readonly)

attribute list ========#

obtained: tracking flag indicating if sources have been obtained built: tracking flag indicating if the build has been completed installed: tracking flag indicating if installation/vendorization completed checked: tracking flag indicating if an installation check succeeded headers: an array of headers to check for (in include path) libs: an array of libs to check for build_path: the path where the build will occur



12
13
14
# File 'lib/gear.rb', line 12

def installed
  @installed
end

#libsObject (readonly)

attribute list ========#

obtained: tracking flag indicating if sources have been obtained built: tracking flag indicating if the build has been completed installed: tracking flag indicating if installation/vendorization completed checked: tracking flag indicating if an installation check succeeded headers: an array of headers to check for (in include path) libs: an array of libs to check for build_path: the path where the build will occur



12
13
14
# File 'lib/gear.rb', line 12

def libs
  @libs
end

#obtainedObject (readonly)

attribute list ========#

obtained: tracking flag indicating if sources have been obtained built: tracking flag indicating if the build has been completed installed: tracking flag indicating if installation/vendorization completed checked: tracking flag indicating if an installation check succeeded headers: an array of headers to check for (in include path) libs: an array of libs to check for build_path: the path where the build will occur



12
13
14
# File 'lib/gear.rb', line 12

def obtained
  @obtained
end

Class Method Details

.initialized?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/gear.rb', line 30

def self.initialized?
  @@initialized
end

.install_path(new_path = nil) ⇒ Object



25
26
27
28
# File 'lib/gear.rb', line 25

def self.install_path(new_path = nil)
  @@install_path = new_path unless new_path.nil?
  @@install_path
end

Instance Method Details

#buildObject



63
64
65
66
67
# File 'lib/gear.rb', line 63

def build()
  STDERR.puts "WARNING: Gear did not override build method. Nothing was built."
  @built = false
  return false
end

#checkObject



75
76
77
78
79
# File 'lib/gear.rb', line 75

def check()
  STDERR.puts "WARNING: Gear did not override check method. Status is unknown."
  @checked = false
  return false
end

#disengageObject



102
103
104
105
# File 'lib/gear.rb', line 102

def disengage()
  uninstall &&
  remove
end

#engageObject



81
82
83
84
85
86
87
# File 'lib/gear.rb', line 81

def engage()
  !check && # bail if already installed
  obtain &&
  build &&
  install &&
  check
end

#gear_exec(command = "") ⇒ Object

Prefixes a command with the gearbox prefixed in the load path



153
154
155
# File 'lib/gear.rb', line 153

def gear_exec(command = "")
  `LD_LIBRARY_PATH=#{@@install_path}/lib:$LD_LIBRARY_PATH C_INCLUDE_PATH=#{@@install_path}/include:$C_INCLUDE_PATH PATH=#{@@install_path}/bin:$PATH #{command}`
end

#gear_exec_macObject



157
158
159
# File 'lib/gear.rb', line 157

def gear_exec_mac()
  `mdfind -onlyin #{@@install_path} -name #{name} -count`.chomp.to_i
end

#git_obtain(repository, branch) ⇒ Object

obtain helpers ========#


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/gear.rb', line 108

def git_obtain(repository, branch)
  Dir.chdir(_root_path + '/build')
  begin
    if Dir.exist? build_path
      @git = Git.open(build_path)
      @git.reset("HEAD", hard: true)
      @git.clean(force: true, d: true, x:true)
    else
      @git = Git.clone(repository, build_path)
    end
  rescue StandardError => e 
    STDERR.puts "Could not obtain repository #{repository}.\n#{e}"
    @obtained = false
    return false
  end

  @git.checkout(branch)
  @git.pull

  Dir.chdir(@build_path)
  `git submodule update --init --recursive`

  @obtained = true
  return true
end

#github_obtain(user, repository, branch = 'master') ⇒ Object



134
135
136
# File 'lib/gear.rb', line 134

def github_obtain(user, repository, branch = 'master')
  git_obtain("https://github.com/#{user}/#{repository}.git", branch)
end

#installObject



69
70
71
72
73
# File 'lib/gear.rb', line 69

def install()
  STDERR.puts "WARNING: Gear did not override install method. Nothing has been installed."
  @installed = false
  return false
end

#nameObject



38
39
40
# File 'lib/gear.rb', line 38

def name()
  self.class.gear_name
end

#obtainObject



57
58
59
60
61
# File 'lib/gear.rb', line 57

def obtain()
  STDERR.puts "WARNING: Gear did not override obtain method. No sources were obtained."
  @obtained = false
  return false
end

#removeObject



89
90
91
92
93
94
# File 'lib/gear.rb', line 89

def remove()
  Dir.chdir(_root_path + '/build')
  FileUtils.rm_rf("#{@build_path}")
  @obtained = false
  return true
end

#std_config_make(flags = "") ⇒ Object



138
139
140
141
142
143
# File 'lib/gear.rb', line 138

def std_config_make(flags = "")
  Dir.chdir(@build_path)
  `autoconf` if !File.exist? 'configure'
  `./confirgure --prefix#{@@install_path}`
  `make`
end

#std_make_installObject



145
146
147
148
149
150
# File 'lib/gear.rb', line 145

def std_make_install()
  Dir.chdir(@build_path)
  `make install`
  @installed = true
  return true
end

#target(new_target = nil) ⇒ Object



42
43
44
45
# File 'lib/gear.rb', line 42

def target(new_target = nil)
  @@install_path = new_target unless new_target.nil?
  @@install_path
end

#uninstallObject



96
97
98
99
100
# File 'lib/gear.rb', line 96

def uninstall()
  # set @installed to false on a succesfully uninstall
  STDERR.puts "WARNING: Gear did not override uninstall method."
  return false
end