Class: Vanagon::Platform

Inherits:
Object
  • Object
show all
Includes:
HashableAttributes, Utilities
Defined in:
lib/vanagon/extensions/hashable.rb,
lib/vanagon/platform.rb,
lib/vanagon/platform/deb.rb,
lib/vanagon/platform/dsl.rb,
lib/vanagon/platform/osx.rb,
lib/vanagon/platform/rpm.rb,
lib/vanagon/platform/rpm/aix.rb,
lib/vanagon/platform/rpm/eos.rb,
lib/vanagon/platform/rpm/wrl.rb,
lib/vanagon/platform/windows.rb,
lib/vanagon/platform/rpm/sles.rb,
lib/vanagon/platform/solaris_10.rb,
lib/vanagon/platform/solaris_11.rb

Overview

Vanagon classes generally don’t implement JSON or Hash functionality so those need to be monkey-patched for useful inspection.

Direct Known Subclasses

DEB, OSX, RPM, Solaris10, Solaris11, Windows

Defined Under Namespace

Classes: DEB, DSL, OSX, RPM, Solaris10, Solaris11, Windows

Constant Summary collapse

PLATFORM_REGEX =

Platform names currently contain some information about the platform. Fields within the name are delimited by the ‘-’ character, and this regex can be used to extract those fields.

/^(.*)-(.*)-(.*)$/
VERSION_REGEX =
/^([=<>]+)\s*([^<>=]*)$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HashableAttributes

#to_hash, #to_json

Methods included from Utilities

#erb_file, #erb_string, #ex, #find_program_on_path, #get_md5sum, #get_sum, #http_request, #local_command, #remote_ssh_command, #retry_with_timeout, #rsync_from, #rsync_to, #ssh_command

Constructor Details

#initialize(name) ⇒ Vanagon::Platform

Platform constructor. Takes just the name. Also sets the @name, @os_name, @os_version and @architecture instance attributes as a side effect

Parameters:

  • name (String)

    name of the platform



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/vanagon/platform.rb', line 220

def initialize(name) # rubocop:disable Metrics/AbcSize
  @name = name
  @os_name = os_name
  @os_version = os_version
  @architecture = architecture
  @ssh_port = 22
  # Environments are like Hashes but with specific constraints
  # around their keys and values.
  @environment = Vanagon::Environment.new
  @provisioning = []
  @install ||= "install"
  @mktemp ||= "mktemp -d -p /var/tmp"
  @target_user ||= "root"
  @find ||= "find"
  @sed ||= "sed"
  @sort ||= "sort"
  @copy ||= "cp"
  @shasum ||= "sha1sum"

  # Our first attempt at defining metadata about a platform
  @cross_compiled ||= false
  @valid_operators ||= ['<', '>', '<=', '>=', '=']
end

Instance Attribute Details

#abs_resource_nameObject

Always-Be-Scheduling engine specific



110
111
112
# File 'lib/vanagon/platform.rb', line 110

def abs_resource_name
  @abs_resource_name
end

#architectureString

Sets and gets the architecture of the platform. Also has the side effect of setting the @architecture instance attribute

Returns:

  • (String)

    the architecture of the platform



305
306
307
# File 'lib/vanagon/platform.rb', line 305

def architecture
  @architecture
end

#aws_amiObject

AWS engine specific



119
120
121
# File 'lib/vanagon/platform.rb', line 119

def aws_ami
  @aws_ami
end

#aws_instance_typeObject

Returns the value of attribute aws_instance_type.



125
126
127
# File 'lib/vanagon/platform.rb', line 125

def aws_instance_type
  @aws_instance_type
end

#aws_keyObject

Returns the value of attribute aws_key.



124
125
126
# File 'lib/vanagon/platform.rb', line 124

def aws_key
  @aws_key
end

#aws_key_nameObject

Returns the value of attribute aws_key_name.



122
123
124
# File 'lib/vanagon/platform.rb', line 122

def aws_key_name
  @aws_key_name
end

#aws_regionObject

Returns the value of attribute aws_region.



123
124
125
# File 'lib/vanagon/platform.rb', line 123

def aws_region
  @aws_region
end

#aws_shutdown_behaviorObject

Returns the value of attribute aws_shutdown_behavior.



121
122
123
# File 'lib/vanagon/platform.rb', line 121

def aws_shutdown_behavior
  @aws_shutdown_behavior
