xezat 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +40 -8
  3. data/.rubocop.yml +3 -1
  4. data/.ruby-version +1 -0
  5. data/lib/xezat/command/announce.rb +22 -0
  6. data/lib/xezat/command/bump/changelog.rb +8 -2
  7. data/lib/xezat/command/bump/compiler.rb +3 -3
  8. data/lib/xezat/command/bump/cygport_dep.rb +4 -4
  9. data/lib/xezat/command/bump/development_package.rb +31 -4
  10. data/lib/xezat/command/bump/file.rb +2 -2
  11. data/lib/xezat/command/bump/language.rb +3 -3
  12. data/lib/xezat/command/bump/runtime_package.rb +10 -4
  13. data/lib/xezat/command/bump/src_uri.rb +5 -5
  14. data/lib/xezat/command/bump.rb +8 -9
  15. data/lib/xezat/command/doctor.rb +0 -2
  16. data/lib/xezat/command/generate.rb +2 -1
  17. data/lib/xezat/command/init.rb +2 -2
  18. data/lib/xezat/command/port.rb +1 -1
  19. data/lib/xezat/command/validate/config.rb +40 -0
  20. data/lib/xezat/command/validate/license.rb +30 -0
  21. data/lib/xezat/command/validate/pkgconfig.rb +37 -0
  22. data/lib/xezat/command/validate.rb +92 -14
  23. data/lib/xezat/cygchangelog.rb +8 -5
  24. data/lib/xezat/cygversion.rb +8 -1
  25. data/lib/xezat/detector/asciidoc.rb +20 -0
  26. data/lib/xezat/detector/autoconf.rb +1 -1
  27. data/lib/xezat/detector/boost.m4.rb +1 -1
  28. data/lib/xezat/detector/cmake.rb +1 -4
  29. data/lib/xezat/detector/libtool.rb +2 -2
  30. data/lib/xezat/detector/make.rb +1 -1
  31. data/lib/xezat/detector/nasm.rb +16 -0
  32. data/lib/xezat/detector/ninja.rb +1 -1
  33. data/lib/xezat/detector/python27.rb +5 -5
  34. data/lib/xezat/detector/python36.rb +10 -1
  35. data/lib/xezat/detector/python37.rb +10 -1
  36. data/lib/xezat/detector/python38.rb +22 -0
  37. data/lib/xezat/detector/{python36-docutils.rb → python39-docutils.rb} +7 -2
  38. data/lib/xezat/detector/python39.rb +26 -0
  39. data/lib/xezat/detector/waf.rb +1 -1
  40. data/lib/xezat/detectors.rb +7 -5
  41. data/lib/xezat/generator/pkgconfig.rb +32 -10
  42. data/lib/xezat/main.rb +9 -1
  43. data/lib/xezat/packages.rb +1 -1
  44. data/lib/xezat/variables.rb +23 -7
  45. data/lib/xezat/version.rb +1 -1
  46. data/lib/xezat.rb +3 -3
  47. data/share/xezat/categories.yaml +51 -0
  48. data/share/xezat/compilers.yaml +44 -0
  49. data/share/xezat/{invoke_cygport_dep.sh → cygport_dep.sh} +0 -0
  50. data/share/xezat/languages.yaml +11 -0
  51. data/share/xezat/repository/bitbucket.yaml +4 -0
  52. data/share/xezat/repository/github.yaml +4 -0
  53. data/share/xezat/repository/gnu.yaml +3 -0
  54. data/share/xezat/repository/savannah.yaml +3 -0
  55. data/share/xezat/repository/sourceforge.yaml +5 -0
  56. data/share/xezat/template/announce.erb +7 -0
  57. data/share/xezat/template/cmake.erb +6 -7
  58. data/share/xezat/template/cygport.erb +4 -0
  59. data/share/xezat/{show_cygport_variable.sh → var2yaml.sh} +3 -2
  60. data/xezat.gemspec +10 -8
  61. metadata +47 -34
  62. data/share/xezat/compilers.json +0 -67
  63. data/share/xezat/languages.json +0 -12
  64. data/share/xezat/repository/bitbucket.json +0 -5
  65. data/share/xezat/repository/github.json +0 -5
  66. data/share/xezat/repository/savannah.json +0 -4
  67. data/share/xezat/repository/sourceforge.json +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ce894f06157cf37deb9e4e97f41da557c51a0a4af3b6c81caede3ee88f2f018
