baltix 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +44 -0
  3. data/.gitignore +10 -0
  4. data/Gemfile +8 -0
  5. data/LICENSE +8 -0
  6. data/README.md +60 -0
  7. data/Rakefile +8 -0
  8. data/TODO +84 -0
  9. data/baltix.gemspec +39 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/exe/baltix +4 -0
  13. data/lib/baltix/actor/copy.rb +19 -0
  14. data/lib/baltix/actor/link.rb +20 -0
  15. data/lib/baltix/actor/spec.rb +25 -0
  16. data/lib/baltix/actor/touch.rb +17 -0
  17. data/lib/baltix/actor.rb +75 -0
  18. data/lib/baltix/cli.rb +173 -0
  19. data/lib/baltix/deps.rb +280 -0
  20. data/lib/baltix/dsl.rb +311 -0
  21. data/lib/baltix/extensions.rb +536 -0
  22. data/lib/baltix/i18n.rb +64 -0
  23. data/lib/baltix/loader/cmake.rb +11 -0
  24. data/lib/baltix/loader/git-version-gen.rb +36 -0
  25. data/lib/baltix/loader/mast.rb +139 -0
  26. data/lib/baltix/loader/pom.rb +27 -0
  27. data/lib/baltix/loader/rookbook.rb +26 -0
  28. data/lib/baltix/loader/yaml.rb +18 -0
  29. data/lib/baltix/loader.rb +192 -0
  30. data/lib/baltix/log.rb +73 -0
  31. data/lib/baltix/rake.rb +57 -0
  32. data/lib/baltix/scheme.erb.yaml +20 -0
  33. data/lib/baltix/source/base.rb +438 -0
  34. data/lib/baltix/source/fake.rb +17 -0
  35. data/lib/baltix/source/gem.rb +407 -0
  36. data/lib/baltix/source/gemfile.rb +35 -0
  37. data/lib/baltix/source/rakefile.rb +24 -0
  38. data/lib/baltix/source.rb +57 -0
  39. data/lib/baltix/space/spec.rb +11 -0
  40. data/lib/baltix/space.rb +424 -0
  41. data/lib/baltix/spec/rpm/name.rb +155 -0
  42. data/lib/baltix/spec/rpm/parser.rb +412 -0
  43. data/lib/baltix/spec/rpm/secondary.rb +170 -0
  44. data/lib/baltix/spec/rpm/spec_core.rb +580 -0
  45. data/lib/baltix/spec/rpm.erb +188 -0
  46. data/lib/baltix/spec/rpm.rb +822 -0
  47. data/lib/baltix/spec.rb +48 -0
  48. data/lib/baltix/version.rb +3 -0
  49. data/lib/baltix.rb +19 -0
  50. data/locale/en_US.UTF-8.yaml +27 -0
  51. data/locale/ru_RU.UTF-8.yaml +23 -0
  52. metadata +216 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1d93503758dc39c82066dfbe05b1914e3de3aa0fbfaac19d8e46e71cea566103
