Class: VCPort::Base::Portfile

Inherits:
Object
  • Object
show all
Defined in:
lib/vcpkg_pipeline/extension/vcport_vpl.rb

Overview

VCPort::Base::Portfile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Portfile

Returns a new instance of Portfile.



67
68
69
70
71
72
73
74
75
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 67

def initialize(path)
  @path = path
  @content_path = "#{path}/portfile.cmake"

  VPL.error("#{@content_path} Not Found") unless File.exist? @content_path
  @content = File.read(@content_path)

  parse_content(@content)
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



65
66
67
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 65

def content
  @content
end

#content_pathObject

Returns the value of attribute content_path.



65
66
67
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 65

def content_path
  @content_path
end

#download_distfileObject

Returns the value of attribute download_distfile.



65
66
67
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 65

def download_distfile
  @download_distfile
end

#filenameObject

Returns the value of attribute filename.



65
66
67
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 65

def filename
  @filename
end

#hashObject

Returns the value of attribute hash.



65
66
67
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 65

def hash
  @hash
end

#pathObject

Returns the value of attribute path.



65
66
67
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 65

def path
  @path
end

#urlObject

Returns the value of attribute url.



65
66
67
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 65

def url
  @url
end

Instance Method Details

#download_distfile_update(new_url, new_filename, new_hash) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 110

def download_distfile_update(new_url, new_filename, new_hash)
  new_download_distfile = @download_distfile
  new_download_distfile = new_download_distfile.sub("URLS \"#{@url}\"", "URLS \"#{new_url}\"")
  new_download_distfile = new_download_distfile.sub("FILENAME \"#{@filename}\"", "FILENAME \"#{new_filename}\"")
  new_download_distfile = new_download_distfile.sub("SHA512 #{@hash}", "SHA512 #{new_hash}")
  File.write(@content_path, @content.sub(@download_distfile, new_download_distfile))
  VPL.info("Port 下载文件信息更新: \
    \n URLS #{@url} -> #{new_url}\
    \n FILENAME #{@filename} -> #{new_filename}\
    \n SHA512 #{@hash} -> #{new_hash}\
  ")
end

#parse_content(content) ⇒ Object



77
78
79
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 77

def parse_content(content)
  content.each_line(')') { |piece| parse_download_distfile(piece) }
end

#parse_download_distfile(piece) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 81

def parse_download_distfile(piece)
  return unless piece.include? 'vcpkg_download_distfile'

  @download_distfile = piece

  clean_download_distfile = piece.clean
  parse_download_distfile_url(clean_download_distfile)
  parse_download_distfile_filename(clean_download_distfile)
  parse_download_distfile_hash(clean_download_distfile)
end

#parse_download_distfile_filename(clean_download_distfile) ⇒ Object



98
99
100
101
102
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 98

def parse_download_distfile_filename(clean_download_distfile)
  regex_filename = /FILENAME "([^ ]*)" /
  regex_filename.match(clean_download_distfile)
  @filename = Regexp.last_match(1)
end

#parse_download_distfile_hash(clean_download_distfile) ⇒ Object



104
105
106
107
108
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 104

def parse_download_distfile_hash(clean_download_distfile)
  regex_hash = /SHA512 ([^ ]*) /
  regex_hash.match(clean_download_distfile)
  @hash = Regexp.last_match(1)
end

#parse_download_distfile_url(clean_download_distfile) ⇒ Object



92
93
94
95
96
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 92

def parse_download_distfile_url(clean_download_distfile)
  regex_url = /URLS "([^ ]*)" /
  regex_url.match(clean_download_distfile)
  @url = Regexp.last_match(1)
end

#to_sObject



123
124
125
# File 'lib/vcpkg_pipeline/extension/vcport_vpl.rb', line 123

def to_s
  "#{@url} -> #{@filename}"
end