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__))

Instance Method Summary collapse

Constructor Details

#initializeLibarchiveRecipe

Returns a new instance of LibarchiveRecipe.



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

def initialize
  super("libarchive", "3.6.1")
  @printed = {}

  @files << {
    url: "https://www.libarchive.org/downloads/libarchive-3.6.1.tar.gz",
    sha256: "c676146577d989189940f1959d9e3980d28513d74eedfbc6b7f15ea45fe54ee2",
  }

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

  create_dependencies
end

Instance Method Details

#activateObject



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

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

  super
end

#checkpointObject



105
106
107
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 105

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

#configure_defaultsObject



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

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

#cookObject



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

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



83
84
85
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 83

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

#create_dependenciesObject



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

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

#default_flagsObject



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

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",
    "-DCMAKE_INCLUDE_PATH=#{include_path}",
    "-DCMAKE_LIBRARY_PATH=#{library_path}"
  ]
end

#generator_flagsObject



37
38
39
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 37

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

#include_pathObject



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

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

#installObject



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

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



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

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

#lib_workpathObject



122
123
124
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 122

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

#library_pathObject



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

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

#message(text) ⇒ Object



149
150
151
152
153
154
155
156
157
158
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 149

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



145
146
147
# File 'lib/ffi-libarchive-binary/libarchive_recipe.rb', line 145

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

#verify_libObject



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

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