Class: VPL::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/vcpkg_pipeline/core/spec.rb

Overview

VPL::Spec

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Spec

Returns a new instance of Spec.

Yields:

  • (_self)

Yield Parameters:

  • _self (VPL::Spec)

    the object that the method was called on



38
39
40
# File 'lib/vcpkg_pipeline/core/spec.rb', line 38

def initialize
  yield self if block_given?
end

Instance Attribute Details

#contentObject

spec file



11
12
13
# File 'lib/vcpkg_pipeline/core/spec.rb', line 11

def content
  @content
end

#content_pathObject

spec file



11
12
13
# File 'lib/vcpkg_pipeline/core/spec.rb', line 11

def content_path
  @content_path
end

#dependenciesObject

port info



14
15
16
# File 'lib/vcpkg_pipeline/core/spec.rb', line 14

def dependencies
  @dependencies
end

#descriptionObject

port info



14
15
16
# File 'lib/vcpkg_pipeline/core/spec.rb', line 14

def description
  @description
end

#disturlObject

dist info



17
18
19
# File 'lib/vcpkg_pipeline/core/spec.rb', line 17

def disturl
  @disturl
end

#homepageObject

port info



14
15
16
# File 'lib/vcpkg_pipeline/core/spec.rb', line 14

def homepage
  @homepage
end

#nameObject

port info



14
15
16
# File 'lib/vcpkg_pipeline/core/spec.rb', line 14

def name
  @name
end

#pathObject

spec file



11
12
13
# File 'lib/vcpkg_pipeline/core/spec.rb', line 11

def path
  @path
end

#sourcesObject

dist info



17
18
19
# File 'lib/vcpkg_pipeline/core/spec.rb', line 17

def sources
  @sources
end

#userObject

port info



14
15
16
# File 'lib/vcpkg_pipeline/core/spec.rb', line 14

def user
  @user
end

#versionObject

port info



14
15
16
# File 'lib/vcpkg_pipeline/core/spec.rb', line 14

def version
  @version
end

Class Method Details

.eval_vplspec(content, content_path) ⇒ Object



19
20
21
22
23
# File 'lib/vcpkg_pipeline/core/spec.rb', line 19

def self.eval_vplspec(content, content_path)
  instance_eval(content)
rescue RescueException => e
  VPL.error("Invalid `#{content_path.basename}` file: #{e.message}")
end

.load(path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vcpkg_pipeline/core/spec.rb', line 25

def self.load(path)
  content_path_list = Dir["#{path}/*.vplspec"]
  VPL.error('未找到或存在多个 *.vplspec 文件') if content_path_list.empty? || content_path_list.count > 1
  content_path = content_path_list.first
  content = File.read(content_path)

  spec = eval_vplspec(content, content_path)
  spec.path = path
  spec.content_path = content_path
  spec.content = content
  spec
end

Instance Method Details

#distfile_nameObject



42
43
44
# File 'lib/vcpkg_pipeline/core/spec.rb', line 42

def distfile_name
  "#{name}-#{version}.zip"
end

#distfile_package(output_path = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vcpkg_pipeline/core/spec.rb', line 46

def distfile_package(output_path = nil)
  output_path ||= '.'
  distfile_path = "#{output_path}/#{distfile_name}"

  zip_sources = []
  @sources.each do |source|
    zip_sources += Dir[source]
  end
  VPL.info(zip_sources.join('\n'))
  `zip #{distfile_path} #{zip_sources.join(' ')}`

  VPL.error("Dist包 打包失败: #{distfile_path}") unless File.exist? distfile_path
  VCPkg.hash(distfile_path)
end

#to_sObject



83
84
85
86
87
88
89
90
# File 'lib/vcpkg_pipeline/core/spec.rb', line 83

def to_s
  "#{@name} (#{@version})\
  \nuser: #{@user}\
  \nhomepage: #{@homepage}\
  \ndescription: #{@description}\
  \nsources: #{@sources}\
  \ndependencies: #{@dependencies}"
end

#version_increasedObject



68
69
70
71
72
73
74
75
76
# File 'lib/vcpkg_pipeline/core/spec.rb', line 68

def version_increased
  versions = @version.split('.')

  new_version_last = (versions.last.to_i + 1).to_s
  versions.pop
  versions.push(new_version_last)

  versions.join('.')
end

#version_update(new_version = nil) ⇒ Object



78
79
80
81
# File 'lib/vcpkg_pipeline/core/spec.rb', line 78

def version_update(new_version = nil)
  new_version ||= version_increased
  write('version', new_version)
end

#write(property, value) ⇒ Object



61
62
63
64
65
66
# File 'lib/vcpkg_pipeline/core/spec.rb', line 61

def write(property, value)
  VPL.info("写入 #{File.basename(@content_path)} : #{property} = #{value}")

  new_content = @content.gsub!(/(.*.#{property}.*=.*)('.*')/, "\\1'#{value}'")
  File.write(@content_path, new_content)
end