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