Class: LibarchiveBinary::LibarchiveRecipe

Inherits:
MiniPortileCMake
  • Object
show all
Defined in:
lib/ffi-libarchive-binary/libarchive_recipe.rb

Constant Summary collapse

ROOT =
Pathname.new(File.expand_path("../..", __dir__))
NAME =
"libarchive"

Instance Method Summary collapse

Constructor Details

#initializeLibarchiveRecipe

Returns a new instance of LibarchiveRecipe.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 17

def initialize
  libarchive = LibarchiveBinary.library_for(NAME)
  super(NAME, libarchive["version"])
  @printed = {}

  @files << {
    url: libarchive["url"],
    sha256: libarchive["sha256"],
  }

  @target = ROOT.join(@target).to_s

  create_dependencies
end

Instance Method Details

#activateObject



76
77
78
79
80
81
82
83
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 76

def activate
  @zlib_recipe.activate
  @expat_recipe.activate
  @openssl_recipe.activate
  @xz_recipe.activate

  super
end

#checkpointObject



107
108
109
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 107

def checkpoint
  File.join(@target, "#{name}-#{version}-#{host}.installed")
end

#configure_defaultsObject



56
57
58
59
60
61
62
63
64
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 56

def configure_defaults
  df = generator_flags + default_flags
  ar = ARCHS[host]
  if ar.nil?
    df
  else
    df + ["-DCMAKE_OSX_ARCHITECTURES=#{ar}"]
  end
end

#cookObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 89

def cook
  @zlib_recipe.host = @host if @host
  @zlib_recipe.cook_if_not

  @expat_recipe.host = @host if @host
  @expat_recipe.cook_if_not

  @openssl_recipe.host = @host if @host
  @openssl_recipe.cook_if_not

  @xz_recipe.host = @host if @host
  @xz_recipe.cook_if_not

  super

  FileUtils.touch(checkpoint)
end

#cook_if_notObject



85
86
87
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 85

def cook_if_not
  cook unless File.exist?(checkpoint)
end

#create_dependenciesObject



32
33
34
35
36
37
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 32

def create_dependencies
  @zlib_recipe = ZLibRecipe.new
  @expat_recipe = LibexpatRecipe.new
  @openssl_recipe = OpensslRecipe.new
  @xz_recipe = XZRecipe.new
end

#default_flagsObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 43

def default_flags
  [
    "-DENABLE_OPENSSL:BOOL=ON",   "-DENABLE_LIBB2:BOOL=OFF",      "-DENABLE_LZ4:BOOL=OFF",
    "-DENABLE_LZO::BOOL=OFF",     "-DENABLE_LZMA:BOOL=ON",        "-DENABLE_ZSTD:BOOL=OFF",
    "-DENABLE_ZLIB::BOOL=ON",     "-DENABLE_BZip2:BOOL=OFF",      "-DENABLE_LIBXML2:BOOL=OFF",
    "-DENABLE_EXPAT::BOOL=ON",    "-DENABLE_TAR:BOOL=OFF",        "-DENABLE_ICONV::BOOL=OFF",
    "-DENABLE_CPIO::BOOL=OFF",    "-DENABLE_CAT:BOOL=OFF",        "-DENABLE_ACL:BOOL=OFF",
    "-DENABLE_TEST:BOOL=OFF",     "-DENABLE_UNZIP:BOOL=OFF",      "-DOPENSSL_USE_STATIC_LIBS=ON",
    "-DCMAKE_INCLUDE_PATH:STRING=#{include_path}",
    "-DCMAKE_LIBRARY_PATH:STRING=#{library_path}"
  ]
end

#generator_flagsObject



39
40
41
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 39

def generator_flags
  MiniPortile::mingw? ? ["-G", "MSYS Makefiles"] : []
end

#include_pathObject



66
67
68
69
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 66

def include_path
  paths = [@zlib_recipe.path, @expat_recipe.path, @openssl_recipe.path, @xz_recipe.path]
  paths.map { |k| "#{k}/include" }.join(";")
end

#installObject



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 111

def install
  super

  libs = Dir.glob(File.join(port_path, "{lib,bin}", "*"))
    .grep(/\/(?:lib)?[a-zA-Z0-9\-]+\.(?:so|dylib|dll)$/)
  FileUtils.cp_r(libs, lib_workpath, verbose: true)
  if lib_fullpath.nil?
    message("Cannot guess libarchive library name, skipping format verification")
  else
    verify_lib
  end
end

#lib_fullpathObject



128
129
130
131
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 128

def lib_fullpath
  lib_filename = LIBNAMES[@host]
  @lib_fullpath ||= lib_filename.nil? ? nil : File.join(lib_workpath, lib_filename)
end

#lib_workpathObject



124
125
126
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 124

def lib_workpath
  @lib_workpath ||= ROOT.join("lib", "ffi-libarchive-binary")
end

#librariesObject



133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 133

def libraries
  configuration_file = File.join(File.dirname(__FILE__), "..", "..", "ext", "configuration.yml")
  @libraries ||= ::YAML.load_file(configuration_file)["libraries"] || {}
rescue Psych::SyntaxError => e
  puts "Warning: The configuration file '#{configuration_file}' contains invalid YAML syntax."
  puts e.message
  exit 1
rescue StandardError => e
  puts "An unexpected error occurred while loading the configuration file '#{configuration_file}'."
  puts e.message
  exit 1
end

#library_for(libname) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 146

def library_for(libname)
  libraries[libname][MiniPortile::windows? ? "windows" : "all"]
rescue StandardError => e
  puts "Failed to load library configuration for '#{libname}'."
  puts e.message
  exit 1
end

#library_pathObject



71
72
73
74
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 71

def library_path
  paths = [@zlib_recipe.path, @expat_recipe.path, @openssl_recipe.path, @xz_recipe.path]
  paths.map { |k| "#{k}/lib;#{k}/lib64" }.join(";")
end

#message(text) ⇒ Object



172
173
174
175
176
177
178
179
180
181
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 172

def message(text)
  return super unless text.start_with?("\rDownloading")

  match = text.match(/(\rDownloading .*)\((\s*)(\d+)%\)/)
  pattern = match ? match[1] : text
  return if @printed[pattern] && match[3].to_i != 100

  @printed[pattern] = true
  super
end

#target_formatObject



168
169
170
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 168

def target_format
  @target_format ||= FORMATS[@host].nil? ? "skip" : FORMATS[@host]
end

#verify_libObject



154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 154

def verify_lib
  begin
    out, = Open3.capture2("file #{lib_fullpath}")
  rescue StandardError
    message("failed to call file, library verification skipped.\n")
    return
  end
  unless out.include?(target_format)
    raise "Invalid file format '#{out.strip}', '#{target_format}' expected"
  end

  message("#{lib_fullpath} format has been verified (#{target_format})\n")
end