4
- data.tar.gz: 5dba5ffae008660e41e8f2ec9c0e8940f05e5d1b7be432d013be58b84439627d
3
+ metadata.gz: 0053db8d2a6f202e9aa40b7454f00f8ced3fdacd2c174944bec6c02a2ae106c4
4
+ data.tar.gz: 5abd0d6bd506b6a44ca306675e7b37b81d8834ff12d1165f47ad2c100ec87fcb
5
5
  SHA512:
6
- metadata.gz: 1bb76ee8cc4c1a9717f6f07403c741eb9d09e819db8f08505a34f55a04374834bf1f0b45d724b968450f9d48a3c772214305f036fe5b39400d02338fe5207ae3
7
- data.tar.gz: 4eb4b364e0e5baf15de4a9c5b486494c8efe84c4ffa71624b55a78c30cd34d224a66c9beb8ae759c7b688347d75eb9a4d5d0ad615bcbad5167551ea8326e9a64
6
+ metadata.gz: eb736dd2128a11b7b249db02e58732b54578085808f3e8d4ad36cfa74741ae2583194e3337b810d82e2a048cf9f7a893e9df1941d589e8953de270abe1799196
7
+ data.tar.gz: f8a26d86744acd8391b21c89db39afe00a880bf26b2660de5fc51d04ccae070a0e2761f650dea28c32a38cfc4b757f739b7baf4cad74aad5a480a4585e89e2dd
data/.circleci/config.yml CHANGED
@@ -1,13 +1,10 @@
1
- # Ruby CircleCI 2.0 configuration file
2
- #
3
- # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
- #
5
- version: 2
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@1.4.0
6
4
  jobs:
7
- build:
5
+ test:
8
6
  docker:
9
- # specify the version you desire here
10
- - image: circleci/ruby
7
+ - image: cimg/ruby:2.6
11
8
 
12
9
  working_directory: ~/repo
13
10
 
@@ -76,3 +73,38 @@ jobs:
76
73
  - store_artifacts:
77
74
  path: ~/repo/coverage
78
75
  destination: coverage
76
+
77
+ deploy:
78
+ docker:
79
+ - image: cimg/ruby:2.6
80
+ steps:
81
+ - checkout
82
+ - run:
83
+ name: Install native libraries
84
+ command: |
85
+ sudo apt-get install cmake libicu-dev
86
+
87
+ - run:
88
+ name: Install dependencies
89
+ command: |
90
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
91
+
92
+ - run:
93
+ name: Publish gem to Rubygems
94
+ command: bundle exec rake release
95
+
96
+ workflows:
97
+ test:
98
+ jobs:
99
+ - test:
100
+ filters:
101
+ tags:
102
+ only: /.*/
103
+ - deploy:
104
+ requires:
105
+ - test
106
+ filters:
107
+ tags:
108
+ only: /^v.*/
109
+ branches:
110
+ ignore: /.*/
data/.rubocop.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  require: rubocop-performance
2
2
 
3
3
  AllCops:
4
+ NewCops: enable
5
+ SuggestExtensions: false
4
6
  TargetRubyVersion: 2.6
5
7
  Exclude:
6
8
  - 'spec/cygport/**/*'
@@ -10,7 +12,7 @@ Layout/LineLength:
10
12
  Max: 160
11
13
 
12
14
  Metrics/AbcSize:
13
- Max: 40
15
+ Max: 45
14
16
  Metrics/BlockLength:
15
17
  Exclude:
16
18
  - '*.gemspec'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.4
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'xezat/variables'
4
+
5
+ module Xezat
6
+ module Command
7
+ class Announce
8
+ include Xezat
9
+
10
+ def initialize(options, cygport)
11
+ @options = options
12
+ @cygport = cygport
13
+ end
14
+
15
+ def execute
16
+ variables = variables(@cygport)
17
+ erb = File.expand_path(File.join(TEMPLATE_DIR, 'announce.erb'))
18
+ print ERB.new(File.readlines(erb).join(nil), trim_mode: '%-').result(binding).chop # remove redundant new line
19
+ end
20
+ end
21
+ end
22
+ end
@@ -9,7 +9,7 @@ module Xezat
9
9
  module Command
10
10
  class Bump
11
11
  def get_changelog(variables, options, readme_file)
12
- Xezat.logger.debug('Append latest log to changelog')
12
+ Xezat.logger.debug(' Try to append latest log to changelog...')
13
13
  current_version = variables[:PVR].intern
14
14
  if FileTest.exist?(readme_file)
15
15
  raise FilePermissionError, "Cannot read #{readme_file}" unless FileTest.readable?(readme_file)
@@ -17,10 +17,16 @@ module Xezat
17
17
 
18
18
  changelog = Cygchangelog.new(File.read(readme_file))
19
19
  message = options['message'] || 'Version bump.'
20
- changelog[current_version] = message unless changelog.key?(current_version)
20
+ if changelog.length > 1 || !changelog.key?(current_version)
21
+ changelog[current_version] = message # overwrite unless initial package
22
+ Xezat.logger.debug(" '#{message}' appended")
23
+ else
24
+ Xezat.logger.warn(' Initial release protected')
25
+ end
21
26
  else
22
27
  changelog = Cygchangelog.new
23
28
  changelog[current_version] = 'Initial release by fd0 <https://github.com/fd00/>'
29
+ Xezat.logger.debug(' Initial release by you')
24
30
  end
25
31
  changelog
26
32
  end
@@ -6,9 +6,9 @@ module Xezat
6
6
  module Command
7
7
  class Bump
8
8
  def get_compilers(languages, _variables)
9
- Xezat.logger.debug('Collect compilers')
10
- compiler_file = File.expand_path(File.join(DATA_DIR, 'compilers.json'))
11
- compiler_candidates = JSON.parse(File.read(compiler_file))
9
+ Xezat.logger.debug(' Collect compilers')
10
+ compiler_file = File.expand_path(File.join(DATA_DIR, 'compilers.yaml'))
11
+ compiler_candidates = YAML.safe_load(File.open(compiler_file), [Symbol])
12
12
  compilers = []
13
13
  languages.uniq.each do |language|
14
14
  next unless compiler_candidates.key?(language)
@@ -7,15 +7,15 @@ require 'xezat'
7
7
  module Xezat
8
8
  module Command
9
9
  class Bump
10
- def invoke_cygport_dep(vars, cygport)
11
- candidate_files = Find.find(vars[:D]).select do |file|
10
+ def invoke_cygport_dep(variables, cygport)
11
+ candidate_files = Find.find(variables[:D]).select do |file|
12
12
  file.end_with?('.exe', '.dll', '.so')
13
13
  end
14
14
  additional_path = candidate_files.map do |file|
15
15
  File.dirname(file)
16
16
  end.sort.uniq.join(':')
17
- command = ['bash', File.expand_path(File.join(DATA_DIR, 'invoke_cygport_dep.sh')), cygport]
18
- result, error, status = Open3.capture3({ 'PATH' => ENV['PATH'] + ':' + additional_path }, command.join(' '))
17
+ command = ['bash', File.expand_path(File.join(DATA_DIR, 'cygport_dep.sh')), cygport]
18
+ result, error, status = Open3.capture3({ 'PATH' => "#{ENV.fetch('PATH')}:#{additional_path}" }, command.join(' '))
19
19
  raise CygportProcessError, error unless status.success?
