plover 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/lib/plover.rb +92 -15
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c02ad2ecd60c71f6183a2db31ba64dd0f15769cbf7774273913595dfb72ccd93
4
- data.tar.gz: c6fb12369964a4aa2238ffde51d4675e5b716eae056e12311193bb3570ec204e
3
+ metadata.gz: b2984c4ea419b9a232a29d892175645cf91d464e2eaec36d7f48e0322d3590fa
4
+ data.tar.gz: 4ed6849a1ac93e65a6882e4a9031f6591db54bf8cf83318446401ac9acb20396
5
5
  SHA512:
6
- metadata.gz: 15a087dd706ac377d6535956b9f62bb3a94e7811ce15c09e2a1b81ee3e79a2c25b26d495eedf5dd1a561e54b495d6c3867d9342a0d28ebbefc48fed7800c48b8
7
- data.tar.gz: 7c8eee52f8818b246f1a57dd01947cb1ee398f12e92d0811559e0c3425ca93e5abfba0ecc2597c0dd091f74a48cf34feb7f159d43257f263c0b1eaab27c3d30b
6
+ metadata.gz: e0652cc353807d85f0696d52f9f2c09537d4b941a6faf7e1cdb62a63a5c997c508c0b038f1c741c85a72e9af8bb8bc07a8a3adb5453d4d0f4efcaa71d16d94fa
7
+ data.tar.gz: c61d1e4c31e95ce23022ca037a02ac646771c7d21208f9422397d37674483717b835fc929439006c5dcca4e7fd4f918a90bb282ab9e3981a55311a607d7e6015
data/README.md CHANGED
@@ -10,7 +10,7 @@ To help you with that, Plover provides a lightweight DSL for defining build phas
10
10
 
11
11
  #### Tiny & Embeddable
12
12
 
13
- Plover consists of ~200 lines of plain Ruby, with no dependencies outside of the standard library.
13
+ Plover consists of ~300 lines of plain Ruby, with no dependencies outside of the standard library.
14
14
 
15
15
  Because Plover is built to be embeddable, you can copy/paste `lib/plover.rb` into your project if you'd rather not use the gem.
16
16
 
@@ -47,7 +47,7 @@ Or, add it to your project’s Gemfile:
47
47
  gem "plover"
