Module: Ibex::CLIGenerationArtifacts

Included in:
CLI
Defined in:
lib/ibex/cli/generation_artifacts.rb,
sig/ibex/cli/generation_artifacts.rbs

Overview

Collects, verifies, and transactionally publishes CLI generation outputs.

Instance Method Summary collapse

Instance Method Details

#add_generation_manifestvoid

This method returns an undefined value.

RBS:

  • () -> void



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ibex/cli/generation_artifacts.rb', line 55

def add_generation_manifest
  require_relative "../generation_manifest"

  path = manifest_output_path
  source = GenerationManifest.render(
    generation_artifacts,
    source_records: @generation_inputs,
    options: generation_manifest_options
  )
  register_artifact(:manifest, path, source, status: true)
end

#artifact_label(kind) ⇒ String

RBS:

  • (Symbol kind) -> String

Parameters:

  • kind (Symbol)

Returns:

  • (String)


77
78
79
80
81
82
83
84
# File 'lib/ibex/cli/generation_artifacts.rb', line 77

def artifact_label(kind)
  {
    parser: "parser",
    rbs: "RBS signature",
    action_source: "action source",
    manifest: "generation manifest"
  }.fetch(kind, kind.to_s.tr("_", " "))
end

#begin_artifact_generationvoid

This method returns an undefined value.

RBS:

  • () -> void



19
20
21
22
23
24
# File 'lib/ibex/cli/generation_artifacts.rb', line 19

def begin_artifact_generation
  @generation_artifacts = ArtifactSet.new
  @generation_statuses = [] #: Array[String]
  @generation_sources = [] #: Array[String]
  @generation_inputs = [] #: Array[GenerationInput]
end

#ensure_generation_inputs_stable!void

This method returns an undefined value.

RBS:

  • () -> void



97
98
99
100
101
# File 'lib/ibex/cli/generation_artifacts.rb', line 97

def ensure_generation_inputs_stable!
  return if generation_inputs_stable?

  raise GenerationTransaction::SourceChanged, "(generation):1:1: source changed while rendering outputs"
end

#finish_artifact_generation(_source_paths) ⇒ Integer

RBS:

  • (Array[String] source_paths) -> Integer

Parameters:

  • source_paths (Array[String])

Returns:

  • (Integer)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ibex/cli/generation_artifacts.rb', line 34

def finish_artifact_generation(_source_paths)
  add_generation_manifest if @options[:manifest]
  return 0 if @defer_generation_publication

  ensure_generation_inputs_stable!
  if @options[:verify_output]
    verify_artifact_generation
    ensure_generation_inputs_stable!
  elsif !generation_artifacts.empty?
    GenerationTransaction.new(
      generation_artifacts,
      warning: ->(message) { @stderr.puts("ibex: warning: #{message}") },
      stability_check: -> { generation_inputs_stable? },
      source_records: @generation_inputs
    ).commit
    @generation_statuses.each { |message| report_status(message) }
  end
  0
end

#generation_artifactsArtifactSet

RBS:

  • () -> ArtifactSet

Returns:



87
88
89
# File 'lib/ibex/cli/generation_artifacts.rb', line 87

def generation_artifacts
  @generation_artifacts || raise(Ibex::Error, "(generation):1:1: artifact collection is not active")
end

#generation_inputs_stable?Boolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


92
93
94
# File 'lib/ibex/cli/generation_artifacts.rb', line 92

def generation_inputs_stable?
  @generation_inputs.all?(&:current?)
end

#generation_manifest_optionsHash[String, untyped]

RBS:

  • () -> Hash[String, untyped]

Returns:

  • (Hash[String, untyped])


124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/ibex/cli/generation_artifacts.rb', line 124

def generation_manifest_options
  keys = %i[
    action_source algorithm counterexample_max_configurations counterexample_max_tokens debug
    embedded emit entry_isolation executable frozen line_convert line_convert_all messages mode omit_actions rbs
    superclass table
  ]
  options = {} #: Hash[String, untyped]
  keys.each do |key|
    value = @options[key]
    options[key.to_s] = value unless value.nil?
  end
  options
end

#manifest_output_pathString

RBS:

  • () -> String

Returns:

  • (String)


113
114
115
116
117
118
119
120
121
# File 'lib/ibex/cli/generation_artifacts.rb', line 113

def manifest_output_path
  configured = @options[:manifest]
  return configured if configured.is_a?(String) && !configured.empty?

  parser = generation_artifacts.find { |artifact| artifact.kind == :parser }
  raise Ibex::Error, "(generation):1:1: generation manifest requires a parser artifact" unless parser

  default_output_path(parser.path, ".ibex.json")
end

#record_generation_input(path, source) ⇒ GenerationInput

RBS:

  • (String path, String source) -> GenerationInput

Parameters:

  • path (String)
  • source (String)

Returns:



104
105
106
107
108
109
110
# File 'lib/ibex/cli/generation_artifacts.rb', line 104

def record_generation_input(path, source)
  input = GenerationInput.new(path, source)
  @generation_inputs.reject! { |entry| entry.path == input.path }
  @generation_inputs << input
  @generation_sources = @generation_inputs.map(&:path)
  input
end

#register_artifact(kind, path, content, mode: nil, status: false) ⇒ Artifact

RBS:

  • (Symbol kind, String path, String content, ?mode: Integer?, ?status: bool) -> Artifact

Parameters:

  • kind (Symbol)
  • path (String)
  • content (String)
  • mode: (Integer, nil) (defaults to: nil)
  • status: (Boolean) (defaults to: false)

Returns:



27
28
29
30
31
# File 'lib/ibex/cli/generation_artifacts.rb', line 27

def register_artifact(kind, path, content, mode: nil, status: false)
  artifact = generation_artifacts.add(kind: kind, path: path, content: content, mode: mode)
  @generation_statuses << "wrote #{path}" if status
  artifact
end

#verify_artifact_generationvoid

This method returns an undefined value.

RBS:

  • () -> void



68
69
70
71
72
73
74
# File 'lib/ibex/cli/generation_artifacts.rb', line 68

def verify_artifact_generation
  generation_artifacts.each do |artifact|
    verify_file(artifact.path, artifact.content, artifact_label(artifact.kind))
  end
  parser = generation_artifacts.find { |artifact| artifact.kind == :parser }
  report_status("verified #{parser.path}") if parser
end