4
+ data.tar.gz: f130603732a880d17a968ecc2b71d4bf5acf91bb98746ad0cc926e157eb05c6d
5
+ SHA512:
6
+ metadata.gz: d950f8bdea1db9d9939111d2f6ca7a4c9d0c7386433abd932c3ddb42d75698aa495cf9b839c01dfb9998004818bfcccdd0060df0748fd7d062fe6a61d2ef8401
7
+ data.tar.gz: '082e0b93a9dac99b4cd92248191132e9b64cd8a26d1e6e4881d6d48381a3114a675370b8c322ace31d5f29f380034e742547629c20640c4f8bd380d241055a80'
@@ -0,0 +1,44 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Rubygem CI
9
+
10
+ on:
11
+ push:
12
+ branches: [ "master" ]
13
+ pull_request:
14
+ branches: [ "master" ]
15
+
16
+ env:
17
+ CODACY_PROJECT_TOKEN: "a1d8e09e34cc43c68cade0c196463c57"
18
+ COVERAGE: true
19
+
20
+ permissions:
21
+ contents: read
22
+
23
+ jobs:
24
+ test:
25
+
26
+ runs-on: ubuntu-latest
27
+ strategy:
28
+ matrix:
29
+ ruby-version: ['3.0', '3.1']
30
+
31
+ steps:
32
+ - uses: actions/checkout@v3
33
+ - name: Set up Ruby
34
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
35
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
36
+ # uses: ruby/setup-ruby@v1
37
+ uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
38
+ with:
39
+ ruby-version: ${{ matrix.ruby-version }}
40
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
41
+ - name: Run tests
42
+ run: bundle exec rake
43
+ - name: Update Codaci Coveralls
44
+ run: bash <(curl -Ls https://coverage.codacy.com/get.sh)
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in baltix.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem 'simplecov', require: false, group: :test
8
+ gem 'simplecov-lcov', require: false, group: :test
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2023 Pavel «Malỷ» Skrylev
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Baltix
2
+
3
+ Dependency detector, and spec generator and reader for projects based on the Ruby.
4
+
5
+ ## Status
6
+
7
+ [![GitHub](http://img.shields.io/badge/github-majioa/baltix-blue.svg)](http://github.com/majioa/baltix)
8
+ [![GitHub tag](https://img.shields.io/github/tag/majioa/baltix.svg)](https://github.com/majioa/baltix/tags/)
9
+ [![Open Source? Yes!](https://badgen.net/badge/Open%20Source%20%3F/Yes%21/blue?icon=github)](https://github.com/majioa/baltix)
10
+ [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
11
+ [![Ruby Github Action](https://github.com/majioa/baltix/actions/workflows/ci.yml/badge.svg)](https://github.com/majioa/baltix/actions/workflows/ci.yml)
12
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/4d99e63d3d7349d5adfdbc4250666ef2)](https://app.codacy.com/gh/majioa/baltix/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
13
+ [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/4d99e63d3d7349d5adfdbc4250666ef2)](https://app.codacy.com/gh/majioa/baltix/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
14
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/majioa/baltix/pulls)
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'baltix', github: "majioa/baltix"
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle install
27
+
28
+ ## Usage
29
+
30
+ ### From a Command Line
31
+
32
+ When you are creating a spec for the space from a scratch sample call may be as follows:
33
+
34
+ $ sudo /usr/bin/setup.rb -o $(echo $(pwd)|sed "s|.*/||").spec --maintainer-name="Pavel Skrylev" --maintainer-email="majioa@altlinux.org" -g/home/majioa/available-list.yaml spec --debug-io=- --verbose=debug --ignore-path-tokens=templates,example,examples,sample,samples,spec,test,features,fixtures,doc,docs,contrib,demo,acceptance,conformance,myapp,website,benchmarks,benchmark,gemfiles,misc,steep 2>/dev/null; sudo chown majioa:majioa . -R
35
+
36
+ When you are updating the spec do something like:
37
+
38
+ $ sudo /usr/bin/setup.rb -s $(find -name "*.spec~") -o _.spec --maintainer-name="Pavel Skrylev" --maintainer-email="majioa@altlinux.org" -g/home/majioa/available-list.yaml spec --debug-io=- --verbose=debug --ignore-path-tokens=templates,example,examples,sample,samples,spec,test,features,fixtures,doc,docs,contrib,demo,acceptance,conformance,myapp,website,benchmarks,benchmark,gemfiles,misc,steep 2>/dev/null; sudo chown majioa:majioa . -R
39
+
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Test
48
+
49
+ To run tests written in Cucumber's Gherkin just run:
50
+
51
+ $ cucumber
52
+
53
+ or you are able to run them with rake as a default task:
54
+
55
+ $ bundle exec rake
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/majioa/baltix.
60
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'cucumber/rake/task'
3
+
4
+ Cucumber::Rake::Task.new do |t|
5
+ t.cucumber_opts = %w{--format progress}
6
+ end
7
+
8
+ task :default => :cucumber
data/TODO ADDED
@@ -0,0 +1,84 @@
1
+ -----
2
+ fix:
3
+ lost runtime deps
4
+ ---
5
+ - add disable source (for ruby-rubygems-update)
6
+ - add return to common space on load (for ruby-rails)
7
+ - add doc compilation only over included lib files
8
+ - validate provides/requires detection speed on gem-google-api-client , azure-sdk
9
+
10
+
11
+ - spec
12
+ wrongdoc/olddoc - kgio
13
+ hoe - hoe/racc
14
+ bones - loquacious/bones
15
+
16
+ - validate spec for gem rdoc (rdoc/ri) - muliple executables
17
+
18
+ + generate spec for:
19
+ - gem:multi_test,parser 2x -> 3x
20
+ - app:cucumber_common - blank root (Fake Source) / Url, Vsc, summary, description, filters for blank packages, dedup packages by name
21
+
22
+
23
+ - rubyzip old -> new
24
+ - check rubocop *.h adding in devel pkg, bo they are absent
25
+ - coveralls with %ruby_use_gem_dependency, 0.8.23-alt2 -> 0.8.23.1-alt0.1 (увеличение версии с помоїью командной строки или анализа git),and Epoch =1
26
+ - google-cloud-ruby - deduplication of build req list for gems: simplecov
27
+ - photobuf - noarch with so packages
28
+ - grpc - custom root - grpc, and not gem-grpc
29
+ - googleauth - alias to google-auth
30
+ - google-api-ruby-client: correct spec, filter by regexp to ignore-names, validate build
31
+ - digest-crc - developmnt gems from Gemfile, valid loading the Gemfile with fixed deps
32
+ - gapic-generator-ruby
33
+ - filterout README.erb, alow pure, or .md/rdoc/.../
34
+ - add README with offset paths to the root source
35
+ - chef 15->17
36
+ + uniq name for spe %doc: README.md can't be multiple
37
+ + generate relative symlinks instead of absolute for execs
38
+ + filter out desc and summary char to other like "’" -> "'"
39
+ + filter out names with path "test/spec/feature/fixture/sandbox": example "turn" gem
40
+ + ignore by part: example: update-rubygems[doc,lib] to ignore when detecting and processing
41
+
42
+ gem-ascii85 - capital name
43
+
44
+ gem-lemon update stable ver to unstable
45
+ gem-compass - multi gem deps in build requiers (sass), embedded gem = instead of >=, markdown extension for readme, false absent README.md generated in spec
46
+ license-scout - README lost
47
+
48
+ gettext-setup - invalid ruby_alias_names when genspec
49
+ async-rspec - blank description
50
+ gem-treetop - break epoch
51
+ gem-nokogiri - crop changelog, fix gem deps on the file (example for mini_portile2, see patch)
52
+ prometheus-client - invalid dep tags when is in available list
53
+ ruby-rc4 - ruby isnt prefix, leads to ruby-ruby-rc4
54
+ facets - new spec invalid type dependencies runtime instead devel
55
+ ffi - 1. git describe --tags command to fix in gemspec; 2. update to 1.15.5 add the wrnog tag
56
+ passenger - minon require list check, because when rebuild spec it losts some things
57
+ digest-crc - lost rake task on update to 0.6.4
58
+ io-event - erroneous update form event
59
+ idn-ruby - can't detect extension
60
+ net-http-persistent - invalid update to 4.0.1
61
+ hoe-bunder - crop long patch number for v.5.0
62
+ oj - expand and crop summary when update to 3.13.11
63
+ hoe-travis - lost description on update
64
+ ruby-shadow - lost license on update unlicense replace with specified default + license replace list args
65
+ unf_ext - invalid dep ruby_use_gem_dependency
66
+ rdoc - update to new version break generate a valid new spec if the gem in available gem list adding unnecesary tag
67
+ hiredis - invalid ruby_use_gem_dependency when generated updated spec
68
+
69
+ glu,glut,kpeg - development deps, merge them correct
70
+ data-objects - main source valid detection
71
+
72
+ fix build dep for ruby-gnome2 -> gem-cairo-devel -> gem-poppler(ruby-gnome2)
73
+
74
+ ?raindrops
75
+ ?capybara ^ -> 3.37.1
76
+
77
+ vcs_url for snaky_hash gem
78
+
79
+ определение жемов для руби и жемов в ruby_version напрмер
80
+ [setup.rb][INFO]> X *RubyGems:3.3.7 [./Rakefile]
81
+ [setup.rb][INFO]> X *Ruby:3.1.1.18 [./Rakefile]
82
+
83
+
84
+ структура дерева mustermann и обьединение жемов из подпроектов, если они одноимённые:), а также определение группы в Gemfile
data/baltix.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ require_relative 'lib/baltix/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "baltix"
5
+ spec.version = Baltix::VERSION
6
+ spec.authors = ["Pavel Skrylev"]
7
+ spec.email = ["majioa@altlinux.org"]
8
+ spec.licenses = ["MIT"]
9
+
10
+ spec.summary = %q{Baltix is setup replacement and spec control utility for RPM/local packages}
11
+ spec.description = %q{Baltix is setup replacement and spec control utility for RPM/local packages}
12
+ spec.homepage = "https://github.org/majioa/baltix"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.org/majioa/baltix"
19
+ spec.metadata["changelog_uri"] = "https://github.org/majioa/baltix/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.required_ruby_version = [ '>= 3.0.0' ]
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", ">= 12.0"
33
+ spec.add_development_dependency "pry", "~> 0.13"
34
+ spec.add_development_dependency "cucumber", "~> 5.2"
35
+ spec.add_development_dependency "shoulda-matchers-cucumber", "~> 1.0", ">= 1.0.1"
36
+ spec.add_development_dependency "timecop"
37
+ spec.add_development_dependency "simplecov"
38
+ spec.add_development_dependency "simplecov-lcov"
39
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "baltix"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/baltix ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'baltix/cli'
4
+ Baltix::CLI.new.run
@@ -0,0 +1,19 @@
1
+ module Baltix::Actor::Copy
2
+ class NoDestinationDirError < StandardError ;end
3
+ class NoSourceDirError < StandardError ;end
4
+ class NoFileError < StandardError ;end
5
+
6
+ class << self
7
+ def apply context
8
+ target_dir = context['target_dir'] || raise(NoDestinationDirError)
9
+ source_dir = context['source_dir'] || raise(NoSourceDirError)
10
+ file = context['file'] || raise(NoFileError)
11
+
12
+ target_file = File.join(context['target_prefix'] || '', target_dir, file)
13
+ source_file = File.join(source_dir, file)
14
+ FileUtils.mkdir_p(File.dirname(target_file))
15
+ FileUtils.cp(source_file, target_file)
16
+ $stdout.puts " #{source_file} => #{target_file}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module Baltix::Actor::Link
2
+ class NoDestinationDirError < StandardError ;end
3
+ class NoSourceDirError < StandardError ;end
4
+ class NoFileError < StandardError ;end
5
+
6
+ class << self
7
+ def apply context
8
+ target_dir = context['target_dir'] || raise(NoDestinationDirError)
9
+ source_dir = context['source_dir'] || raise(NoSourceDirError)
10
+ file = context['file'] || raise(NoFileError)
11
+
12
+ target_file = File.join(context['target_prefix'] || '', target_dir, file)
13
+ source_file = File.join(source_dir, file)
14
+ FileUtils.mkdir_p(File.dirname(target_file))
15
+ FileUtils.rm_rf(target_file)
16
+ FileUtils.ln_s(source_file, target_file, force: true)
17
+ $stdout.puts " #{source_file} -> #{target_file}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ # vim: noai:ts=3:sts=3:et:sw=3
2
+ # Actor spec
3
+ require 'baltix/spec'
4
+
5
+ module Baltix::Actor::Spec
6
+ class << self
7
+ def context_kind
8
+ Baltix::Space
9
+ end
10
+
11
+ # +apply_to+ generates spec according to the provided setup
12
+ #
13
+ def apply_to space, template = nil
14
+ spec = Baltix::Spec.find(space.spec_type)
15
+
16
+ rendered = spec.render(space, template)
17
+
18
+ if space.options.output_file
19
+ File.open(space.options.output_file, "w") { |f| f.puts(rendered) }
20
+ end
21
+
22
+ rendered
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module Baltix::Actor::Touch
2
+ class NoDestinationDirError < StandardError ;end
3
+ class NoSourceDirError < StandardError ;end
4
+ class NoFileError < StandardError ;end
5
+
6
+ class << self
7
+ def apply context
8
+ target_dir = context['target_dir'] || raise(NoDestinationDirError)
9
+ file = context['file'] || raise(NoFileError)
10
+
11
+ target_file = File.join(context['target_prefix'] || '', target_dir, file)
12
+ FileUtils.mkdir_p(File.dirname(target_file))
13
+ FileUtils.touch(target_file)
14
+ $stdout.puts " >> #{target_file}"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,75 @@
1
+ require 'rubygems'
2
+
3
+ module Baltix::Actor
4
+ class InvalidActorKindError < StandardError; end
5
+ class InvalidContextKindForActorError < StandardError; end
6
+
7
+ Gem.load_yaml
8
+
9
+ AUTOMAP = {
10
+ Spec: "baltix/actor/spec",
11
+ Link: "baltix/actor/link",
12
+ Touch: "baltix/actor/touch",
13
+ Copy: "baltix/actor/copy",
14
+ }
15
+
16
+ class << self
17
+ def kinds
18
+ @kinds ||= AUTOMAP.keys.map(&:to_s).map(&:downcase)
19
+ end
20
+
21
+ def actors
22
+ @actors ||= AUTOMAP.keys.map do |const|
23
+ require(AUTOMAP[const])
24
+ [ const.to_s.downcase, const_get(const) ]
25
+ end.to_h
26
+ end
27
+
28
+ def scheme
29
+ @scheme ||= YAML.load(IO.read(File.join(File.dirname(__FILE__), "scheme.erb.yaml")))
30
+ end
31
+
32
+ def config
33
+ @config ||= ObjectSpace.each_object(Baltix::Configuration).first
34
+ end
35
+
36
+ def procline file
37
+ scheme.map.with_index do |rule, index|
38
+ match = rule['match']
39
+
40
+ if !match || /#{match}$/ =~ file
41
+ rule['proc'].map do |data|
42
+ # TODO cache it by match or index
43
+ context_in = ERB.new(data['context'].to_yaml)
44
+ c = yield(data['actor'], context_in)
45
+ c.merge('$' => actors[data['actor']])
46
+ end
47
+ end
48
+ end.compact
49
+ end
50
+
51
+ def objectize target
52
+ target.source.trees do |kind, h|
53
+ h.map do |dir, files|
54
+ files.map do |file|
55
+ procline(file) do |actor, context_in|
56
+ YAML.load(context_in.result(binding))
57
+ end
58
+ end
59
+ end
60
+ end.flatten
61
+ end
62
+
63
+ def for! task, context
64
+ actor = actors[task.to_s] || raise(InvalidActorKindError)
65
+ actor.context_kind == context.class || raise(InvalidContextKindForActorError)
66
+
67
+ actor
68
+ end
69
+
70
+ def for task, context
71
+ for!(task, context)
72
+ rescue InvalidActorKindError
73
+ end
74
+ end
75
+ end
data/lib/baltix/cli.rb ADDED
@@ -0,0 +1,173 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+ require 'yaml'
4
+
5
+ require 'baltix'
6
+ require 'baltix/space'
7
+ require 'baltix/actor'
8
+ require 'baltix/log'
9
+
10
+ class Baltix::CLI
11
+ include Baltix::Log
12
+
13
+ DEFAULT_OPTIONS = {
14
+ rootdir: nil,
15
+ spec_type: "rpm",
16
+ ignored_names: [],
17
+ regarded_names: [],
18
+ aliased_names: [],
19
+ ignored_path_tokens: [],
20
+ spec_file: nil,
21
+ maintainer_name: nil,
22
+ maintainer_email: nil,
23
+ available_gem_list: {},
24
+ devel_dep_baltix: :include,
25
+ use_gem_version_list: {}.to_os,
26
+ use_gem_obsolete_list: {}.to_os,
27
+ log_level: :info,
28
+ warn_io: 'stderr',
29
+ error_io: 'stderr',
30
+ info_io: 'stdout',
31
+ debug_io: 'stderr',
32
+ skip_platforms: %i(jruby)
33
+ }.to_os
34
+
35
+ def option_parser
36
+ @option_parser ||=
37
+ OptionParser.new do |opts|
38
+ opts.banner = "Usage: baltix.rb [options & actions]"
39
+
40
+ opts.on("-r", "--rootdir=FOLDER", String, "Root folder to scan the sources") do |folder|
41
+ options[:rootdir] = folder
42
+ end
43
+
44
+ opts.on("--source-lib-folders=FOLDERS", Array, "Lib directories for the current source or at whole") do |list|
45
+ options[:source_lib_folders] = list.compact
46
+ end
47
+
48
+ opts.on("-I", "--ignore-names=LIST", Array, "Source names comma-separated ignore list") do |list|
49
+ options.ignored_names |= list.compact.map do |x|
50
+ m = /^\/(?<re>.*)/.match(x)
51
+ m && /#{m[:re]}/ || x
52
+ end
53
+ end
54
+
55
+ opts.on("-R", "--regard-names=LIST", Array, "Source names comma-separated regard list") do |list|
56
+ options.regarded_names |= list.compact.map do |x|
57
+ m = /^\/(?<re>.*)/.match(x)
58
+ m && /#{m[:re]}/ || x
59
+ end
60
+ end
61
+
62
+ opts.on("-A", "--alias-names=[LIST]", Array, "Source names comma-separated alias list") do |list|
63
+ options.aliased_names << list.compact
64
+ end
65
+
66
+ opts.on("-o", "--output-file=FILE", String, "Output file for a spec action") do |file|
67
+ options.output_file = file
68
+ end
69
+
70
+ opts.on("-s", "--spec-file=FILE", String, "Spec file for covering the baltix space") do |file|
71
+ options.spec_file = file
72
+ end
73
+
74
+ opts.on("-i", "--ignore-path-tokens=[LIST]", Array, "Ignore sources by a contained in its path token, and passed as a comma-separated list") do |list|
75
+ options.ignored_path_tokens.concat(list.compact)
76
+ end
77
+
78
+ opts.on("--maintainer-name=NAME", String, "Name of the maintainer to use on spec generation") do |name|
79
+ options.maintainer_name = name
80
+ end
81
+
82
+ opts.on("--maintainer-email=EMAIL", String, "Email of the maintainer to use on spec generation") do |email|
83
+ options.maintainer_email = email
84
+ end
85
+
86
+ opts.on("--devel-dep-baltix=<TYPE>", %i(include skip), "Apply baltix type for devel dependencies to use with, defaulting to 'include'") do |type|
87
+ options.devel_dep_baltix = type
88
+ end
89
+
90
+ opts.on("-g", "--available-gem-list-file=[FILE]", String, "Path to a YAML-formatted file with the list of available gems to replace in dependencies") do |file|
91
+ options.available_gem_list = YAML.load(IO.read(file))
92
+ end
93
+
94
+ opts.on("--debug-io=[FILE|IO| |-|--]", String, "IO for debug level. Value is file name, or --/stderr for stderr, or -/stdout for stdout, or blank to disable") do |str|
95
+ options.debug_io = str
96
+ end
97
+
98
+ opts.on("-V", "--use-gem-version=[LIST]", Array, "Comma separated gem version pair list to forcely use in the baltix") do |gem_version|
99
+ hash = gem_version.map {|gv| gv.split(":") }.to_h
100
+ options.use_gem_version_list = options.use_gem_version_list.merge(hash)
101
+ end
102
+
103
+ opts.on("-O", "--use-gem-obsolete=[LIST]", Array, "Comma separated gem obsolete list to forcely use in the baltix") do |gem_obsolete|
104
+ hash = gem_obsolete.map {|gv| gv.split(":") }.map {|(x, y)| [x, y.split(/,/)] }.to_h
105
+ options.use_gem_obsolete_list = options.use_gem_obsolete_list.merge(hash)
106
+ end
107
+
108
+ opts.on("-v", "--verbose=[LEVEL]", String, "Run verbosely with levels: none, error, warn, info, or debug") do |v|
109
+ options.log_level = v
110
+ end
111
+
112
+ opts.on("-h", "--help", "This help") do |v|
113
+ puts opts
114
+ exit
115
+ end
116
+ end
117
+
118
+ if @argv
119
+ @option_parser.default_argv.replace(@argv)
120
+ elsif @option_parser.default_argv.empty?
121
+ @option_parser.default_argv << "-h"
122
+ end
123
+
124
+ @option_parser
125
+ end
126
+
127
+ def options
128
+ @options ||= DEFAULT_OPTIONS.dup
129
+ end
130
+
131
+ def actions
132
+ @actions ||= parse.actions.select { |a| Baltix::Actor.kinds.include?(a) }
133
+ end
134
+
135
+ def parse!
136
+ return @parse if @parse
137
+
138
+ option_parser.parse!
139
+
140
+ @parse = OpenStruct.new(options: options, actions: option_parser.default_argv)
141
+ end
142
+
143
+ def parse
144
+ parse!
145
+ rescue OptionParser::InvalidOption
146
+ @parse = OpenStruct.new(options: options, actions: option_parser.default_argv)
147
+ end
148
+
149
+ def space
150
+ @space ||= Baltix::Space.load_from(options: parse.options)
151
+ end
152
+
153
+ def space= value
154
+ @space = value
155
+ end
156
+
157
+ def run
158
+ actions.reduce({}.to_os) do |res, action_name|
159
+ res[action_name] = Baltix::Actor.for!(action_name, space)
160
+
161
+ res
162
+ end.map do |action_name, actor|
163
+ actor.apply_to(space)
164
+ end
165
+ rescue SystemExit, Interrupt
166
+ rescue Exception => e
167
+ error("[#{e.class}]: #{e.message}\n\t#{e.backtrace.join("\n\t")}")
168
+ end
169
+
170
+ def initialize argv = nil
171
+ @argv = argv&.split(/\s+/)
172
+ end
173
+ end