Module: PandocBinary

Defined in:
lib/pandoc_binary/version.rb,
lib/pandoc_binary.rb,
sig/pandoc_binary.rbs

Overview

-- mode: ruby -- frozen_string_literal: true

Defined Under Namespace

Modules: RawDataParsable, TimeAttributeParsable Classes: Architecture, Release

Constant Summary collapse

PREFIX =
"pandoc"
TOP_PATH =
Pathname(__dir__).parent.expand_path
LIBEXEC_PATH =
TOP_PATH / "libexec"
ARCHITECTURES =

The top directory of an archive is named after its asset, so it differs between architectures and versions. Match it with a wildcard instead of spelling it out.

[
  Architecture.new(name: "linux-amd64", archive_suffix: "tar.gz",
                   bin_path_pattern: "*/bin/pandoc"),
  Architecture.new(name: "linux-arm64", archive_suffix: "tar.gz",
                   bin_path_pattern: "*/bin/pandoc"),
  # Pandoc splits its macOS asset into arm64 and x86_64 since 3.1.2. Keep
  # taking the x86_64 one that runs on both Intel and Apple silicon Macs, and
  # fall back to the single macOS asset of 3.1.1 and older.
  Architecture.new(name: "macOS", archive_suffix: "zip",
                   asset_patterns: %w[x86_64-macOS macOS],
                   bin_path_pattern: "*/bin/pandoc"),
  Architecture.new(name: "windows-x86_64", archive_suffix: "zip",
                   bin_path_pattern: "*/pandoc.exe", bin_suffix: "exe"),
]
NAME_TO_ARCHITECTURE =
ARCHITECTURES.map { |architecture| [architecture.name, architecture] }.to_h
VERSION =

Returns:

  • (String)
"3.11"

Class Method Summary collapse

Class Method Details

.determine_architecture(host_os: , host_cpu: ) ⇒ Object

Raises:

  • (NotImplementedError)


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/pandoc_binary.rb', line 116

def determine_architecture(host_os: RbConfig::CONFIG["host_os"], host_cpu: RbConfig::CONFIG["host_cpu"])
  case host_os
  when /linux/i
    case host_cpu
    when /amd64|x86_64|x64/i
      return NAME_TO_ARCHITECTURE["linux-amd64"]
    when /aarch64/i
      return NAME_TO_ARCHITECTURE["linux-arm64"]
    end
  when /darwin/i
    return NAME_TO_ARCHITECTURE["macOS"]
  when /mingw|mswin/i
    return NAME_TO_ARCHITECTURE["windows-x86_64"]
  end

  raise NotImplementedError, "This platform (#{host_os.inspect} #{host_cpu.inspect}) is not supported. Please send pull-request!"
end

.executable_path(architecture: determine_architecture) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/pandoc_binary.rb', line 138

def executable_path(architecture: determine_architecture)
  path = Pathname(
    ENV["PANDOC_BINARY_EXTRACTED_PATH"] ||
    LIBEXEC_PATH / "#{PREFIX}-#{architecture.name}"
  )
  path = path.sub_ext(".#{architecture.bin_suffix}") if architecture.bin_suffix
  return path if path.exist?

  gzipped_path = gzipped_executable_path(architecture: architecture)
  Zlib::GzipReader.open(gzipped_path) do |gzip|
    path.open("wb", 0o755) do |f|
      IO.copy_stream(gzip, f)
    end
  end
  return path
end

.gzipped_executable_path(architecture: determine_architecture) ⇒ Object



134
135
136
# File 'lib/pandoc_binary.rb', line 134

def gzipped_executable_path(architecture: determine_architecture)
  return LIBEXEC_PATH / "#{PREFIX}-#{architecture.name}.gz"
end