20
20
 
21
21
  result
@@ -8,15 +8,42 @@ require 'xezat/command/bump/tool'
8
8
  module Xezat
9
9
  module Command
10
10
  class Bump
11
- def get_development_packages(variables, packages)
12
- Xezat.logger.debug('Collect development packages')
11
+ def get_development_packages(variables, packages, runtimes, pkg2files)
12
+ Xezat.logger.debug(' Collect development packages')
13
13
  compilers = get_compilers(get_languages(variables[:S]), variables)
14
14
  tools = get_tools(variables)
15
- development_packages = (compilers + tools + [:cygport]).uniq.sort
15
+ build_requires = variables[:BUILD_REQUIRES].nil? ? [] : variables[:BUILD_REQUIRES].split.map(&:to_sym)
16
+ development_packages = (compilers + tools + build_requires + [:cygport]).uniq
17
+
18
+ resolve_development_package(development_packages)
19
+
20
+ # Check gcc-gfortran
21
+ if runtimes.grep(/^libgfortran/).empty?
22
+ delete_fortran = true
23
+ pkg2files.each_value do |files|
24
+ delete_fortran = false unless files.grep(/\.mod$/).empty?
25
+ end
26
+ development_packages.delete(:'gcc-fortran') if delete_fortran
27
+ end
28
+
29
+ development_packages.sort!
30
+
16
31
  development_packages.map! do |package|
17
- packages[package] || ''
32
+ pkg = packages[package]
33
+ raise "Package #{package} is not installed in your system" if pkg.nil?
34
+
35
+ pkg
18
36
  end
19
37
  end
38
+
39
+ def resolve_development_package(development_packages)
40
+ # Check libssl duplication
41
+ development_packages.delete(:'libssl-devel') if development_packages.include?(:'libssl1.0-devel')
42
+
43
+ # Check lua duplication
44
+ development_packages.delete(:lua) if development_packages.include?(:'lua5.1-devel')
45
+ development_packages.delete(:lua) if development_packages.include?(:'luajit-devel')
46
+ end
20
47
  end
21
48
  end
22
49
  end
@@ -9,10 +9,10 @@ module Xezat
9
9
  module Command
10
10
  class Bump
11
11
  def get_files(variables)
12
- Xezat.logger.debug('Collect files')
12
+ Xezat.logger.debug(' Collect files')
13
13
  pkg2files = {}
14
14
  variables[:pkg_name].each do |pkg_name|
15
- Xezat.logger.debug(" Collect #{pkg_name}")
15
+ Xezat.logger.debug(" Collect #{pkg_name}")
16
16
  lst_file = File.expand_path(File.join(variables[:T], ".#{pkg_name}.lst"))
17
17
  raise IllegalStateError, "No such file: #{lst_file}" unless FileTest.readable?(lst_file)
18
18
 
@@ -7,9 +7,9 @@ module Xezat
7
7
  module Command
8
8
  class Bump
9
9
  def get_languages(top_src_dir)
10
- Xezat.logger.debug('Collect languages')
11
- languages_file = File.expand_path(File.join(DATA_DIR, 'languages.json'))
12
- languages_candidates = JSON.parse(File.read(languages_file))
10
+ Xezat.logger.debug(' Collect languages')
11
+ languages_file = File.expand_path(File.join(DATA_DIR, 'languages.yaml'))
12
+ languages_candidates = YAML.safe_load(File.open(languages_file), [Symbol])
13
13
  languages = []
14
14
  Find.find(top_src_dir) do |path|
15
15
  next if FileTest.directory?(path)
@@ -7,10 +7,16 @@ require 'xezat/variables'
7
7
  module Xezat
8
8
  module Command
9
9
  class Bump