48
48
  ```
49
49
 
50
- Because Plover is built to be embeddable, you can also just copy/paste `lib/plover.rb` into your project if you'd rather not use RubyGems (it's ~200 lines of plain Ruby, with no dependencies outside of the standard library).
50
+ Because Plover is built to be embeddable, you can also just copy/paste `lib/plover.rb` into your project if you'd rather not use RubyGems (it's ~300 lines of plain Ruby, with no dependencies outside of the standard library).
51
51
 
52
52
  ## Usage
53
53
 
data/lib/plover.rb CHANGED
@@ -4,7 +4,7 @@ module Plover
4
4
  require "shellwords"
5
5
  require "fileutils"
6
6
 
7
- VERSION = "1.0.0"
7
+ VERSION = "1.1.0"
8
8
 
9
9
  class PloverError < StandardError; end
10
10
 
@@ -30,6 +30,46 @@ module Plover
30
30
  end
31
31
  end
32
32
 
33
+ module Log
34
+ require "logger"
35
+
36
+ def log(severity, msg)
37
+ logger.add(log_severity(severity), msg) unless log_config[:level] == :none
38
+ end
39
+
40
+ def log_level(severity)
41
+ log_config[:level] = severity
42
+ @logger = nil
43
+ logger.level = log_severity(log_config[:level])
44
+ end
45
+
46
+ def log_severity(severity = nil)
47
+ Logger::Severity.coerce(severity)
48
+ rescue
49
+ Logger::Severity.coerce(:unknown)
50
+ end
51
+
52
+ def logger
53
+ sink = case log_config[:sink]
54
+ when String
55
+ f = File.open(log_config[:sink], "a")
56
+ f.sync = true
57
+ f
58
+ when ->(s) { s.respond_to?(:write) }
59
+ log_config[:sink]
60
+ else $stdout
61
+ end
62
+
63
+ @logger ||= Logger.new(sink,
64
+ progname: "<Plover/#{is_a?(Class) ? name : self.class.name}>",
65
+ level: log_severity(log_config[:level]))
66
+ end
67
+
68
+ def log_config
69
+ is_a?(Class) ? configuration[:options][:log] : @configuration[:options][:log]
70
+ end
71
+ end
72
+
33
73
  class Builder
34
74
  class FlagError < PloverError; end
35
75
 
@@ -39,6 +79,8 @@ module Plover
39
79
 
40
80
  module Common; end
41
81
 
82
+ include Log
83
+
42
84
  attr_reader :configuration
43
85
 
44
86
  @configuration = {
@@ -51,9 +93,13 @@ module Plover
51
93
  },
52
94
  options: {
53
95
  flags: {},
54
- expected_flags: []
96
+ expected_flags: [],
97
+ common_include: :none,
98
+ log: {
99
+ level: :info,
100
+ sink: :stdout
101
+ }
55
102
  },
56
- include_common: :none,
57
103
  artifacts: {
58
104
  setup: {},
59
105
  before_build: {},
@@ -64,10 +110,12 @@ module Plover
64
110
  }
65
111
 
66
112
  class << self
113
+ extend Log
114
+
67
115
  attr_reader :configuration
68
116
 
69
117
  def inherited(subclass)
70
- auto_include_common
118
+ subclass.extend(Log)
71
119
  subclass.instance_variable_set(:@configuration, deep_copy(configuration))
72
120
  end
73
121
 
@@ -87,6 +135,14 @@ module Plover
87
135
  configuration[:options][:common_include] = :none
88
136
  end
89
137
 
138
+ def log_level(severity)
139
+ configuration[:options][:log][:level] = severity.to_sym
140
+ end
141
+
142
+ def log_sink(sink)
143
+ configuration[:options][:log][:sink] = sink
144
+ end
145
+
90
146
  def common_include(*modules)
91
147
  configuration[:options][:common_include] = [] unless configuration[:options][:common_include].is_a?(Array)
92
148
 
@@ -108,14 +164,17 @@ module Plover
108
164
  end
109
165
 
110
166
  def auto_include_common
111
- return if configuration[:options][:common_include] == :none
167
+ return if @configuration[:options][:common_include] == :none
112
168
 
113
169
  ObjectSpace.each_object(Module).select { |m| m&.name&.start_with?("Plover::Builder::Common::") }.each do |mod|
114
170
  next if mod.name.to_s.end_with?("::ClassMethods")
115
171
 
116
- next if configuration[:options][:common_include].is_a?(Array) && !configuration[:options][:common_include].any? { |m| m.end_with?("::#{mod.name}") }
172
+ next if @configuration[:options][:common_include].is_a?(Array) && !@configuration[:options][:common_include].any? { |m| m == mod.name.split("::").last }
117
173
 
118
- mod.apply_concern(self) if mod.respond_to?(:apply_concern) && !included_modules.include?(mod)
174
+ if mod.respond_to?(:apply_concern) && !included_modules.include?(mod)
175
+ log(:debug, "Loading Common #{mod.name}")
176
+ mod.apply_concern(self)
177
+ end
119
178
  end
120
179
  end
121
180
 
@@ -131,15 +190,22 @@ module Plover
131
190
  end
132
191
  end
133
192
 
134
- def initialize(flags = {})
135
- self.class.auto_include_common
193
+ def initialize(flags = {}, use_env_flags: true)
136
194
  @configuration = self.class.configuration
137
- @configuration[:options][:flags] = @configuration[:options][:flags].merge(flags).merge(self.class.env_flags)
138
195
 
139
- return unless @configuration[:options][:expected_flags].any?
196
+ @configuration[:options][:log][:level] = flags[:log_level] || ENV["PLOVER_LOG_LEVEL"]&.to_sym || @configuration[:options][:log][:level] || :info
197
+ @configuration[:options][:log][:sink] = flags[:log_sink] || ENV["PLOVER_LOG_SINK"] || @configuration[:options][:log][:sink] || :stdout
140
198
 
141
- missing_flags = @configuration[:options][:expected_flags].reject { |sym| @configuration[:options][:flags].key?(sym) }
142
- raise BuildError.new("Missing required flags: #{missing_flags.join(", ")}") if missing_flags.any?
199
+ @configuration[:options][:flags] = @configuration[:options][:flags].merge(flags).merge(use_env_flags ? self.class.env_flags : {})
200
+
201
+ self.class.auto_include_common
202
+
203
+ if @configuration[:options][:expected_flags].any?
204
+ missing_flags = @configuration[:options][:expected_flags].reject { |sym| @configuration[:options][:flags].key?(sym) }
205
+ fail_build("Missing required flags: #{missing_flags.join(", ")}") if missing_flags.any?
206
+ end
207
+
208
+ log :debug, "Initialized, options=#{@configuration[:options]}"
143
209
  end
144
210
 
145
211
  def prepend_phase(phase, &block)
@@ -167,11 +233,15 @@ module Plover
167
233
  end
168
234
 
169
235
  def raise_unless_flag(name, message)
170
- raise FlagError.new(message) unless flag(name)
236
+ unless flag(name)
237
+ log :fatal, "Missing flag '#{name}': #{message}"
238
+ raise FlagError.new(message)
239
+ end
171
240
  end
172
241
 
173
242
  def push_artifact(name, value)
174
243
  return unless @current_phase
244
+ log :debug, "Pushed artifact name='#{name}' value='#{value}'"
175
245
  @configuration[:artifacts][@current_phase][name] = value
176
246
  end
177
247
 
@@ -189,17 +259,23 @@ module Plover
189
259
  end
190
260
 
191
261
  def raise_unless_artifact(phase, name, message)
192
- raise ArtifactError.new(message) unless artifact(phase, name)
262
+ unless artifact(phase, name)
263
+ log :fatal, "Missing artifact '#{name}': #{message}"
264
+ raise ArtifactError.new(message)
265
+ end
193
266
  end
194
267
 
195
268
  def fail_build(message)
269
+ log :fatal, "Build failure: #{message}"
196
270
  raise BuildError.new(message)
197
271
  end
198
272
 
199
273
  def run_phase(phase)
274
+ log :debug, "\\/ #{phase.to_s.capitalize} Phase Starting \\/"
200
275
  @current_phase = phase
201
276
  @configuration[:steps][phase].each { |block| instance_exec(&block) }
202
277
  @current_phase = nil
278
+ log :debug, "/\\ #{phase.to_s.capitalize} Phase Finished /\\"
203
279
  end
204
280
 
205
281
  def run
@@ -210,6 +286,7 @@ module Plover
210
286
  run_phase(:after_build)
211
287
  end
212
288
  run_phase(:teardown)
289
+ logger.close
213
290
  end
214
291
  end
215
292
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plover
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlton Trezevant
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-17 00:00:00.000000000 Z
10
+ date: 2025-03-18 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Plover is a tiny, embeddable Ruby build system.
13
13
  email: