File: update-LegacyInspectorBackendCommands.rb

package info (click to toggle)
webkit2gtk 2.48.3-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 429,620 kB
  • sloc: cpp: 3,696,936; javascript: 194,444; ansic: 169,997; python: 46,499; asm: 19,276; ruby: 18,528; perl: 16,602; xml: 4,650; yacc: 2,360; sh: 2,098; java: 1,993; lex: 1,327; pascal: 366; makefile: 295
file content (73 lines) | stat: -rwxr-xr-x 2,268 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env ruby

require 'fileutils'
require 'tmpdir'

if ARGV.size != 0
  puts "usage: #{File.basename $0}"
  exit 1
end

WEB_INSPECTOR_PATH = File.expand_path File.join(File.dirname(__FILE__), "..")
JAVASCRIPTCORE_PATH = File.expand_path File.join(File.dirname(__FILE__), "..", "..", "JavaScriptCore")

$code_generator_path = File.join JAVASCRIPTCORE_PATH, "inspector", "scripts", "generate-inspector-protocol-bindings.py"
$versions_directory_path = File.join WEB_INSPECTOR_PATH, "Versions"
$web_inspector_protocol_legacy_path = File.join WEB_INSPECTOR_PATH, "UserInterface", "Protocol", "Legacy"

class Task
  def initialize(input_json_path, output_directory_path)
    @input_json_path = input_json_path
    @output_directory_path = output_directory_path
  end

  def run
    output_filename = "InspectorBackendCommands.js"
    display_input = File.basename @input_json_path
    display_output = File.join @output_directory_path.gsub(/^.*?\/UserInterface/, "UserInterface"), output_filename
    puts "#{display_input} -> #{display_output}"

    Dir.mktmpdir do |tmpdir|
      cmd = "#{$code_generator_path} --force --outputDir '#{tmpdir}' --framework WebInspectorUI '#{@input_json_path}'"
      %x{ #{cmd} }
      if $?.exitstatus != 0
        puts "ERROR: Error Code (#{$?.exitstatus}) Evaluating: #{cmd}"
        exit 1
      end

      generated_path = File.join tmpdir, output_filename
      if !File.exist?(generated_path)
        puts "ERROR: Generated file does not exist at expected path."
        exit 1
      end

      FileUtils.mkdir_p @output_directory_path
      FileUtils.cp generated_path, @output_directory_path
    end
  end
end

def all_tasks
  tasks = []

  had_error = false
  Dir.glob(File.join($versions_directory_path, "*.json")).each do |version_path|
    match = File.basename(version_path).match(/^Inspector\-(.*?)\-([^-]+?)\.json$/)
    if match
      output_path = File.join $web_inspector_protocol_legacy_path, match[1], match[2]
      tasks << Task.new(version_path, output_path)
    else
      puts "ERROR: Version file (#{version_path}) did not match the template Inspector-<ANYTHING>-<VERSION>.js"
      had_error = true
    end
  end
  exit 1 if had_error

  tasks
end

def main
  all_tasks.each { |task| task.run }
end

main