10
- def get_runtime_packages(vars, cygport)
11
- Xezat.logger.debug('Collect runtime packages from cygport dep')
12
- result = invoke_cygport_dep(vars, cygport)
13
- result.gsub(/^.*\*\*\*.*$/, '').split($INPUT_RECORD_SEPARATOR).map(&:lstrip)
10
+ def get_runtime_packages(variables, pkgs, cygport)
11
+ Xezat.logger.debug(' Collect runtime packages from cygport dep')
12
+ result = invoke_cygport_dep(variables, cygport)
13
+ runtime_packages = result.gsub(/^.*\*\*\*.*$/, '').split($INPUT_RECORD_SEPARATOR).map(&:lstrip)
14
+ build_requires = variables[:BUILD_REQUIRES].nil? ? [] : variables[:BUILD_REQUIRES].split.map(&:to_sym)
15
+ runtime_packages.delete(pkgs[:'libssl-devel']) if build_requires.include?(:'libssl1.0-devel')
16
+ variables[:REQUIRES]&.split&.each do |req|
17
+ runtime_packages << pkgs[req.to_sym]
18
+ end
19
+ runtime_packages.sort
14
20
  end
15
21
  end
16
22
  end
@@ -6,15 +6,15 @@ require 'xezat/cygclasses'
6
6
  module Xezat
7
7
  module Command
8
8
  class Bump
9
- def get_src_uri(vars, cygclasses = CygclassManager.new)
10
- Xezat.logger.debug('Collect SRC_URI')
9
+ def get_src_uri(variables, cygclasses = CygclassManager.new)
10
+ Xezat.logger.debug(' Collect SRC_URI')
11
11
  cygclasses.vcs.each do |vcs|
12
- next unless vars.key?("_#{vcs}_CYGCLASS_".intern)
12
+ next unless variables.key?("_#{vcs}_CYGCLASS_".intern)
13
13
 
14
14
  src_uri_key = "#{vcs.to_s.upcase}_URI".intern
15
- return vars[src_uri_key].split if vars.key?(src_uri_key)
15
+ return variables[src_uri_key].split if variables.key?(src_uri_key)
16
16
  end
17
- vars[:SRC_URI].split
17
+ variables[:SRC_URI].split
18
18
  end
19
19
  end
20
20
  end
@@ -30,15 +30,14 @@ module Xezat
30
30
  vars = variables(@cygport)
31
31
  readme_file = File.expand_path(File.join(vars[:C], 'README'))
32
32
 
33
- info = {
34
- src_uri: get_src_uri(vars),
35
- runtimes: get_runtime_packages(vars, @cygport),
36
- developments: get_development_packages(vars, pkgs),
37
- files: get_files(vars),
38
- changelog: get_changelog(vars, @options, readme_file)
39
- }
40
-
41
- Xezat.logger.debug('Write ChangeLog atomically')
33
+ info = {}
34
+ info[:src_uri] = get_src_uri(vars)
35
+ info[:runtimes] = get_runtime_packages(vars, pkgs, @cygport)
36
+ info[:files] = get_files(vars)
37
+ info[:developments] = get_development_packages(vars, pkgs, info[:runtimes], info[:files])
38
+ info[:changelog] = get_changelog(vars, @options, readme_file)
39
+
40
+ Xezat.logger.debug(' Write ChangeLog atomically')
42
41
  File.atomic_write(readme_file) do |f|
43
42
  f.write(get_embedded_contents(vars, info))
44
43
  end
@@ -7,8 +7,6 @@ module Xezat
7
7
  class Doctor
8
8
  include Xezat
9
9
 
10
- def initialize; end
11
-
12
10
  def execute
13
11
  get_contents_uniqueness.each do |path, pkg|
14
12
  puts "#{path} is not unique: #{pkg}" if pkg.length > 1
@@ -5,8 +5,9 @@ require 'thor'
5
5
  module Xezat
6
6
  module Command
7
7
  class Generate < Thor
8
- desc 'generate pkgconfig cygport', 'Generate *.pc'
8
+ desc 'pkgconfig cygport', 'Generate *.pc'
9
9
  option :overwrite, type: :boolean, aliases: '-o', desc: 'overwrite *.pc'
