Tweak the Ruby code to support Bazel.
* Change how the files load each other so they actually work with
ruby_binary.
* Add an alternative set of command line flags to the queue compiler
which aligns with what Bazel wants better.
Change-Id: If20d2bad0f8a07ef1d2c2de8519ff0849ec9b6e2
diff --git a/aos/build/queues/compiler.rb b/aos/build/queues/compiler.rb
index 52c0005..1f739e0 100644
--- a/aos/build/queues/compiler.rb
+++ b/aos/build/queues/compiler.rb
@@ -1,62 +1,79 @@
-require File.dirname(__FILE__) + '/load.rb'
+require_relative "load.rb"
def parse_args(globals,args)
- i = 0
- while(i < args.length)
- if(args[i] == "-I")
- args.delete_at(i)
- if(!args[i])
- $stderr.puts "hey! -I is followed by nothing."
- $stderr.puts "\tnot a supported usage..."
- $stderr.puts "\tWot. Wot."
- exit!(-1)
- end
- path = args.delete_at(i)
- globals.add_path(path)
- elsif(args[i] == "-cpp_out")
- args.delete_at(i)
- path = args.delete_at(i)
- if(path =~ /\./)
- $stderr.puts "hey! path #{path} has a \".\" char which is "
- $stderr.puts "\tnot a supported usage..."
- $stderr.puts "\tWot. Wot."
- exit!(-1)
- elsif(!path)
- $stderr.puts "hey! No cpp_out path provided."
- $stderr.puts "\tumm, you could try -cpp_out \"\""
- $stderr.puts "\tThat might do the trick"
- $stderr.puts "\tWot. Wot."
- exit!(-1)
- end
- $cpp_out = path.split(/\\|\//)
- elsif(args[i] == "-cpp_base")
- args.delete_at(i)
- path = args.delete_at(i)
- $cpp_base = File.expand_path(path)
- if(!File.exists?($cpp_base))
- $stderr.puts "output directory #{$cpp_base.inspect} does not exist."
- $stderr.puts "\tI'm not going to make that! sheesh, who do you think I am?"
- $stderr.puts "\tWot. Wot."
- exit!(-1)
- end
- elsif(args[i] =~ /^-/)
- $stderr.puts "hey! unknown argument #{args[i]}."
- $stderr.puts "\tWot. Wot."
- exit!(-1)
- else
- i += 1
- end
- end
- if(!$cpp_base)
- $stderr.puts "hey! missing -cpp_base argument."
- $stderr.puts "\tWot. Wot."
- exit!(-1)
- end
- if(!$cpp_out)
- $stderr.puts "hey! missing -cpp_out argument."
- $stderr.puts "\tWot. Wot."
- exit!(-1)
- end
+ i = 0
+ while(i < args.length)
+ if(args[i] == "-I")
+ args.delete_at(i)
+ if(!args[i])
+ $stderr.puts "hey! -I is followed by nothing."
+ $stderr.puts "\tnot a supported usage..."
+ $stderr.puts "\tWot. Wot."
+ exit!(-1)
+ end
+ path = args.delete_at(i)
+ globals.add_path(path)
+ elsif(args[i] == "-cpp_out")
+ args.delete_at(i)
+ path = args.delete_at(i)
+ if(path =~ /\./)
+ $stderr.puts "hey! path #{path} has a \".\" char which is "
+ $stderr.puts "\tnot a supported usage..."
+ $stderr.puts "\tWot. Wot."
+ exit!(-1)
+ elsif(!path)
+ $stderr.puts "hey! No cpp_out path provided."
+ $stderr.puts "\tumm, you could try -cpp_out \"\""
+ $stderr.puts "\tThat might do the trick"
+ $stderr.puts "\tWot. Wot."
+ exit!(-1)
+ end
+ $cpp_out = path.split(/\\|\//)
+ elsif(args[i] == "-cpp_base")
+ args.delete_at(i)
+ path = args.delete_at(i)
+ $cpp_base = File.expand_path(path)
+ if(!File.exists?($cpp_base))
+ $stderr.puts "output directory #{$cpp_base.inspect} does not exist."
+ $stderr.puts "\tI'm not going to make that! sheesh, who do you think I am?"
+ $stderr.puts "\tWot. Wot."
+ exit!(-1)
+ end
+ elsif(args[i] == "-src_filename")
+ args.delete_at(i)
+ $src_filename = args.delete_at(i)
+ elsif(args[i] == "-h_file_path")
+ args.delete_at(i)
+ path = args.delete_at(i)
+ $h_file_path = File.expand_path(path)
+ if(!File.exists?(File.dirname($h_file_path)))
+ $stderr.puts "directory of output #{$h_file_path.inspect} does not exist."
+ $stderr.puts "\tI'm not going to make that! sheesh, who do you think I am?"
+ $stderr.puts "\tWot. Wot."
+ exit!(-1)
+ end
+ elsif(args[i] == "-cc_file_path")
+ args.delete_at(i)
+ path = args.delete_at(i)
+ $cc_file_path = File.expand_path(path)
+ if(!File.exists?(File.dirname($cc_file_path)))
+ $stderr.puts "directory of output #{$cc_file_path.inspect} does not exist."
+ $stderr.puts "\tI'm not going to make that! sheesh, who do you think I am?"
+ $stderr.puts "\tWot. Wot."
+ exit!(-1)
+ end
+ elsif(args[i] =~ /^-/)
+ $stderr.puts "hey! unknown argument #{args[i]}."
+ $stderr.puts "\tWot. Wot."
+ exit!(-1)
+ else
+ i += 1
+ end
+ end
+ if ($cpp_base && $cpp_out) == ($src_filename && $h_file_path && $cc_file_path)
+ $stderr.puts "hey! I'm not sure where to write the output files!"
+ exit!(-1)
+ end
end
def format_pipeline(output)
read_in, write_in = IO.pipe()
@@ -67,39 +84,41 @@
[child, write_in]
end
def build(filename,globals_template)
- globals = Globals.new()
- globals_template.paths.each do |path|
- globals.add_path(path)
- end
- filename = File.expand_path(filename)
- q_file = QFile.parse(filename)
- output_file = q_file.q_eval(globals)
- q_filename = File.basename(filename)
- rel_path = ($cpp_out + [q_filename]).join("/")
+ globals = Globals.new()
+ globals_template.paths.each do |path|
+ globals.add_path(path)
+ end
+ filename = File.expand_path(filename)
+ q_file = QFile.parse(filename)
+ output_file = q_file.q_eval(globals)
+ q_filename = File.basename(filename)
- FileUtils.mkdir_p(Pathname.new($cpp_base) + $cpp_out.join("/"))
+ if $cpp_base && $cpp_out
+ $src_filename = ($cpp_out + [q_filename]).join("/")
+ $h_file_path = $cpp_base + "/" + $src_filename + ".h"
+ $cc_file_path = $cpp_base + "/" + $src_filename + ".cc"
+ FileUtils.mkdir_p(Pathname.new($cpp_base) + $cpp_out.join("/"))
+ end
- cpp_tree = output_file.make_cpp_tree(rel_path)
+ cpp_tree = output_file.make_cpp_tree($src_filename)
- h_file_path = $cpp_base + "/" + rel_path + ".h"
- cc_file_path = $cpp_base + "/" + rel_path + ".cc"
- cpp_tree.add_cc_include((rel_path + ".h").inspect)
- cpp_tree.add_cc_include("aos/common/byteorder.h".inspect)
- cpp_tree.add_cc_include("<inttypes.h>")
- cpp_tree.add_cc_include("aos/common/queue_types.h".inspect)
+ cpp_tree.add_cc_include(($src_filename + ".h").inspect)
+ cpp_tree.add_cc_include("aos/common/byteorder.h".inspect)
+ cpp_tree.add_cc_include("<inttypes.h>")
+ cpp_tree.add_cc_include("aos/common/queue_types.h".inspect)
cpp_tree.add_cc_include("aos/common/once.h".inspect)
cpp_tree.add_cc_include("aos/common/logging/logging_printf_formats.h".inspect)
- cpp_tree.add_cc_using("::aos::to_network")
- cpp_tree.add_cc_using("::aos::to_host")
+ cpp_tree.add_cc_using("::aos::to_network")
+ cpp_tree.add_cc_using("::aos::to_host")
- header_file = WriteIffChanged.new(h_file_path)
- cc_file = WriteIffChanged.new(cc_file_path)
+ header_file = WriteIffChanged.new($h_file_path)
+ cc_file = WriteIffChanged.new($cc_file_path)
header_child, header_output = format_pipeline(header_file)
cc_child, cc_output = format_pipeline(cc_file)
- cpp_tree.write_header_file($cpp_base,header_output)
- cpp_tree.write_cc_file($cpp_base,cc_output)
- header_output.close()
- cc_output.close()
+ cpp_tree.write_header_file($cpp_base,header_output)
+ cpp_tree.write_cc_file($cpp_base,cc_output)
+ header_output.close()
+ cc_output.close()
if !Process.wait2(cc_child)[1].success?
$stderr.puts "Formatting cc file failed."
exit 1
@@ -112,20 +131,20 @@
cc_file.close()
end
begin
- args = ARGV.dup
- globals = Globals.new()
- parse_args(globals,args)
- if(args.length == 0)
- $stderr.puts "hey! you want me to do something,"
- $stderr.puts "\tbut you gave me no q files to build!"
- $stderr.puts "\tWot. Wot."
- exit!(-1)
- end
- args.each do |filename|
- build(filename,globals)
- end
- exit(0)
+ args = ARGV.dup
+ globals = Globals.new()
+ parse_args(globals,args)
+ if(args.length == 0)
+ $stderr.puts "hey! you want me to do something,"
+ $stderr.puts "\tbut you gave me no q files to build!"
+ $stderr.puts "\tWot. Wot."
+ exit!(-1)
+ end
+ args.each do |filename|
+ build(filename,globals)
+ end
+ exit(0)
rescue QError => e
- $stderr.print(e.to_s)
- exit!(-1)
+ $stderr.print(e.to_s)
+ exit!(-1)
end