From a7ebe54eb1cc09cc50cf97af8436835ead4cbbee Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Sat, 3 Nov 2018 18:18:47 -0700 Subject: Conformance tests work under Bazel. --- tools/upbc.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'tools/upbc.lua') diff --git a/tools/upbc.lua b/tools/upbc.lua index 8ac4f73..adea373 100644 --- a/tools/upbc.lua +++ b/tools/upbc.lua @@ -13,11 +13,17 @@ local make_c_api = require "make_c_api" local upb = require "upb" local generate_upbdefs = false +local outdir = "." -for _, argument in ipairs(arg) do +i = 1 +while i <= #arg do + argument = arg[i] if argument.sub(argument, 1, 2) == "--" then if argument == "--generate-upbdefs" then generate_upbdefs = true + elseif argument == "--outdir" then + i = i + 1 + outdir = arg[i] else print("Unknown flag: " .. argument) return 1 @@ -29,6 +35,7 @@ for _, argument in ipairs(arg) do end src = argument end + i = i + 1 end if not src then @@ -40,6 +47,11 @@ function strip_proto(filename) return string.gsub(filename, '%.proto$','') end +local function open(filename) + local full_name = outdir .. "/" .. filename + return assert(io.open(full_name, "w"), "couldn't open " .. full_name) +end + -- Open input/output files. local f = assert(io.open(src, "r"), "couldn't open input file " .. src) local descriptor = f:read("*all") @@ -67,8 +79,8 @@ for _, file in ipairs(files) do if generate_upbdefs then -- Legacy generated defs. - local hfile = assert(io.open(hfilename, "w"), "couldn't open " .. hfilename) - local cfile = assert(io.open(cfilename, "w"), "couldn't open " .. cfilename) + local hfile = open(hfilename) + local cfile = open(cfilename) local happend = dump_cinit.file_appender(hfile) local cappend = dump_cinit.file_appender(cfile) @@ -90,8 +102,8 @@ for _, file in ipairs(files) do print(string.format(" cfilename=%s", cfilename)) end - local hfile = assert(io.open(hfilename, "w"), "couldn't open " .. hfilename) - local cfile = assert(io.open(cfilename, "w"), "couldn't open " .. cfilename) + local hfile = open(hfilename) + local cfile = open(cfilename) local happend = dump_cinit.file_appender(hfile) local cappend = dump_cinit.file_appender(cfile) -- cgit v1.2.3