end

#aws_subnet_idObject

Returns the value of attribute aws_subnet_id.



127
128
129
# File 'lib/vanagon/platform.rb', line 127

def aws_subnet_id
  @aws_subnet_id
end

#aws_user_dataObject

Returns the value of attribute aws_user_data.



120
121
122
# File 'lib/vanagon/platform.rb', line 120

def aws_user_data
  @aws_user_data
end

#aws_vpc_idObject

Returns the value of attribute aws_vpc_id.



126
127
128
# File 'lib/vanagon/platform.rb', line 126

def aws_vpc_id
  @aws_vpc_id
end

#build_dependenciesObject

Stores an Array of OpenStructs, each representing a complete command to be run to install external the needed toolchains and build dependencies for a given target platform.



71
72
73
# File 'lib/vanagon/platform.rb', line 71

def build_dependencies
  @build_dependencies
end

#build_hostsObject

Hardware engine specific



107
108
109
# File 'lib/vanagon/platform.rb', line 107

def build_hosts
  @build_hosts
end

#cflagsObject

Hold a string containing the values that a given platform should use when a Makefile is run - resolves to the CFLAGS and LDFLAGS variables. This should be changed to take advantage of the Environment, so that we can better leverage Make’s Implicit Variables.

It should also be extended to support CXXFLAGS and CPPFLAGS ASAP.



61
62
63
# File 'lib/vanagon/platform.rb', line 61

def cflags
  @cflags
end

#codenameObject

this is Debian/Ubuntu specific



23
24
25
# File 'lib/vanagon/platform.rb', line 23

def codename
  @codename
end

#copyObject

