Class: MiniPortile

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_portile2/version.rb,
lib/mini_portile2/mini_portile.rb

Constant Summary collapse

VERSION =
"2.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version) ⇒ MiniPortile

Returns a new instance of MiniPortile.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mini_portile2/mini_portile.rb', line 36

def initialize(name, version)
  @name = name
  @version = version
  @target = 'ports'
  @files = []
  @patch_files = []
  @log_files = {}
  @logger = STDOUT

  @original_host = @host = detect_host
end

Instance Attribute Details

#configure_optionsObject



91
92
93
# File 'lib/mini_portile2/mini_portile.rb', line 91

def configure_options
  @configure_options ||= configure_defaults
end

#filesObject

Returns the value of attribute files.



34
35
36
# File 'lib/mini_portile2/mini_portile.rb', line 34

def files
  @files
end

#hostObject

Returns the value of attribute host.



34
35
36
# File 'lib/mini_portile2/mini_portile.rb', line 34

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



34
35
36
# File 'lib/mini_portile2/mini_portile.rb', line 34

def logger
  @logger
end

#nameObject (readonly)

Returns the value of attribute name.



32
33
34
# File 'lib/mini_portile2/mini_portile.rb', line 32

def name
  @name
end

#original_hostObject (readonly)

Returns the value of attribute original_host.



32
33
34
# File 'lib/mini_portile2/mini_portile.rb', line 32

def original_host
  @original_host
end

#patch_filesObject

Returns the value of attribute patch_files.



34
35
36
# File 'lib/mini_portile2/mini_portile.rb', line 34

def patch_files
  @patch_files
end

#targetObject

Returns the value of attribute target.



34
35
36
# File 'lib/mini_portile2/mini_portile.rb', line 34

def target
  @target
end

#versionObject (readonly)

Returns the value of attribute version.



32
33
34
# File 'lib/mini_portile2/mini_portile.rb', line 32

def version
  @version
end

Instance Method Details

#activateObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/mini_portile2/mini_portile.rb', line 156

def activate
  lib_path = File.join(port_path, "lib")
  vars = {
    'PATH'          => File.join(port_path, 'bin'),
    'CPATH'         => File.join(port_path, 'include'),
    'LIBRARY_PATH'  => lib_path
  }.reject { |env, path| !File.directory?(path) }

  output "Activating #{@name} #{@version} (from #{port_path})..."
  vars.each do |var, path|
    full_path = File.expand_path(path)

    # turn into a valid Windows path (if required)
    full_path.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR

    # save current variable value
    old_value = ENV[var] || ''

    unless old_value.include?(full_path)
      ENV[var] = "#{full_path}#{File::PATH_SEPARATOR}#{old_value}"
    end
  end

  # rely on LDFLAGS when cross-compiling
  if File.exist?(lib_path) && (@host != @original_host)
    full_path = File.expand_path(lib_path)

    old_value = ENV.fetch("LDFLAGS", "")

    unless old_value.include?(full_path)
      ENV["LDFLAGS"] = "-L#{full_path} #{old_value}".strip
    end
  end
end

#apply_patch(patch_file) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mini_portile2/mini_portile.rb', line 61

def apply_patch(patch_file)
  (
    # Not a class variable because closures will capture self.
    @apply_patch ||=
    case
    when which('git')
      lambda { |file|
        message "Running git apply with #{file}... "
        # By --work-tree=. git-apply uses the current directory as
        # the project root and will not search upwards for .git.
        execute('patch', ["git", "--work-tree=.", "apply", "--whitespace=warn", file], :initial_message => false)
      }
    when which('patch')
      lambda { |file|
        message "Running patch with #{file}... "
        execute('patch', ["patch", "-p1", "-i", file], :initial_message => false)
      }
    else
      raise "Failed to complete patch task; patch(1) or git(1) is required."
    end
  ).call(patch_file)
end

#compileObject



110
111
112
# File 'lib/mini_portile2/mini_portile.rb', line 110

def compile
  execute('compile', make_cmd)
end

#configureObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/mini_portile2/mini_portile.rb', line 95

def configure
  return if configured?

  md5_file = File.join(tmp_path, 'configure.md5')
  digest   = Digest::MD5.hexdigest(computed_options.to_s)
  File.open(md5_file, "w") { |f| f.write digest }

  if RUBY_PLATFORM=~/mingw|mswin/
    # Windows doesn't recognize the shebang.
    execute('configure', %w(sh ./configure) + computed_options)
  else
    execute('configure', %w(./configure) + computed_options)
  end
end

#configured?Boolean

Returns:

  • (Boolean)


127
128
129
130
131
132
133
134
135
136
# File 'lib/mini_portile2/mini_portile.rb', line 127

def configured?
  configure = File.join(work_path, 'configure')
  makefile  = File.join(work_path, 'Makefile')
  md5_file  = File.join(tmp_path, 'configure.md5')

  stored_md5  = File.exist?(md5_file) ? File.read(md5_file) : ""
  current_md5 = Digest::MD5.hexdigest(computed_options.to_s)

  (current_md5 == stored_md5) && newer?(makefile, configure)
end

#cookObject



145
146
147
148
149
150
151
152
153
154
# File 'lib/mini_portile2/mini_portile.rb', line 145

def cook
  download unless downloaded?
  extract
  patch
  configure unless configured?
  compile
  install unless installed?

  return true
end

#downloadObject



48
49
50
51
52
53
# File 'lib/mini_portile2/mini_portile.rb', line 48

def download
  files_hashs.each do |file|
    download_file(file[:url], file[:local_path])
    verify_file(file)
  end
end

#downloaded?Boolean

Returns:

  • (Boolean)


119
120
121
122
123
124
125
# File 'lib/mini_portile2/mini_portile.rb', line 119

def downloaded?
  missing = files_hashs.detect do |file|
    !File.exist?(file[:local_path])
  end

  missing ? false : true
end

#extractObject



55
56
57
58
59
# File 'lib/mini_portile2/mini_portile.rb', line 55

def extract
  files_hashs.each do |file|
    extract_file(file[:local_path], tmp_path)
  end
end

#installObject



114
115
116
117
# File 'lib/mini_portile2/mini_portile.rb', line 114

def install
  return if installed?
  execute('install', %Q(#{make_cmd} install))
end

#installed?Boolean

Returns:

  • (Boolean)


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

def installed?
  makefile  = File.join(work_path, 'Makefile')
  target_dir = Dir.glob("#{port_path}/*").find { |d| File.directory?(d) }

  newer?(target_dir, makefile)
end

#patchObject



84
85
86
87
88
89
# File 'lib/mini_portile2/mini_portile.rb', line 84

def patch
  @patch_files.each do |full_path|
    next unless File.exist?(full_path)
    apply_patch(full_path)
  end
end

#pathObject



191
192
193
# File 'lib/mini_portile2/mini_portile.rb', line 191

def path
  File.expand_path(port_path)
end