Class: Xezat::Command::Bump
- Inherits:
-
Object
- Object
- Xezat::Command::Bump
show all
- Includes:
- Xezat
- Defined in:
- lib/xezat/command/bump.rb,
lib/xezat/command/bump/file.rb,
lib/xezat/command/bump/tool.rb,
lib/xezat/command/bump/src_uri.rb,
lib/xezat/command/bump/compiler.rb,
lib/xezat/command/bump/language.rb,
lib/xezat/command/bump/changelog.rb,
lib/xezat/command/bump/cygport_dep.rb,
lib/xezat/command/bump/runtime_package.rb,
lib/xezat/command/bump/development_package.rb
Constant Summary
Constants included
from Xezat
Xezat::CONFIG_FILE, DATA_DIR, REPOSITORY_DIR, ROOT_DIR, TEMPLATE_DIR, VERSION
Instance Method Summary
collapse
-
#execute ⇒ Object
-
#get_changelog(variables, options, readme_file) ⇒ Object
-
#get_compilers(languages, _variables) ⇒ Object
-
#get_development_packages(variables, packages, runtimes, pkg2files) ⇒ Object
-
#get_embedded_contents(variables, info) ⇒ Object
-
#get_files(variables) ⇒ Object
-
#get_languages(top_src_dir) ⇒ Object
-
#get_runtime_packages(variables, pkgs, cygport) ⇒ Object
-
#get_src_uri(variables, cygclasses = CygclassManager.new) ⇒ Object
-
#get_tools(variables) ⇒ Object
-
#initialize(options, cygport) ⇒ Bump
constructor
-
#invoke_cygport_dep(variables, cygport) ⇒ Object
-
#resolve_development_package(development_packages) ⇒ Object
Methods included from Xezat
#config, #packages, #print_yaml, #variables
Constructor Details
#initialize(options, cygport) ⇒ Bump
Returns a new instance of Bump.
22
23
24
25
|
# File 'lib/xezat/command/bump.rb', line 22
def initialize(options, cygport)
@options = options
@cygport = cygport
end
|
Instance Method Details
#execute ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/xezat/command/bump.rb', line 27
def execute
Xezat.logger.debug('Start bumping')
pkgs = packages
vars = variables(@cygport)
readme_file = File.expand_path(File.join(vars[:C], 'README'))
info = {}
info[:src_uri] = get_src_uri(vars)
info[:runtimes] = get_runtime_packages(vars, pkgs, @cygport)
info[:files] = get_files(vars)
info[:developments] = get_development_packages(vars, pkgs, info[:runtimes], info[:files])
info[:changelog] = get_changelog(vars, @options, readme_file)
Xezat.logger.debug(' Write ChangeLog atomically')
File.atomic_write(readme_file) do |f|
f.write(get_embedded_contents(vars, info))
end
Xezat.logger.debug('End bumping')
end
|
#get_changelog(variables, options, readme_file) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/xezat/command/bump/changelog.rb', line 11
def get_changelog(variables, options, readme_file)
Xezat.logger.debug(' Try to append latest log to changelog...')
current_version = variables[:PVR].intern
if FileTest.exist?(readme_file)
raise FilePermissionError, "Cannot read #{readme_file}" unless FileTest.readable?(readme_file)
raise FilePermissionError, "Cannot write #{readme_file}" unless FileTest.writable?(readme_file)
changelog = Cygchangelog.new(File.read(readme_file))
message = options['message'] || 'Version bump.'
if changelog.length > 1 || !changelog.key?(current_version)
changelog[current_version] = message Xezat.logger.debug(" '#{message}' appended")
else
Xezat.logger.warn(' Initial release protected')
end
else
changelog = Cygchangelog.new
changelog[current_version] = 'Initial release by fd0 <https://github.com/fd00/>'
Xezat.logger.debug(' Initial release by you')
end
changelog
end
|
#get_compilers(languages, _variables) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/xezat/command/bump/compiler.rb', line 8
def get_compilers(languages, _variables)
Xezat.logger.debug(' Collect compilers')
compiler_file = File.expand_path(File.join(DATA_DIR, 'compilers.yaml'))
compiler_candidates = YAML.safe_load(File.open(compiler_file), symbolize_names: true, permitted_classes: [Symbol])
compilers = []
languages.uniq.each do |language|
next unless compiler_candidates.key?(language)
compiler_candidate = compiler_candidates[language]
compilers << compiler_candidate[:package].intern
next unless compiler_candidate.key?(:dependencies)
compiler_candidate[:dependencies].each do |dependency|
compilers << dependency.intern
end
end
compilers.uniq
end
|
#get_development_packages(variables, packages, runtimes, pkg2files) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/xezat/command/bump/development_package.rb', line 11
def get_development_packages(variables, packages, runtimes, pkg2files)
Xezat.logger.debug(' Collect development packages')
compilers = get_compilers(get_languages(variables[:S]), variables)
tools = get_tools(variables)
build_requires = variables[:BUILD_REQUIRES].nil? ? [] : variables[:BUILD_REQUIRES].split.map(&:to_sym)
development_packages = (compilers + tools + build_requires + [:cygport]).uniq
resolve_development_package(development_packages)
if runtimes.grep(/^libgfortran/).empty?
delete_fortran = true
pkg2files.each_value do |files|
delete_fortran = false unless files.grep(/\.mod$/).empty?
end
development_packages.delete(:'gcc-fortran') if delete_fortran
end
development_packages.sort!
development_packages.map! do |package|
pkg = packages[package]
raise "Package #{package} is not installed in your system" if pkg.nil?
pkg
end
end
|
#get_embedded_contents(variables, info) ⇒ Object
48
49
50
51
|
# File 'lib/xezat/command/bump.rb', line 48
def get_embedded_contents(variables, info)
erb = File.expand_path(File.join(TEMPLATE_DIR, 'README.erb'))
ERB.new(File.readlines(erb).join(nil), trim_mode: '%-').result(binding).chop end
|
#get_files(variables) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/xezat/command/bump/file.rb', line 11
def get_files(variables)
Xezat.logger.debug(' Collect files')
pkg2files = {}
variables[:pkg_name].each do |pkg_name|
Xezat.logger.debug(" Collect #{pkg_name}")
lst_file = File.expand_path(File.join(variables[:T], ".#{pkg_name}.lst"))
raise IllegalStateError, "No such file: #{lst_file}" unless FileTest.readable?(lst_file)
lines = File.readlines(lst_file)
lines.delete_if do |path|
path.strip!
path[-1] == File::SEPARATOR end
lines.map! do |path|
File::SEPARATOR + path
end
if variables[:PN] == pkg_name
readme = File::SEPARATOR + File.join('usr', 'share', 'doc', 'Cygwin', "#{pkg_name}.README")
lines << readme.strip unless lines.include?(readme)
end
pkg2files[pkg_name.intern] = lines.sort
end
pkg2files
end
|
#get_languages(top_src_dir) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/xezat/command/bump/language.rb', line 9
def get_languages(top_src_dir)
Xezat.logger.debug(' Collect languages')
languages_file = File.expand_path(File.join(DATA_DIR, 'languages.yaml'))
languages_candidates = YAML.safe_load(File.open(languages_file), symbolize_names: true, permitted_classes: [Symbol])
languages = []
Find.find(top_src_dir) do |path|
next if FileTest.directory?(path)
extname = File.extname(path)
next if extname == '.inc'
name = languages_candidates[extname.to_sym]
if name.nil?
language = Xezat::Linguist::FileBlob.new(path).language
next if language.nil?
name = language.name
end
languages << name.to_sym
end
languages.uniq
end
|
#get_runtime_packages(variables, pkgs, cygport) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/xezat/command/bump/runtime_package.rb', line 10
def get_runtime_packages(variables, pkgs, cygport)
Xezat.logger.debug(' Collect runtime packages from cygport dep')
result = invoke_cygport_dep(variables, cygport)
runtime_packages = result.gsub(/^.*\*\*\*.*$/, '').split($INPUT_RECORD_SEPARATOR).map(&:lstrip)
build_requires = variables[:BUILD_REQUIRES].nil? ? [] : variables[:BUILD_REQUIRES].split.map(&:to_sym)
runtime_packages.delete(pkgs[:'libssl-devel']) if build_requires.include?(:'libssl1.0-devel')
runtime_packages.map! do |pkg|
resolve_pseudo(pkg, pkgs)
end
variables[:REQUIRES]&.split&.each do |req|
runtime_packages << pkgs[req.to_sym]
end
runtime_packages.sort.uniq
end
|
#get_src_uri(variables, cygclasses = CygclassManager.new) ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/xezat/command/bump/src_uri.rb', line 9
def get_src_uri(variables, cygclasses = CygclassManager.new)
Xezat.logger.debug(' Collect SRC_URI')
cygclasses.vcs.each do |vcs|
next unless variables.key?(:"_#{vcs}_CYGCLASS_")
src_uri_key = :"#{vcs.to_s.upcase}_URI"
return variables[src_uri_key].split if variables.key?(src_uri_key)
end
variables[:SRC_URI].split
end
|
8
9
10
|
# File 'lib/xezat/command/bump/tool.rb', line 8
def get_tools(variables)
DetectorManager.new.detect(variables)
end
|
#invoke_cygport_dep(variables, cygport) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/xezat/command/bump/cygport_dep.rb', line 10
def invoke_cygport_dep(variables, cygport)
candidate_files = Find.find(variables[:D]).select do |file|
file.end_with?('.exe', '.dll', '.so')
end
additional_path = candidate_files.map do |file|
File.dirname(file)
end.sort.uniq.join(':')
Xezat.logger.debug(" Additional PATH = #{additional_path.gsub(Regexp.new(variables[:D]), '')}")
command = ['bash', File.expand_path(File.join(DATA_DIR, 'cygport_dep.sh')), cygport]
result, error, status = Open3.capture3({ 'PATH' => "#{additional_path}:#{ENV.fetch('PATH')}" }, command.join(' '))
Xezat.logger.warn(" Stderr = #{error}") unless error.empty?
raise CygportProcessError, error unless status.success?
result
end
|
#resolve_development_package(development_packages) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/xezat/command/bump/development_package.rb', line 39
def resolve_development_package(development_packages)
development_packages.delete(:'libssl-devel') if development_packages.include?(:'libssl1.0-devel')
development_packages.delete(:lua) if development_packages.include?(:'lua5.1-devel')
development_packages.delete(:lua) if development_packages.include?(:'luajit-devel')
end
|