blob: e53e217ef730ac17979ce1a73cc2f258bc4f500b [file] [log] [blame]
Brian Silverman1885bd02014-02-13 12:28:12 -08001require File.dirname(__FILE__) + '/load.rb'
brians343bc112013-02-10 01:53:46 +00002
3def parse_args(globals,args)
4 i = 0
brians343bc112013-02-10 01:53:46 +00005 while(i < args.length)
6 if(args[i] == "-I")
7 args.delete_at(i)
8 if(!args[i])
9 $stderr.puts "hey! -I is followed by nothing."
10 $stderr.puts "\tnot a supported usage..."
11 $stderr.puts "\tWot. Wot."
12 exit!(-1)
13 end
14 path = args.delete_at(i)
15 globals.add_path(path)
brians343bc112013-02-10 01:53:46 +000016 elsif(args[i] == "-cpp_out")
17 args.delete_at(i)
18 path = args.delete_at(i)
19 if(path =~ /\./)
20 $stderr.puts "hey! path #{path} has a \".\" char which is "
21 $stderr.puts "\tnot a supported usage..."
22 $stderr.puts "\tWot. Wot."
23 exit!(-1)
24 elsif(!path)
25 $stderr.puts "hey! No cpp_out path provided."
26 $stderr.puts "\tumm, you could try -cpp_out \"\""
27 $stderr.puts "\tThat might do the trick"
28 $stderr.puts "\tWot. Wot."
29 exit!(-1)
30 end
31 $cpp_out = path.split(/\\|\//)
brians343bc112013-02-10 01:53:46 +000032 elsif(args[i] == "-cpp_base")
33 args.delete_at(i)
34 path = args.delete_at(i)
35 $cpp_base = File.expand_path(path)
36 if(!File.exists?($cpp_base))
37 $stderr.puts "output directory #{$cpp_base.inspect} does not exist."
38 $stderr.puts "\tI'm not going to make that! sheesh, who do you think I am?"
39 $stderr.puts "\tWot. Wot."
40 exit!(-1)
41 end
42 elsif(args[i] =~ /^-/)
43 $stderr.puts "hey! unknown argument #{args[i]}."
44 $stderr.puts "\tWot. Wot."
45 exit!(-1)
46 else
47 i += 1
48 end
49 end
50 if(!$cpp_base)
51 $stderr.puts "hey! missing -cpp_base argument."
52 $stderr.puts "\tWot. Wot."
53 exit!(-1)
54 end
55 if(!$cpp_out)
56 $stderr.puts "hey! missing -cpp_out argument."
57 $stderr.puts "\tWot. Wot."
58 exit!(-1)
59 end
60end
61def build(filename,globals_template)
62 globals = Globals.new()
63 globals_template.paths.each do |path|
64 globals.add_path(path)
65 end
66 filename = File.expand_path(filename)
67 q_file = QFile.parse(filename)
68 output_file = q_file.q_eval(globals)
69 q_filename = File.basename(filename)
70 rel_path = ($cpp_out + [q_filename]).join("/")
71
72 FileUtils.mkdir_p(Pathname.new($cpp_base) + $cpp_out.join("/"))
73
74 cpp_tree = output_file.make_cpp_tree(rel_path)
75
76 h_file_path = $cpp_base + "/" + rel_path + ".h"
77 cc_file_path = $cpp_base + "/" + rel_path + ".cc"
brians343bc112013-02-10 01:53:46 +000078 cpp_tree.add_cc_include((rel_path + ".h").inspect)
79 cpp_tree.add_cc_include("aos/common/byteorder.h".inspect)
80 cpp_tree.add_cc_include("aos/common/inttypes.h".inspect)
Parker Schuh711db3e2014-02-12 09:47:34 -080081 cpp_tree.add_cc_include("aos/common/queue_types.h".inspect)
Brian Silverman665e60c2014-02-12 13:57:10 -080082 cpp_tree.add_cc_include("aos/common/once.h".inspect)
brians343bc112013-02-10 01:53:46 +000083 cpp_tree.add_cc_using("::aos::to_network")
84 cpp_tree.add_cc_using("::aos::to_host")
brians343bc112013-02-10 01:53:46 +000085
86 header_file = File.open(h_file_path,"w+")
87 cc_file = File.open(cc_file_path,"w+")
88 cpp_tree.write_header_file($cpp_base,header_file)
89 cpp_tree.write_cc_file($cpp_base,cc_file)
90 cc_file.close()
91 header_file.close()
brians343bc112013-02-10 01:53:46 +000092end
93begin
94 args = ARGV.dup
95 globals = Globals.new()
96 parse_args(globals,args)
97 if(args.length == 0)
98 $stderr.puts "hey! you want me to do something,"
99 $stderr.puts "\tbut you gave me no q files to build!"
100 $stderr.puts "\tWot. Wot."
101 exit!(-1)
102 end
103 args.each do |filename|
104 build(filename,globals)
105 end
106 exit(0)
107rescue QError => e
108 $stderr.print(e.to_s)
109 exit!(-1)
110end