blob: bcd497adb0b5ed0e354d5ea13f30a68b4dd15e32 [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",
Brian Silverman04fdc232014-02-12 14:51:11 -08007"dep_file_pair.rb"].each do |name|
brians343bc112013-02-10 01:53:46 +00008 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
brians343bc112013-02-10 01:53:46 +000018 while(i < args.length)
19 if(args[i] == "-I")
20 args.delete_at(i)
21 if(!args[i])
22 $stderr.puts "hey! -I is followed by nothing."
23 $stderr.puts "\tnot a supported usage..."
24 $stderr.puts "\tWot. Wot."
25 exit!(-1)
26 end
27 path = args.delete_at(i)
28 globals.add_path(path)
brians343bc112013-02-10 01:53:46 +000029 elsif(args[i] == "-cpp_out")
30 args.delete_at(i)
31 path = args.delete_at(i)
32 if(path =~ /\./)
33 $stderr.puts "hey! path #{path} has a \".\" char which is "
34 $stderr.puts "\tnot a supported usage..."
35 $stderr.puts "\tWot. Wot."
36 exit!(-1)
37 elsif(!path)
38 $stderr.puts "hey! No cpp_out path provided."
39 $stderr.puts "\tumm, you could try -cpp_out \"\""
40 $stderr.puts "\tThat might do the trick"
41 $stderr.puts "\tWot. Wot."
42 exit!(-1)
43 end
44 $cpp_out = path.split(/\\|\//)
brians343bc112013-02-10 01:53:46 +000045 elsif(args[i] == "-cpp_base")
46 args.delete_at(i)
47 path = args.delete_at(i)
48 $cpp_base = File.expand_path(path)
49 if(!File.exists?($cpp_base))
50 $stderr.puts "output directory #{$cpp_base.inspect} does not exist."
51 $stderr.puts "\tI'm not going to make that! sheesh, who do you think I am?"
52 $stderr.puts "\tWot. Wot."
53 exit!(-1)
54 end
55 elsif(args[i] =~ /^-/)
56 $stderr.puts "hey! unknown argument #{args[i]}."
57 $stderr.puts "\tWot. Wot."
58 exit!(-1)
59 else
60 i += 1
61 end
62 end
63 if(!$cpp_base)
64 $stderr.puts "hey! missing -cpp_base argument."
65 $stderr.puts "\tWot. Wot."
66 exit!(-1)
67 end
68 if(!$cpp_out)
69 $stderr.puts "hey! missing -cpp_out argument."
70 $stderr.puts "\tWot. Wot."
71 exit!(-1)
72 end
73end
74def build(filename,globals_template)
75 globals = Globals.new()
76 globals_template.paths.each do |path|
77 globals.add_path(path)
78 end
79 filename = File.expand_path(filename)
80 q_file = QFile.parse(filename)
81 output_file = q_file.q_eval(globals)
82 q_filename = File.basename(filename)
83 rel_path = ($cpp_out + [q_filename]).join("/")
84
85 FileUtils.mkdir_p(Pathname.new($cpp_base) + $cpp_out.join("/"))
86
87 cpp_tree = output_file.make_cpp_tree(rel_path)
88
89 h_file_path = $cpp_base + "/" + rel_path + ".h"
90 cc_file_path = $cpp_base + "/" + rel_path + ".cc"
brians343bc112013-02-10 01:53:46 +000091 cpp_tree.add_cc_include((rel_path + ".h").inspect)
92 cpp_tree.add_cc_include("aos/common/byteorder.h".inspect)
93 cpp_tree.add_cc_include("aos/common/inttypes.h".inspect)
Parker Schuh711db3e2014-02-12 09:47:34 -080094 cpp_tree.add_cc_include("aos/common/queue_types.h".inspect)
Brian Silverman665e60c2014-02-12 13:57:10 -080095 cpp_tree.add_cc_include("aos/common/once.h".inspect)
brians343bc112013-02-10 01:53:46 +000096 cpp_tree.add_cc_using("::aos::to_network")
97 cpp_tree.add_cc_using("::aos::to_host")
brians343bc112013-02-10 01:53:46 +000098
99 header_file = File.open(h_file_path,"w+")
100 cc_file = File.open(cc_file_path,"w+")
101 cpp_tree.write_header_file($cpp_base,header_file)
102 cpp_tree.write_cc_file($cpp_base,cc_file)
103 cc_file.close()
104 header_file.close()
brians343bc112013-02-10 01:53:46 +0000105end
106begin
107 args = ARGV.dup
108 globals = Globals.new()
109 parse_args(globals,args)
110 if(args.length == 0)
111 $stderr.puts "hey! you want me to do something,"
112 $stderr.puts "\tbut you gave me no q files to build!"
113 $stderr.puts "\tWot. Wot."
114 exit!(-1)
115 end
116 args.each do |filename|
117 build(filename,globals)
118 end
119 exit(0)
120rescue QError => e
121 $stderr.print(e.to_s)
122 exit!(-1)
123end