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.



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

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

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

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

  create_dependencies
end

Instance Method Details

#activateObject



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

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

  super
end

#checkpointObject



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

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

#configure_defaultsObject



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

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

#cookObject



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

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



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

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

#create_dependenciesObject



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

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

#default_flagsObject



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

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

#generator_flagsObject



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

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

#include_pathObject



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

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

#installObject



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

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



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

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

#lib_workpathObject



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

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

#library_pathObject



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

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



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

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



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

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

#verify_libObject



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

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