forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodegen
More file actions
executable file
·75 lines (64 loc) · 1.9 KB
/
codegen
File metadata and controls
executable file
·75 lines (64 loc) · 1.9 KB
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
74
75
#!/usr/bin/env ruby
CurrentDir = File.dirname(__FILE__)
require 'optparse'
require 'ostruct'
$LOAD_PATH.unshift(File.join(CurrentDir, '..', 'lib'))
require 'code_generator'
require 'parser'
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
options = OpenStruct.new
# default input / output path
options.input = "#{CurrentDir}/../../include/TrustWalletCore"
options.output = "#{CurrentDir}/../../"
options.swift = true
options.java = true
options.jni_h = true
options.jni_c = true
OptionParser.new do |opts|
opts.banner = 'Usage: codegen [options]'
opts.on('-i', '--input FOLDER', "Input folder with C headers. Default: #{options.input}") do |v|
options.swift = v
end
opts.on('-o', '--output FOLDER', "Output folder. Default: #{options.output}") do |v|
options.swift = v
end
opts.on('-s', '--swift', "Generate Swift code. Default: #{options.swift}") do |v|
options.swift = v
end
opts.on('-j', '--java', "Generate Java code. Default: #{options.java}") do |v|
options.java = v
end
opts.on('-d', '--jnih', "Generate JNI header. Default: #{options.jni_h}") do |v|
options.jni_h = v
end
opts.on('-c', '--jnic', "Generate JNI code. Default: #{options.jni_c}") do |v|
options.jni_c = v
end
opts.on_tail('-h', '--help', 'Show this message') do
puts opts
exit
end
end.parse!
entities = []
files = []
Dir.foreach(options.input) do |item|
next if ['.', '..', '.DS_Store'].include?(item)
entity = Parser.new(path: File.expand_path(File.join(options.input, item))).parse
next if entity.nil?
entities << entity
files << File.basename(item, '.h').sub(/^TW/, '')
end
generator = CodeGenerator.new(entities: entities, files: files, output_folder: options.output)
if options.swift
generator.render_swift
end
if options.java
generator.render_java
end
if options.jni_h
generator.render_jni_h
end
if options.jni_c
generator.render_jni_c
end