Class: Xezat::Command::Validate
- Inherits:
-
Object
- Object
- Xezat::Command::Validate
show all
- Includes:
- Xezat
- Defined in:
- lib/xezat/command/validate.rb,
lib/xezat/command/validate/config.rb,
lib/xezat/command/validate/license.rb,
lib/xezat/command/validate/appstream.rb,
lib/xezat/command/validate/pkgconfig.rb
Constant Summary
collapse
- EXECUTABLE_TIMEOUT =
5
Constants included
from Xezat
Xezat::CONFIG_FILE, DATA_DIR, REPOSITORY_DIR, ROOT_DIR, TEMPLATE_DIR, VERSION
Instance Method Summary
collapse
Methods included from Xezat
#bashvar, #config, #packages, #variables
Constructor Details
#initialize(options, cygport) ⇒ Validate
Returns a new instance of Validate.
18
19
20
21
|
# File 'lib/xezat/command/validate.rb', line 18
def initialize(options, cygport)
@options = options
@cygport = cygport
end
|
Instance Method Details
#execute ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/xezat/command/validate.rb', line 23
def execute
Xezat.logger.debug('Start validating')
vars = variables(@cygport)
pkgs = packages
gcc_version = Cygversion.new(pkgs[:'gcc-core'].gsub(/^gcc-core-/, '')).version.split('.')[0]
Xezat.logger.debug(' Validate .cygport')
validate_cygport(@cygport)
Xezat.logger.debug(' Validate category')
validate_category(vars[:CATEGORY])
Xezat.logger.debug(' Validate homepage')
validate_homepage(vars[:HOMEPAGE])
Xezat.logger.debug(' Validate licenses')
validate_license(vars)
Xezat.logger.debug(' Validate BUILD_REQUIRES')
validate_build_requires(vars[:BUILD_REQUIRES], pkgs)
Xezat.logger.debug(' Validate *.pc')
validate_pkgconfig(vars, gcc_version)
Xezat.logger.debug(' Validate *-config')
validate_config(vars, gcc_version)
Xezat.logger.debug(' Validate AppStream path')
validate_appstream_path(vars)
Xezat.logger.debug('End validating')
end
|
#validate_appstream_path(variables) ⇒ Object
8
9
10
11
12
13
|
# File 'lib/xezat/command/validate/appstream.rb', line 8
def validate_appstream_path(variables)
legacy_dir = File.join(variables[:D], '/usr/share/appdata')
Dir.glob('*', base: legacy_dir).each do |file|
Xezat.logger.error(" #{file} is in the legacy AppStream path /usr/share/appdata, move it to /usr/share/metainfo")
end
end
|
#validate_build_requires(build_requires, pkgs) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/xezat/command/validate.rb', line 76
def validate_build_requires(build_requires, pkgs)
return if build_requires.nil?
build_requires.split.each do |build_require|
build_require_pkg = pkgs[build_require.to_sym]
if build_require_pkg.nil?
Xezat.logger.error(" #{build_require} not found")
else
Xezat.logger.debug(" #{build_require_pkg}")
end
end
end
|
#validate_category(category) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/xezat/command/validate.rb', line 63
def validate_category(category)
categories_file = File.expand_path(File.join(DATA_DIR, 'categories.yaml'))
valid_categories = YAML.safe_load(File.open(categories_file), symbolize_names: true, permitted_classes: [Symbol])
category.split.each do |cat|
Xezat.logger.error(" Category is invalid : #{cat}") unless valid_categories.include?(cat.downcase)
end
end
|
#validate_config(variables, gcc_version) ⇒ 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/validate/config.rb', line 9
def validate_config(variables, gcc_version)
Dir.glob(File.join(variables[:D], '/usr/bin/*-config')).each do |config|
Xezat.logger.debug(" #{File.basename(config)} found")
begin
executable?(config)
rescue StandardError
next
end
validate_modversion(config, variables)
validate_cflags(config)
validate_cxxflags(config)
result, _, status = Open3.capture3("#{config} --libs")
if status.success?
Xezat.logger.debug(" libs = #{result.strip}")
validate_libs(variables, result.strip, gcc_version)
else
Xezat.logger.warn(' libs not supported')
end
end
end
|
#validate_cygport(cygport) ⇒ Object
57
58
59
60
61
|
# File 'lib/xezat/command/validate.rb', line 57
def validate_cygport(cygport)
original_string = File.read(cygport)
stripped_string = original_string.gsub(/^\xEF\xBB\xBF/, '')
Xezat.logger.error(' .cygport contains BOM') unless original_string == stripped_string
end
|
#validate_homepage(homepage) ⇒ Object
71
72
73
74
|
# File 'lib/xezat/command/validate.rb', line 71
def validate_homepage(homepage)
Xezat.logger.debug(" HOMEPAGE = #{homepage}")
livecheck(homepage)
end
|
#validate_libs(variables, libs, gcc_version) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/xezat/command/validate.rb', line 89
def validate_libs(variables, libs, gcc_version)
lib_dirs = [File.join(variables[:D], '/usr/lib'), '/usr/lib', '/usr/lib/w32api', "/usr/lib/gcc/x86_64-pc-cygwin/#{gcc_version}"]
libs.split do |option|
if option.start_with?('-l')
lib_name = option[2, 255] found = false
lib_dirs.each do |dir|
archive_path = File.join(dir, "lib#{lib_name}.dll.a")
if File.exist?(archive_path)
Xezat.logger.debug(" #{lib_name} -> #{archive_path.gsub(variables[:D], '$D')}")
found = true
break
end
static_path = File.join(dir, "lib#{lib_name}.a")
next unless File.exist?(static_path)
Xezat.logger.debug(" #{lib_name} -> #{static_path}")
found = true
break
end
Xezat.logger.error(" #{lib_name} not found") unless found
end
end
end
|
#validate_license(vars) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/xezat/command/validate/license.rb', line 9
def validate_license(vars)
license = vars[:LICENSE]
if license.nil? || license.empty?
Xezat.logger.warn(' LICENSE is not defined')
elsif Spdx.valid?(license)
Xezat.logger.debug(" LICENSE = #{license}")
else
Xezat.logger.error(" LICENSE = #{license} (invalid)")
end
license_uri = vars[:LICENSE_URI]
if license_uri.nil? || license_uri.empty?
Xezat.logger.warn(' LICENSE_URI is not defined')
elsif license_uri.start_with?('https://', 'http://')
Xezat.logger.debug(" LICENSE_URI = #{license_uri}")
livecheck(license_uri)
elsif File.exist?(File.join(vars[:S], license_uri))
Xezat.logger.debug(" LICENSE_URI = #{license_uri}")
else
Xezat.logger.error(" LICENSE_URI = #{license_uri} (not found)")
end
end
|
#validate_pkgconfig(variables, gcc_version) ⇒ Object
9
10
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/validate/pkgconfig.rb', line 9
def validate_pkgconfig(variables, gcc_version)
pkgconfig_path = File.join(variables[:D], 'usr', 'lib', 'pkgconfig')
PKGConfig.add_path(pkgconfig_path)
Dir.glob('*.pc', 0, base: pkgconfig_path).each do |pc|
Xezat.logger.debug(" #{pc} found")
basename = File.basename(pc, '.pc')
modversion = PKGConfig.modversion(basename)
Xezat.logger.debug(" modversion = #{modversion}")
pv = variables[:PV][0].gsub(/\+.+$/, '')
Xezat.logger.error(" modversion differs from $PN = #{pv}") unless modversion == pv
prefix = PKGConfig.variable(basename, 'prefix')
if prefix.nil? || prefix.empty? || prefix.eql?('/usr')
Xezat.logger.debug(" prefix = #{prefix}")
else
Xezat.logger.warn(" prefix = #{prefix} (not standard)")
end
Xezat.logger.debug(" cflags = #{PKGConfig.cflags(basename)}")
libs = PKGConfig.libs(basename)
Xezat.logger.debug(" libs = #{libs}")
validate_libs(variables, libs, gcc_version)
end
end
|