Class: PackageConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/pkg-config.rb

Defined Under Namespace

Classes: Error, NotFoundError

Constant Summary collapse

SEPARATOR =
File::PATH_SEPARATOR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ PackageConfig

Returns a new instance of PackageConfig.



393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/pkg-config.rb', line 393

def initialize(name, options={})
  if Pathname(name).absolute?
    @pc_path = name
    @path_position = 0
    @name = File.basename(@pc_path, ".*")
  else
    @pc_path = nil
    @path_position = nil
    @name = name
  end
  @options = options
  @paths = [
    @options[:path],
    self.class.default_path,
  ].compact.join(SEPARATOR).split(SEPARATOR)
  @paths.unshift(*(@options[:paths] || []))
  @paths = normalize_paths(@paths)
  @msvc_syntax = @options[:msvc_syntax]
  @variables = @declarations = nil
  override_variables = self.class.custom_override_variables
  @override_variables = parse_override_variables(override_variables)
  default_override_variables = @options[:override_variables] || {}
  @override_variables = default_override_variables.merge(@override_variables)
end

Instance Attribute Details

#msvc_syntaxObject

Returns the value of attribute msvc_syntax.



392
393
394
# File 'lib/pkg-config.rb', line 392

def msvc_syntax
  @msvc_syntax
end

#nameObject (readonly)

Returns the value of attribute name.



390
391
392
# File 'lib/pkg-config.rb', line 390

def name
  @name
end

#pathsObject (readonly)

Returns the value of attribute paths.



391
392
393
# File 'lib/pkg-config.rb', line 391

def paths
  @paths
end

Class Method Details

.clear_configure_args_cacheObject



168
169
170
171
172
173
# File 'lib/pkg-config.rb', line 168

def clear_configure_args_cache
  @native_pkg_config = nil
  @native_pkg_config_prefix = nil
  @default_path = nil
  @custom_override_variables = nil
end

.custom_override_variablesObject



164
165
166
# File 'lib/pkg-config.rb', line 164

def custom_override_variables
  @custom_override_variables ||= with_config("override-variables", "")
end

.default_pathObject



159
160
161
# File 'lib/pkg-config.rb', line 159

def default_path
  @default_path ||= compute_default_path
end

.native_pkg_configObject



149
150
151
# File 'lib/pkg-config.rb', line 149

def native_pkg_config
  @native_pkg_config ||= guess_native_pkg_config
end

.native_pkg_config_prefixObject



154
155
156
# File 'lib/pkg-config.rb', line 154

def native_pkg_config_prefix
  @native_pkg_config_prefix ||= compute_native_pkg_config_prefix
end

Instance Method Details

#cflagsObject



438
439
440
441
# File 'lib/pkg-config.rb', line 438

def cflags
  path_flags, other_flags = collect_cflags
  (path_flags + other_flags).join(" ")
end

#cflags_only_IObject



443
444
445
# File 'lib/pkg-config.rb', line 443

def cflags_only_I
  collect_cflags[0].join(" ")
end

#cflags_only_otherObject



447
448
449
# File 'lib/pkg-config.rb', line 447

def cflags_only_other
  collect_cflags[1].join(" ")
end

#declaration(name) ⇒ Object



488
489
490
491
# File 'lib/pkg-config.rb', line 488

def declaration(name)
  parse_pc if @declarations.nil?
  expand_value(@declarations[name])
end

#descriptionObject



479
480
481
# File 'lib/pkg-config.rb', line 479

def description
  declaration("Description")
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


418
419
420
# File 'lib/pkg-config.rb', line 418

def eql?(other)
  other.is_a?(self.class) and @name == other.name
end

#exist?Boolean

Returns:

  • (Boolean)


426
427
428
# File 'lib/pkg-config.rb', line 426

def exist?
  not pc_path.nil?
end

#hashObject



422
423
424
# File 'lib/pkg-config.rb', line 422

def hash
  @name.hash
end

#libsObject



451
452
453
# File 'lib/pkg-config.rb', line 451

def libs
  collect_libs.join(" ")
end

#libs_only_lObject



455
456
457
458
459
460
461
462
463
# File 'lib/pkg-config.rb', line 455

def libs_only_l
  collect_libs.find_all do |arg|
    if @msvc_syntax
      arg.end_with?(".lib")
    else
      arg.start_with?("-l")
    end
  end.join(" ")
end

#libs_only_LObject



465
466
467
468
469
470
471
472
473
# File 'lib/pkg-config.rb', line 465

def libs_only_L
  collect_libs.find_all do |arg|
    if @msvc_syntax
      arg.start_with?("/libpath:")
    else
      arg.start_with?("-L")
    end
  end.join(" ")
end

#pc_pathObject



493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/pkg-config.rb', line 493

def pc_path
  if @pc_path
    return @pc_path if File.exist?(@pc_path)
  else
    @paths.each_with_index do |path, i|
      _pc_path = File.join(path, "#{@name}.pc")
      if File.exist?(_pc_path)
        @path_position = i + 1
        return _pc_path
      end
    end
  end
  nil
end

#requiresObject



430
431
432
# File 'lib/pkg-config.rb', line 430

def requires
  parse_requires(declaration("Requires"))
end

#requires_privateObject



434
435
436
# File 'lib/pkg-config.rb', line 434

def requires_private
  parse_requires(declaration("Requires.private"))
end

#variable(name) ⇒ Object



483
484
485
486
# File 'lib/pkg-config.rb', line 483

def variable(name)
  parse_pc if @variables.nil?
  expand_value(@override_variables[name] || @variables[name])
end

#versionObject



475
476
477
# File 'lib/pkg-config.rb', line 475

def version
  declaration("Version")
end