blob: 9c0270fdd00116e863bc1b30b0daddf70aec03ae [file] [log] [blame]
Parker Schuh343481e2014-02-09 18:28:43 -08001$LOAD_PATH.unshift(".")
brians343bc112013-02-10 01:53:46 +00002["tokenizer.rb","q_file.rb","queue_group.rb","queue.rb","namespaces.rb",
Parker Schuh343481e2014-02-09 18:28:43 -08003"interface.rb","errors.rb", "q_struct.rb"].each do |name|
brians343bc112013-02-10 01:53:46 +00004 require File.dirname(__FILE__) + "/objects/" + name
5end
6["standard_types.rb","auto_gen.rb","file_pair_types.rb",
7"dep_file_pair.rb","swig.rb"].each do |name|
8 require File.dirname(__FILE__) + "/cpp_pretty_print/" + name
9end
Parker Schuh343481e2014-02-09 18:28:43 -080010["q_file.rb","message_dec.rb","queue_dec.rb", "q_struct.rb"].each do |name|
brians343bc112013-02-10 01:53:46 +000011 require File.dirname(__FILE__) + "/output/" + name
12end
13require "fileutils"
14require "pathname"
15
16def parse_args(globals,args)
17 i = 0
18 $swig = false
19 $swigccout_path = ""
20 while(i < args.length)
21 if(args[i] == "-I")
22 args.delete_at(i)
23 if(!args[i])
24 $stderr.puts "hey! -I is followed by nothing."
25 $stderr.puts "\tnot a supported usage..."
26 $stderr.puts "\tWot. Wot."
27 exit!(-1)
28 end
29 path = args.delete_at(i)
30 globals.add_path(path)
31 elsif(args[i] == "--swigccout")
32 args.delete_at(i)
33 $swigccout_path = args.delete_at(i)
34 elsif(args[i] == "-cpp_out")
35 args.delete_at(i)
36 path = args.delete_at(i)
37 if(path =~ /\./)
38 $stderr.puts "hey! path #{path} has a \".\" char which is "
39 $stderr.puts "\tnot a supported usage..."
40 $stderr.puts "\tWot. Wot."
41 exit!(-1)
42 elsif(!path)
43 $stderr.puts "hey! No cpp_out path provided."
44 $stderr.puts "\tumm, you could try -cpp_out \"\""
45 $stderr.puts "\tThat might do the trick"
46 $stderr.puts "\tWot. Wot."
47 exit!(-1)
48 end
49 $cpp_out = path.split(/\\|\//)
50 elsif(args[i] == "--swig")
51 $swig = true
52 args.delete_at(i)
53 elsif(args[i] == "-cpp_base")
54 args.delete_at(i)
55 path = args.delete_at(i)
56 $cpp_base = File.expand_path(path)
57 if(!File.exists?($cpp_base))
58 $stderr.puts "output directory #{$cpp_base.inspect} does not exist."
59 $stderr.puts "\tI'm not going to make that! sheesh, who do you think I am?"
60 $stderr.puts "\tWot. Wot."
61 exit!(-1)
62 end
63 elsif(args[i] =~ /^-/)
64 $stderr.puts "hey! unknown argument #{args[i]}."
65 $stderr.puts "\tWot. Wot."
66 exit!(-1)
67 else
68 i += 1
69 end
70 end
71 if(!$cpp_base)
72 $stderr.puts "hey! missing -cpp_base argument."
73 $stderr.puts "\tWot. Wot."
74 exit!(-1)
75 end
76 if(!$cpp_out)
77 $stderr.puts "hey! missing -cpp_out argument."
78 $stderr.puts "\tWot. Wot."
79 exit!(-1)
80 end
81end
82def build(filename,globals_template)
83 globals = Globals.new()
84 globals_template.paths.each do |path|
85 globals.add_path(path)
86 end
87 filename = File.expand_path(filename)
88 q_file = QFile.parse(filename)
89 output_file = q_file.q_eval(globals)
90 q_filename = File.basename(filename)
91 rel_path = ($cpp_out + [q_filename]).join("/")
92
93 FileUtils.mkdir_p(Pathname.new($cpp_base) + $cpp_out.join("/"))
94
95 cpp_tree = output_file.make_cpp_tree(rel_path)
96
97 h_file_path = $cpp_base + "/" + rel_path + ".h"
98 cc_file_path = $cpp_base + "/" + rel_path + ".cc"
99 swig_file_path = $cpp_base + "/" + rel_path + ".swig"
100 java_directory = $cpp_base + "/" + rel_path + "_java/"
101 cpp_tree.add_cc_include((rel_path + ".h").inspect)
102 cpp_tree.add_cc_include("aos/common/byteorder.h".inspect)
103 cpp_tree.add_cc_include("aos/common/inttypes.h".inspect)
Parker Schuh711db3e2014-02-12 09:47:34 -0800104 cpp_tree.add_cc_include("aos/common/queue_types.h".inspect)
brians343bc112013-02-10 01:53:46 +0000105 cpp_tree.add_cc_using("::aos::to_network")
106 cpp_tree.add_cc_using("::aos::to_host")
107 cpp_tree.add_swig_header_include("aos/common/queue.h".inspect)
Brian Silverman14fd0fb2014-01-14 21:42:01 -0800108 cpp_tree.add_swig_body_include("aos/linux_code/queue-tmpl.h".inspect)
brians343bc112013-02-10 01:53:46 +0000109 cpp_tree.add_swig_header_include("aos/common/time.h".inspect)
110 cpp_tree.add_swig_include((rel_path + ".h").inspect)
111
112 header_file = File.open(h_file_path,"w+")
113 cc_file = File.open(cc_file_path,"w+")
114 cpp_tree.write_header_file($cpp_base,header_file)
115 cpp_tree.write_cc_file($cpp_base,cc_file)
116 cc_file.close()
117 header_file.close()
118 if ($swig)
119 swig_file = File.open(swig_file_path,"w+")
120 cpp_tree.write_swig_file($cpp_base,swig_file,q_filename)
121 swig_file.close()
122 namespace = q_file.namespace.get_name()[1..-1]
123 FileUtils.mkdir_p(java_directory)
124 includes = globals.paths.collect { |a| "-I#{a}" }
125
126 if (!system('/usr/bin/swig', *(includes + ['-I' + $cpp_base + '/',
127 '-package', namespace,
128 '-outdir', java_directory,
129 '-o', $swigccout_path,
130 '-c++', '-Wall', '-Wextra', '-java', swig_file_path])))
131 puts "Swig failed."
132 exit -1
133 end
134 end
135end
136begin
137 args = ARGV.dup
138 globals = Globals.new()
139 parse_args(globals,args)
140 if(args.length == 0)
141 $stderr.puts "hey! you want me to do something,"
142 $stderr.puts "\tbut you gave me no q files to build!"
143 $stderr.puts "\tWot. Wot."
144 exit!(-1)
145 end
146 args.each do |filename|
147 build(filename,globals)
148 end
149 exit(0)
150rescue QError => e
151 $stderr.print(e.to_s)
152 exit!(-1)
153end