Each of these holds the path or name of the command in question, e.g. ‘copy = “/usr/local/bin/gcp”`, or `copy = “cp”`



42
43
44
# File 'lib/vanagon/platform.rb', line 42

def copy
  @copy
end

#cross_compiledObject

Determines if a platform should be treated as cross-compiled or natively compiled.



89
90
91
# File 'lib/vanagon/platform.rb', line 89

def cross_compiled
  @cross_compiled
end

#defaultdirObject

Where does a given platform’s init system expect to find something resembling ‘defaults’ files. Most likely to apply to Linux systems that use SysV-ish, upstart, or systemd init systems.



38
39
40
# File 'lib/vanagon/platform.rb', line 38

def defaultdir
  @defaultdir
end

#distString

Get the value of @dist, or derive it from the value of @os_name and @os_version. This is relatively RPM specific but ‘#codename’ is defined in Platform, and that’s just as Deb/Ubuntu specific. All of the accessors in the top-level Platform namespace should be refactored, but #dist will live here for now.

Returns:

  • (String)

    the %dist name that RPM will use to build new RPMs



281
282
283
# File 'lib/vanagon/platform.rb', line 281

def dist
  @dist ||= @os_name.tr('-', '_') + @os_version
end

#docker_imageObject

Docker engine specific



116
117
118
# File 'lib/vanagon/platform.rb', line 116

def docker_image
  @docker_image
end

#environmentObject

The overall Environment that a given platform should pass to each component



66
67
68
# File 'lib/vanagon/platform.rb', line 66

def environment
  @environment
end

#findObject

Returns the value of attribute find.



43
44
45
# File 'lib/vanagon/platform.rb', line 43

def find
  @find
end

#installObject

Returns the value of attribute install.



44
45
46
# File 'lib/vanagon/platform.rb', line 44

def install
  @install
end

#ldflagsObject

Returns the value of attribute ldflags.



62
63
64
# File 'lib/vanagon/platform.rb', line 62

def ldflags
  @ldflags
end

#makeObject

Returns the value of attribute make.



45
46
47
# File 'lib/vanagon/platform.rb', line 45

def make
  @make
end

#mktempObject

Returns the value of attribute mktemp.



46
47
48
# File 'lib/vanagon/platform.rb', line 46

def mktemp
  @mktemp
end

#nameObject

Basic generic information related to a given instance of Platform. e.g. The name we call it, the platform triplet (name-version-arch), etc.



18
19
20
# File 'lib/vanagon/platform.rb', line 18

def name
  @name
end

#num_coresObject

A string, containing the script that will be executed on the remote build target to determine how many CPU cores are available on that platform. Vanagon will use that count to determine how many build threads should be initialized for compilations.



101
102
103
# File 'lib/vanagon/platform.rb', line 101

def num_cores
  @num_cores
end

#os_nameString

Sets and gets the name of the operating system for the platform. Also has the side effect of setting the @os_name instance attribute

Returns:

  • (String)

    the operating system name as specified in the platform



289
290
291
# File 'lib/vanagon/platform.rb', line 289

def os_name
  @os_name
end

#os_versionString

Sets and gets the version of the operating system for the platform. Also has the side effect of setting the @os_version instance attribute

Returns:

  • (String)

    the operating system version as specified in the platform



297
298
299
# File 'lib/vanagon/platform.rb', line 297

def os_version
  @os_version
end

#output_dir(target_repo = "") ⇒ String

Get the output dir for packages. If the output_dir was defined already (by the platform config) then don’t change it.

Parameters:

  • target_repo (String) (defaults to: "")

    optional repo target for built packages defined at the project level

Returns:

  • (String)

    relative path to where packages should be output to



74
75
76
# File 'lib/vanagon/platform.rb', line 74

def output_dir
  @output_dir
end

#package_typeObject

The name of the sort of package type that a given platform expects, e.g. msi, rpm,



28
29
30
# File 'lib/vanagon/platform.rb', line 28

def package_type
  @package_type
end

#patchObject

Returns the value of attribute patch.



47
48
49
# File 'lib/vanagon/platform.rb', line 47

def patch
  @patch
end

#platform_tripleObject

Returns the value of attribute platform_triple.



19
20
21
# File 'lib/vanagon/platform.rb', line 19

def platform_triple
  @platform_triple
end

#provisioningObject

Stores an Array of Strings, which will be passed in as a shell script as part of the provisioning step for a given build target



85
86
87
# File 'lib/vanagon/platform.rb', line 85

def provisioning
  @provisioning
end

#rpmbuildObject

This is RedHat/EL/Fedora/SLES specific



48
49
50
# File 'lib/vanagon/platform.rb', line 48

def rpmbuild
  @rpmbuild
end

#sedObject

Returns the value of attribute sed.



49
50
51
# File 'lib/vanagon/platform.rb', line 49

def sed
  @sed
end

#servicedirObject

Where does a given platform expect to find init scripts/service files? e.g. /etc/init.d, /usr/lib/systemd/system



34
35
36
# File 'lib/vanagon/platform.rb', line 34

def servicedir
  @servicedir
end

#servicetypeObject

The name of the sort of init system that a given platform uses



31
32
33
# File 'lib/vanagon/platform.rb', line 31

def servicetype
  @servicetype
end

#settingsObject

Freeform Hash of leftover settings



130
131
132
# File 'lib/vanagon/platform.rb', line 130

def settings
  @settings
end

#shasumObject

Returns the value of attribute shasum.



52
53
54
# File 'lib/vanagon/platform.rb', line 52

def shasum
  @shasum
end

#shellObject

rubocop:disable Lint/DuplicateMethods



94
95
96
# File 'lib/vanagon/platform.rb', line 94

def shell
  @shell
end

#sortObject

Returns the value of attribute sort.



50
51
52
# File 'lib/vanagon/platform.rb', line 50

def sort
  @sort
end

#source_output_dir(target_repo = "") ⇒ String

Get the source dir for packages. Don’t change it if it was already defined by the platform config. Defaults to output_dir unless specified otherwise (RPM specifies this)

defined at the project level

Parameters:

  • target_repo (String) (defaults to: "")

    optional repo target for built source packages

Returns:

  • (String)

    relative path to where source packages should be output to



77
78
79
# File 'lib/vanagon/platform.rb', line 77

def source_output_dir
  @source_output_dir
end

#ssh_portObject

Generic engine



104
105
106
# File 'lib/vanagon/platform.rb', line 104

def ssh_port
  @ssh_port
end

#tarObject

Returns the value of attribute tar.



51
52
53
# File 'lib/vanagon/platform.rb', line 51

def tar
  @tar
end

#target_userObject

Username to use when connecting to a build target



80
81
82
# File 'lib/vanagon/platform.rb', line 80

def target_user
  @target_user
end

#valid_operatorsObject

Returns the value of attribute valid_operators.



132
133
134
# File 'lib/vanagon/platform.rb', line 132

def valid_operators
  @valid_operators
end

#vmpooler_templateObject

VMpooler engine specific



113
114
115
# File 'lib/vanagon/platform.rb', line 113

def vmpooler_template
  @vmpooler_template
end

Class Method Details

.load_platform(name, configdir) ⇒ Vanagon::Platform

Loads a given platform from the configdir

Parameters:

  • name (String)

    the name of the platform

  • configdir (String)

    the path to the platform config file

Returns:

Raises:

  • if the instance_eval on Platform fails, the exception is reraised



147
148
149
150
151
152
153
154
155
156
157
# File 'lib/vanagon/platform.rb', line 147

def self.load_platform(name, configdir)
  platfile = File.join(configdir, "#{name}.rb")
  dsl = Vanagon::Platform::DSL.new(name)
  dsl.instance_eval(File.read(platfile), platfile, 1)
  dsl._platform
rescue StandardError => e
  warn "Error loading platform '#{name}' using '#{platfile}':"
  warn e
  warn e.backtrace.join("\n")
  raise e
end

Instance Method Details

#[](key) ⇒ Object

This allows instance variables to be accessed using the hash lookup syntax



249
250
251
252
253
# File 'lib/vanagon/platform.rb', line 249

def [](key)
  if instance_variable_get("@#{key}")
    instance_variable_get("@#{key}")
  end
end

#add_build_repository(*args) ⇒ Object

Generic adder for build repositories

Parameters:

  • *args (Array<String>)

    List of arguments to pass on to the platform specific method

Raises:

  • (Vanagon::Error)

    an arror is raised if the current platform does not define add_repository



451
452
453
454
455
456
457
# File 'lib/vanagon/platform.rb', line 451

def add_build_repository(*args)
  if self.respond_to?(:add_repository)
    self.provision_with self.send(:add_repository, *args)
  else
    raise Vanagon::Error, "Adding a build repository not defined for #{name}"
  end
end

#add_group(user) ⇒ String

Generate the scripts required to add a group to the package generated. This will also update the group if it has changed.

Parameters:

Returns:

  • (String)

    the commands required to add a group to the system



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/vanagon/platform.rb', line 164

def add_group(user)
  cmd_args = ["'#{user.group}'"]
  cmd_args.unshift '--system' if user.is_system

  groupadd_args = cmd_args.join "\s"
  groupmod_args = (cmd_args - ["--system"]).join "\s"

  return <<-HERE.undent
    if getent group '#{user.group}' > /dev/null 2>&1; then
      /usr/sbin/groupmod #{groupmod_args}
    else
      /usr/sbin/groupadd #{groupadd_args}
    fi
  HERE
end

#add_user(user) ⇒ String

Generate the scripts required to add a user to the package generated. This will also update the user if it has changed.

Parameters:

Returns:

  • (String)

    the commands required to add a user to the system



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/vanagon/platform.rb', line 185

def add_user(user) # rubocop:disable Metrics/AbcSize
  cmd_args = ["'#{user.name}'"]
  cmd_args.unshift "--home '#{user.homedir}'" if user.homedir
  if user.shell
    cmd_args.unshift "--shell '#{user.shell}'"
  elsif user.is_system
    cmd_args.unshift "--shell '/usr/sbin/nologin'"
  end
  cmd_args.unshift "--gid '#{user.group}'" if user.group
  cmd_args.unshift '--system' if user.is_system

  # Collapse the cmd_args array into a string that can be used
  # as an argument to `useradd`
  useradd_args = cmd_args.join "\s"

  # Collapse the cmd_args array into a string that can be used
  # as an argument to `usermod`; If this is a system account,
  # then specify it as such for user addition only (strip
  # --system from usermod_args)
  usermod_args = (cmd_args - ["--system"]).join "\s"

  return <<-HERE.undent
    if getent passwd '#{user.name}' > /dev/null 2>&1; then
      /usr/sbin/usermod #{usermod_args}
    else
      /usr/sbin/useradd #{useradd_args}
    fi
  HERE
end

#generate_compiled_archive(project) ⇒ Object

Save the generic compiled archive and relevant metadata as packaging output. This will include a json file with all of the components/versions that were built and a bill of materials when relevant. The archive will be a gzipped tarball.

Parameters:

  • project

    The Vanagon::Project to run this on

Returns:

  • array of commands to be run



466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/vanagon/platform.rb', line 466

def generate_compiled_archive(project)
  name_and_version = "#{project.name}-#{project.version}"
  name_and_version_and_platform = "#{name_and_version}.#{name}"
  final_archive = "output/#{name_and_version_and_platform}.tar.gz"
  archive_directory = "#{project.name}-archive"
   = project.build_manifest_json(true)
  .gsub!(/\n/, '\n')
  [
    "mkdir output",
    "mkdir #{archive_directory}",
    "gunzip -c #{name_and_version}.tar.gz | '#{tar}' -C #{archive_directory} -xf -",
    "rm #{name_and_version}.tar.gz",
    "cd #{archive_directory}/#{name_and_version}; rm -f bill-of-materials; #{tar} cf ../../#{name_and_version_and_platform}.tar *",
    "gzip -9c #{name_and_version_and_platform}.tar > #{name_and_version_and_platform}.tar.gz",
    "echo -e \"#{}\" > output/#{name_and_version_and_platform}.json",
    "cp bill-of-materials output/#{name_and_version_and_platform}-bill-of-materials ||:",
    "cp #{name_and_version_and_platform}.tar.gz output",
    "#{shasum} #{final_archive} > #{final_archive}.sha1"
  ]
end

#is_aix?true, false

Utility matcher to determine is the platform is an aix variety

Returns:

  • (true, false)

    true if it is an aix variety, false otherwise



349
350
351
# File 'lib/vanagon/platform.rb', line 349

def is_aix?
  return !!@name.match(/^aix-.*$/)
end

#is_cisco_wrlinux?true, false

Utility matcher to determine is the platform is a cisco-wrlinux variety

otherwise

Returns:

  • (true, false)

    true if it is a cisco-wrlinux variety, false



372
373
374
# File 'lib/vanagon/platform.rb', line 372

def is_cisco_wrlinux?
  return !!@name.match(/^cisco-wrlinux-.*$/)
end

#is_cross_compiled?true, false

Utility matcher to determine if the platform is a cross-compiled variety

Returns:

  • (true, false)

    true if it is a cross-compiled variety, false otherwise



425
426
427
# File 'lib/vanagon/platform.rb', line 425

def is_cross_compiled?
  return @cross_compiled
end

#is_cross_compiled_linux?true, false

Utility matcher to determine if the platform is a cross-compiled Linux variety. Many of the customizations needed to cross-compile for Linux are similar, so it’s useful to group them together vs. other cross-compiled OSes.

Returns:

  • (true, false)

    true if it is a cross-compiled Linux variety, false otherwise



434
435
436
# File 'lib/vanagon/platform.rb', line 434

def is_cross_compiled_linux?
  return (is_cross_compiled? && is_linux?)
end

#is_deb?true, false

Utility matcher to determine is the platform is a debian variety

Returns:

  • (true, false)

    true if it is a debian variety, false otherwise



312
313
314
# File 'lib/vanagon/platform.rb', line 312

def is_deb?
  return !!@name.match(/^(debian|ubuntu|cumulus|huaweios)-.*$/)
end

#is_el?true, false

Utility matcher to determine is the platform is an enterprise linux variety

Returns:

  • (true, false)

    true if it is a enterprise linux variety, false otherwise



328
329
330
# File 'lib/vanagon/platform.rb', line 328

def is_el?
  return !!@name.match(/^(el|redhat)-.*$/)
end

#is_eos?true, false

Utility matcher to determine is the platform is an eos variety

Returns:

  • (true, false)

    true if it is an eos variety, false otherwise



356
357
358
# File 'lib/vanagon/platform.rb', line 356

def is_eos?
  return !!@name.match(/^eos-.*$/)
end

#is_fedora?true, false

Utility matcher to determine is the platform is a fedora variety

Returns:

  • (true, false)

    true if it is a fedora variety, false otherwise



342
343
344
# File 'lib/vanagon/platform.rb', line 342

def is_fedora?
  return !!@name.match(/^fedora-.*$/)
end

#is_huaweios?true, false

Utility matcher to determine is the platform is a HuaweiOS variety

Returns:

  • (true, false)

    true if it is a HuaweiOS variety, false otherwise



363
364
365
# File 'lib/vanagon/platform.rb', line 363

def is_huaweios?
  return !!@name.match(/^huaweios-.*$/)
end

#is_linux?true, false

Utility matcher to determine is the platform is a linux variety

Returns:

  • (true, false)

    true if it is a linux variety, false otherwise



418
419
420
# File 'lib/vanagon/platform.rb', line 418

def is_linux?
  return (!is_windows? && !is_unix?)
end

#is_macos?true, false

Utility matcher to determine if the platform is a macos or osx variety is_osx is a deprecated method that calls is_macos We still match for osx currently but this will change

Returns:

  • (true, false)

    true if it is a macos or osx variety, false otherwise



390
391
392
# File 'lib/vanagon/platform.rb', line 390

def is_macos?
  !!(@name =~ /^macos-.*$/ || @name =~ /^osx-.*$/)
end

#is_osx?true, false

Deprecated.

Please use is_macos? instead

Utility matcher to determine if the platform is an osx variety

Returns:

  • (true, false)

    true if it is an osx variety, false otherwise



380
381
382
383
# File 'lib/vanagon/platform.rb', line 380

def is_osx?
  warn "is_osx? is a deprecated method, please use #is_macos? instead."
  is_macos?
end

#is_rpm?true, false

Utility matcher to determine is the platform is a redhat variety or uses rpm under the hood

under the hood, false otherwise

Returns:

  • (true, false)

    true if it is a redhat variety or uses rpm



321
322
323
# File 'lib/vanagon/platform.rb', line 321

def is_rpm?
  return !!@name.match(/^(aix|cisco-wrlinux|el|eos|fedora|sles|redhat)-.*$/)
end

#is_sles?true, false

Utility matcher to determine is the platform is a sles variety

Returns:

  • (true, false)

    true if it is a sles variety, false otherwise



335
336
337
# File 'lib/vanagon/platform.rb', line 335

def is_sles?
  return !!@name.match(/^sles-.*$/)
end

#is_solaris?true, false

Utility matcher to determine is the platform is a solaris variety

Returns:

  • (true, false)

    true if it is an solaris variety, false otherwise



397
398
399
# File 'lib/vanagon/platform.rb', line 397

def is_solaris?
  return !!@name.match(/^solaris-.*$/)
end

#is_unix?true, false

Utility matcher to determine is the platform is a unix variety

Returns:

  • (true, false)

    true if it is a unix variety, false otherwise



404
405
406
# File 'lib/vanagon/platform.rb', line 404

def is_unix?
  return !!@name.match(/^(solaris|aix|osx)-.*$/)
end

#is_windows?true, false

Utility matcher to determine is the platform is a windows variety

Returns:

  • (true, false)

    true if it is a windows variety, false otherwise



411
412
413
# File 'lib/vanagon/platform.rb', line 411

def is_windows?
  return !!@name.match(/^windows-.*$/)
end

#package_override(project, var) ⇒ Object

Pass in a packaging override. This needs to be implemented for each individual platform so that this input ends up in the right place.

Parameters:

  • project
  • var

    the string that should be added to the build script.



443
444
445
# File 'lib/vanagon/platform.rb', line 443

def package_override(project, var)
  fail "I don't know how to set package overrides for #{name}, teach me?"
end

#provision_with(command) ⇒ Object

Set the command to turn the target machine into a builder for vanagon

Parameters:

  • command (String)

    Command to enable the target machine to build packages for the platform



490
491
492
493
# File 'lib/vanagon/platform.rb', line 490

def provision_with(command)
  provisioning << command
  provisioning.flatten!
end

#validate_operator(operator_string) ⇒ Object



516
517
518
# File 'lib/vanagon/platform.rb', line 516

def validate_operator(operator_string)
  valid_operators.include?(operator_string)
end

#version_munger(version_string, default: '=') ⇒ Object

version strings for dependencies, conflicts, replaces, etc need some munging based on platform.

Parameters:

  • version_string

    operator(<,>,=,<=,>=) and version to be munged, like ‘<1.2.3’

  • default (deprecated) (defaults to: '=')

    default operator to use if version string doesn’t contain an operator



502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/vanagon/platform.rb', line 502

def version_munger(version_string, default: '=')
  match = version_string.match(VERSION_REGEX)

  if match.nil?
    warn "Passing a version without an operator is deprecated!"
    operator = default
    version = version_string
  end
  operator ||= match[1]
  version ||= match[2]
  fail "Operator '#{operator}' is invalid" unless validate_operator(operator)
  "#{operator} #{version}"
end