10
+ option :srcdir, type: :string, aliases: '-s', desc: 'relative path to Makefile.am / CMakeLists.txt'
10
11
 
11
12
  def pkgconfig(cygport)
12
13
  require 'xezat/generator/pkgconfig'
@@ -41,10 +41,10 @@ module Xezat
41
41
 
42
42
  def get_repository_variables(repository)
43
43
  if repository
44
- repository_file = File.expand_path(File.join(REPOSITORY_DIR, "#{repository}.json"))
44
+ repository_file = File.expand_path(File.join(REPOSITORY_DIR, "#{repository}.yaml"))
45
45
  raise NoSuchRepositoryError, "No such repository: #{template}" unless FileTest.exist?(repository_file) || FileTest.readable?(repository_file)
46
46
 
47
- JSON.parse(File.read(repository_file), symbolize_names: true)
47
+ YAML.safe_load(File.open(repository_file), symbolize_names: true)
48
48
  else
49
49
  {
50
50
  HOMEPAGE: '',
@@ -43,7 +43,7 @@ module Xezat
43
43
  port_dir = conf['xezat']['portdir'] || options[:portdir]
44
44
  raise NoPortDirectoryError if port_dir.nil?
45
45
 
46
- Xezat.logger.debug("Port directory: #{port_dir}")
46
+ Xezat.logger.debug(" Port directory: #{port_dir}")
47
47
  port_dir
48
48
  end
49
49
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pkg-config'
4
+ require 'xezat'
5
+
6
+ module Xezat
7
+ module Command
8
+ class Validate
9
+ def validate_config(variables, gcc_version)
10
+ configs = Dir.glob(File.join(variables[:D], '/usr/bin/*-config'))
11
+ configs.each do |config|
12
+ basename = File.basename(config)
13
+ Xezat.logger.debug(" #{basename} found")
14
+
15
+ result, _, status = Open3.capture3("#{config} --cflags")
16
+ if status.success?
17
+ Xezat.logger.debug(" cflags = #{result.strip}")
18
+ else
19
+ Xezat.logger.warn(' cflags not supported')
20
+ end
21
+
22
+ result, _, status = Open3.capture3("#{config} --cxxflags")
23
+ if status.success?
24
+ Xezat.logger.debug(" cxxflags = #{result.strip}")
25
+ else
26
+ Xezat.logger.warn(' cxxflags not supported')
27
+ end
28
+
29
+ result, _, status = Open3.capture3("#{config} --libs")
30
+ if status.success?
31
+ Xezat.logger.debug(" libs = #{result.strip}")
32
+ validate_libs(variables, result.strip, gcc_version)
33
+ else
34
+ Xezat.logger.warn(' libs not supported')
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spdx'
4
+ require 'xezat'
5
+
6
+ module Xezat
7
+ module Command
8
+ class Validate
9
+ def validate_license(vars)
10
+ license = vars[:LICENSE]
11
+ if license.nil? || license.empty?
12
+ Xezat.logger.warn(' LICENSE is not defined')
13
+ elsif Spdx.valid?(license)
14
+ Xezat.logger.debug(" LICENSE = #{license}")
15
+ else
16
+ Xezat.logger.error(" LICENSE = #{license} (invalid)")
17
+ end
18
+
19
+ license_uri = vars[:LICENSE_URI]
20
+ if license_uri.nil? || license_uri.empty?
21
+ Xezat.logger.warn(' LICENSE_URI is not defined')
22
+ elsif File.exist?(File.join(vars[:S], license_uri))
23
+ Xezat.logger.debug(" LICENSE_URI = #{license_uri}")
24
+ else
25
+ Xezat.logger.error(" LICENSE_URI = #{license_uri} (not found)")
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pkg-config'
4
+ require 'xezat'
5
+
6
+ module Xezat
7
+ module Command
8
+ class Validate
9
+ def validate_pkgconfig(variables, gcc_version)
10
+ pkgconfig_path = File.join(variables[:D], 'usr', 'lib', 'pkgconfig')
11
+ PKGConfig.add_path(pkgconfig_path)
12
+ Dir.glob('*.pc', 0, base: pkgconfig_path).each do |pc|
13
+ Xezat.logger.debug(" #{pc} found")
14
+ basename = File.basename(pc, '.pc')
15
+
16
+ modversion = PKGConfig.modversion(basename)
17
+ Xezat.logger.debug(" modversion = #{modversion}")
18
+ pv = variables[:PV][0].gsub(/\+.+$/, '')
19
+ Xezat.logger.error(" modversion differs from $PN = #{pv}") unless modversion == pv
20
+
21
+ prefix = PKGConfig.variable(basename, 'prefix')
22
+ if prefix.nil? || prefix.empty? || prefix.eql?('/usr')
23
+ Xezat.logger.debug(" prefix = #{prefix}")
24
+ else
25
+ Xezat.logger.warn(" prefix = #{prefix} (not standard)")
26
+ end
27
+
28
+ Xezat.logger.debug(" cflags = #{PKGConfig.cflags(basename)}")
29
+
30
+ libs = PKGConfig.libs(basename)
31
+ Xezat.logger.debug(" libs = #{libs}")
32
+ validate_libs(variables, libs, gcc_version)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,6 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pkg-config'
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'xezat/command/validate/config'
6
+ require 'xezat/command/validate/license'
7
+ require 'xezat/command/validate/pkgconfig'
8
+ require 'xezat/cygversion'
9
+ require 'xezat/packages'
4
10
  require 'xezat/variables'
5
11
 
6
12
  module Xezat
@@ -16,22 +22,94 @@ module Xezat
16
22
  def execute
17
23
  Xezat.logger.debug('Start validating')
18
24
  vars = variables(@cygport)
19
- validate_pkgconfig(vars)
25
+ pkgs = packages
26
+
27
+ gcc_version = Cygversion.new(pkgs[:'gcc-core'].gsub(/^gcc-core-/, '')).version.split('.')[0]
28
+
29
+ Xezat.logger.debug(' Validate .cygport')
30
+ validate_cygport(@cygport)
31
+
32
+ Xezat.logger.debug(' Validate category')
33
+ validate_category(vars[:CATEGORY])
34
+
35
+ Xezat.logger.debug(' Validate homepage')
36
+ validate_homepage(vars[:HOMEPAGE])
37
+
38
+ Xezat.logger.debug(' Validate licenses')
39
+ validate_license(vars)
40
+
41
+ Xezat.logger.debug(' Validate BUILD_REQUIRES')
42
+ validate_build_requires(vars[:BUILD_REQUIRES], pkgs)
43
+
44
+ Xezat.logger.debug(' Validate *.pc')
45
+ validate_pkgconfig(vars, gcc_version)
46
+
47
+ Xezat.logger.debug(' Validate *-config')
48
+ validate_config(vars, gcc_version)
49
+
20
50
  Xezat.logger.debug('End validating')
21
51
  end
22
52
 
23
- def validate_pkgconfig(variables)
24
- pkgconfig_path = File.join(variables[:D], 'usr', 'lib', 'pkgconfig')
25
- PKGConfig.add_path(pkgconfig_path)
26
- Dir.glob('*.pc', 0, base: pkgconfig_path).each do |pc|
27
- basename = File.basename(pc, '.pc')
28
- Xezat.logger.debug(" #{basename}.pc found")
29
- modversion = PKGConfig.modversion(basename)
30
- Xezat.logger.debug(" modversion = #{modversion}")
31
- pv = variables[:PV][0]
32
- Xezat.logger.error(" modversion differs from $PN = #{pv}") unless modversion == pv
33
- Xezat.logger.debug(" cflags = #{PKGConfig.cflags(basename)}")
34
- Xezat.logger.debug(" libs = #{PKGConfig.libs(basename)}")
53
+ def validate_cygport(cygport)
54
+ original_string = File.read(cygport)
55
+ stripped_string = original_string.gsub(/^\xEF\xBB\xBF/, '')
56
+ Xezat.logger.error(' .cygport contains BOM') unless original_string == stripped_string
57
+ end
58
+
59
+ def validate_category(category)
60
+ categories_file = File.expand_path(File.join(DATA_DIR, 'categories.yaml'))
61
+ Xezat.logger.error(" Category is invalid : #{category}") unless YAML.safe_load(File.open(categories_file), [Symbol]).include?(category.downcase)
62
+ end
63
+
64
+ def validate_homepage(homepage)
65
+ response = Net::HTTP.get_response(URI.parse(homepage))
66
+ code = response.code
67
+ if code == '200'
68
+ Xezat.logger.debug(" code = #{code}")
69
+ else
70
+ Xezat.logger.error(" code = #{code}")
71
+ end
72
+ rescue OpenSSL::SSL::SSLError => e
73
+ raise e unless @options[:ignore]
74
+
75
+ Xezat.logger.error(' Ignore SSLError')
76
+ end
77
+
78
+ def validate_build_requires(build_requires, pkgs)
79
+ return if build_requires.nil?
80
+
81
+ build_requires.split.each do |build_require|
82
+ build_require_pkg = pkgs[build_require.to_sym]
83
+ if build_require_pkg.nil?
84
+ Xezat.logger.error(" #{build_require} not found")
85
+ else
86
+ Xezat.logger.debug(" #{build_require_pkg}")
87
+ end
88
+ end
89
+ end
90
+
91
+ def validate_libs(variables, libs, gcc_version)
92
+ lib_dirs = [File.join(variables[:D], '/usr/lib'), '/usr/lib', '/usr/lib/w32api', "/usr/lib/gcc/x86_64-pc-cygwin/#{gcc_version}"]
93
+ libs.split do |option|
94
+ if option.start_with?('-l')
95
+ lib_name = option[2, 255] # Assume file length limit
96
+ found = false
97
+ lib_dirs.each do |dir|
98
+ archive_path = File.join(dir, "lib#{lib_name}.dll.a")
99
+ if File.exist?(archive_path)
100
+ Xezat.logger.debug(" #{lib_name} -> #{archive_path.gsub(variables[:D], '$D')}")
101
+ found = true
102
+ break
103
+ end
104
+ static_path = File.join(dir, "lib#{lib_name}.a")
105
+ next unless File.exist?(static_path)
106
+
107
+ Xezat.logger.debug(" #{lib_name} -> #{static_path}")
108
+ found = true
109
+ break
110
+ end
111
+ Xezat.logger.error(" #{lib_name} not found") unless found
112
+ end
35
113
  end
36
114
  end
37
115
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'English'
3
4
  require 'xezat/cygversion'
4
5
 
5
6
  module Xezat
@@ -24,7 +25,7 @@ module Xezat
24
25
  next
25
26
  end
26
27
  matched_content = /^(.+)$/.match(line)
27
- next unless matched_content
28
+ next if matched_content.nil?
28
29
  raise ReadmeSyntaxError, 'Version missing' if version.nil?
29
30
 
30
31
  if @changelogs.key?(version)
@@ -48,13 +49,15 @@ module Xezat
48
49
  @changelogs.key?(key)
49
50
  end
50
51
 
51
- def each
52
+ def each(&block)
52
53
  logs = @changelogs.sort do |a, b|
53
54
  -(Cygversion.new(a[0].to_s) <=> Cygversion.new(b[0].to_s))
54
55
  end
55
- logs.each do |k, v|
56
- yield(k, v)
57
- end
56
+ logs.each(&block)
57
+ end
58
+
59
+ def length
60
+ @changelogs.length
58
61
  end
59
62
  end
60
63
  end