Class: Emf2svg::Recipe

Inherits:
MiniPortileCMake
  • Object
show all
Defined in:
lib/emf2svg/recipe.rb

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initializeRecipe

Returns a new instance of Recipe.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/emf2svg/recipe.rb', line 12

def initialize
  super("libemf2svg", LIBEMF2SVG_VERSION)

  @files << {
    url: "https://github.com/metanorma/libemf2svg/releases/download/v#{LIBEMF2SVG_VERSION}/libemf2svg.tar.gz",
    sha256: "c65f25040a351d18beb5172609a55d034245f85a1152d7f294780c6cc155d876", # rubocop:disable Layout/LineLength
  }

  @target = ROOT.join(@target).to_s
  @printed = {}
end

Instance Method Details

#checkpointObject



41
42
43
# File 'lib/emf2svg/recipe.rb', line 41

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

#compileObject



60
61
62
# File 'lib/emf2svg/recipe.rb', line 60

def compile
  execute("compile", "#{make_cmd} --target emf2svg")
end

#configure_defaultsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/emf2svg/recipe.rb', line 45

def configure_defaults
  opts = []

  opts << "-DCMAKE_BUILD_TYPE=Release"
  opts << "-DLONLY=ON"

  unless target_triplet.nil? || drop_target_triplet?
    opts << "-DVCPKG_TARGET_TRIPLET=#{target_triplet}"
  end

  opts << "-DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"

  opts
end

#cookObject



28
29
30
31
# File 'lib/emf2svg/recipe.rb', line 28

def cook
  super
  FileUtils.touch(checkpoint)
end

#cook_if_notObject



24
25
26
# File 'lib/emf2svg/recipe.rb', line 24

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

#drop_target_triplet?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/emf2svg/recipe.rb', line 37

def drop_target_triplet?
  windows_native? || host_platform.eql?(target_platform)
end

#execute(action, command, command_opts = {}) ⇒ Object



102
103
104
# File 'lib/emf2svg/recipe.rb', line 102

def execute(action, command, command_opts = {})
  super(action, command, command_opts.merge(debug: false))
end

#installObject



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/emf2svg/recipe.rb', line 90

def install
  libs = if MiniPortile.windows?
           Dir.glob(File.join(work_path, "Release", "*.dll"))
         else
           Dir.glob(File.join(work_path, "libemf2svg.{so,dylib}"))
             .grep(/\/(?:lib)?[a-zA-Z0-9\-]+\.(?:so|dylib)$/)
         end
  FileUtils.cp_r(libs, ROOT.join("lib", "emf2svg"), verbose: true)

  verify_libs unless target_format.eql?("skip")
end

#lb_to_verifyObject



68
69
70
71
72
73
74
75
# File 'lib/emf2svg/recipe.rb', line 68

def lb_to_verify
  pt = if MiniPortile.windows?
         "emf2svg.dll"
       else
         "libemf2svg.{so,dylib}"
       end
  @lb_to_verify ||= Dir.glob(ROOT.join("lib", "emf2svg", pt))
end

#make_cmdObject



64
65
66
# File 'lib/emf2svg/recipe.rb', line 64

def make_cmd
  "cmake --build #{File.expand_path(work_path)} --config Release"
end

#message(text) ⇒ Object



106
107
108
109
110
111
112
113
114
115
# File 'lib/emf2svg/recipe.rb', line 106

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]

  @printed[pattern] = true
  super
end

#verify_libsObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/emf2svg/recipe.rb', line 77

def verify_libs
  lb_to_verify.each do |l|
    out, st = Open3.capture2("file #{l}")
    raise "Failed to query file #{l}: #{out}" unless st.exitstatus.zero?

    if out.include?(target_format)
      message("Verifying #{l} ... OK\n")
    else
      raise "Invalid file format '#{out}', '#{@target_format}' expected"
    end
  end
end

#windows_native?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/emf2svg/recipe.rb', line 33

def windows_native?
  MiniPortile.windows? && target_triplet.eql?("x64-mingw-static")
end