This change has several parts: 1. Resurrected tools/upbc. The code was all there but the build was broken for open-source. Now you can type "make tools/upbc" and it will build all necessary Lua modules and create a robust shell script for running upbc. 2. Changed Lua module loading to no longer rely on OS-level .so dependencies. The net effect of this is that you now only need to set LUA_PATH and LUA_CPATH; setting LD_LIBRARY_PATH or rpaths is no longer required. Downside: this drops compatibility with Lua 5.1, since it depends on a feature that only exists in Lua >=5.2 (and LuaJIT). 3. Since upbc works again, I fixed the re-generation of the descriptor files (descriptor.upb.h, descriptor.upb.c). "make genfiles" will re-generate these as well as the JIT code generator. 4. Added a Travis test target that ensures that the checked-in generated files are not out of date. I would do this for the Ragel generated file also, but we can't count on all versions of Ragel to necessarily generate identical output. 5. Changed Makefile to no longer automatically run Ragel to regenerate the JSON parser. This is unfortuante, because it's convenient when you're developing the JSON parser. However, "git clone" sometimes skews the timestamps a little bit so that "make" thinks it needs to regenerate these files for a fresh "git clone." This would normally be harmless, but if the user doesn't have Ragel installed, it makes the build fail completely. So now you have to explicitly regenerate the Ragel output. If you want to you can uncomment the auto-generation during development.pull/13171/head
parent
35923b43b5
commit
51cf616dab
12 changed files with 234 additions and 176 deletions
@ -1,146 +1,156 @@ |
|||||||
|
--[[-------------------------------------------------------------------- |
||||||
|
|
||||||
|
upb - a minimalist implementation of protocol buffers. |
||||||
|
|
||||||
|
Copyright (c) 2009 Google Inc. See LICENSE for details. |
||||||
|
Author: Josh Haberman <jhaberman@gmail.com> |
||||||
|
|
||||||
|
--------------------------------------------------------------------]]-- |
||||||
|
|
||||||
|
-- Before calling require on "upb_c", we need to load the same library |
||||||
|
-- as RTLD_GLOBAL, for the benefit of other C extensions that depend on |
||||||
|
-- C functions in the core. |
||||||
-- |
-- |
||||||
-- upb - a minimalist implementation of protocol buffers. |
-- This has to happen *before* the require call, because if the module |
||||||
-- |
-- is loaded RTLD_LOCAL first, a subsequent load as RTLD_GLOBAL won't |
||||||
-- Copyright (c) 2009 Google Inc. See LICENSE for details. |
-- have the proper effect, at least on some platforms. |
||||||
-- Author: Josh Haberman <jhaberman@gmail.com> |
package.loadlib(package.searchpath("upb_c", package.cpath), "*") |
||||||
|
|
||||||
|
local upb = require("upb_c") |
||||||
|
|
||||||
|
-- A convenience function for building/linking/freezing defs |
||||||
|
-- while maintaining their original order. |
||||||
-- |
-- |
||||||
-- Pure-Lua support functions that are part of the "upb" module. |
-- Sample usage: |
||||||
-- This file is embedded and packaged into the "upb" C module binary -- it |
-- local m1, m2 = upb.build_defs{ |
||||||
-- should not be installed or used directly! |
-- upb.MessageDef{full_name = "M1", fields = { |
||||||
|
-- upb.FieldDef{ |
||||||
return function(upb) |
-- name = "m2", |
||||||
-- A convenience function for building/linking/freezing defs |
-- number = 1, |
||||||
-- while maintaining their original order. |
-- type = upb.TYPE_MESSAGE, |
||||||
-- |
-- subdef_name = ".M2" |
||||||
-- Sample usage: |
-- }, |
||||||
-- local m1, m2 = upb.build_defs{ |
-- } |
||||||
-- upb.MessageDef{full_name = "M1", fields = { |
-- }, |
||||||
-- upb.FieldDef{ |
-- upb.MessageDef{full_name = "M2"} |
||||||
-- name = "m2", |
-- } |
||||||
-- number = 1, |
upb.build_defs = function(defs) |
||||||
-- type = upb.TYPE_MESSAGE, |
upb.SymbolTable(defs) |
||||||
-- subdef_name = ".M2" |
-- Lua 5.2 puts unpack in the table library. |
||||||
-- }, |
return (unpack or table.unpack)(defs) |
||||||
-- } |
end |
||||||
-- }, |
|
||||||
-- upb.MessageDef{full_name = "M2"} |
|
||||||
-- } |
|
||||||
upb.build_defs = function(defs) |
|
||||||
upb.SymbolTable(defs) |
|
||||||
-- Lua 5.2 puts unpack in the table library. |
|
||||||
return (unpack or table.unpack)(defs) |
|
||||||
end |
|
||||||
|
|
||||||
local ipairs_iter = function(array, last_index) |
local ipairs_iter = function(array, last_index) |
||||||
local next_index = last_index + 1 |
local next_index = last_index + 1 |
||||||
if next_index > #array then |
if next_index > #array then |
||||||
return nil |
return nil |
||||||
end |
|
||||||
return next_index, array[next_index] |
|
||||||
end |
end |
||||||
|
return next_index, array[next_index] |
||||||
|
end |
||||||
|
|
||||||
-- For iterating over the indexes and values of a upb.Array. |
-- For iterating over the indexes and values of a upb.Array. |
||||||
-- |
-- |
||||||
-- for i, val in upb.ipairs(array) do |
-- for i, val in upb.ipairs(array) do |
||||||
-- -- ... |
-- -- ... |
||||||
-- end |
-- end |
||||||
upb.ipairs = function(array) |
upb.ipairs = function(array) |
||||||
return ipairs_iter, array, 0 |
return ipairs_iter, array, 0 |
||||||
end |
end |
||||||
|
|
||||||
local set_named = function(obj, init) |
local set_named = function(obj, init) |
||||||
for k, v in pairs(init) do |
for k, v in pairs(init) do |
||||||
local func = obj["set_" .. k] |
local func = obj["set_" .. k] |
||||||
if not func then |
if not func then |
||||||
error("Cannot set member: " .. k) |
error("Cannot set member: " .. k) |
||||||
end |
|
||||||
func(obj, v) |
|
||||||
end |
end |
||||||
|
func(obj, v) |
||||||
end |
end |
||||||
|
end |
||||||
|
|
||||||
|
-- Capture references to the functions we're wrapping. |
||||||
|
local RealFieldDef = upb.FieldDef |
||||||
|
local RealEnumDef = upb.EnumDef |
||||||
|
local RealMessageDef = upb.MessageDef |
||||||
|
local RealSymbolTable = upb.SymbolTable |
||||||
|
|
||||||
-- Capture references to the functions we're wrapping. |
-- FieldDef constructor; a wrapper around the real constructor that can |
||||||
local RealFieldDef = upb.FieldDef |
-- set initial properties. |
||||||
local RealEnumDef = upb.EnumDef |
-- |
||||||
local RealMessageDef = upb.MessageDef |
-- User can specify initialization values like so: |
||||||
local RealSymbolTable = upb.SymbolTable |
-- upb.FieldDef{label=upb.LABEL_REQUIRED, name="my_field", number=5, |
||||||
|
-- type=upb.TYPE_INT32, default_value=12, type_name="Foo"} |
||||||
-- FieldDef constructor; a wrapper around the real constructor that can |
upb.FieldDef = function(init) |
||||||
-- set initial properties. |
local f = RealFieldDef() |
||||||
-- |
|
||||||
-- User can specify initialization values like so: |
if init then |
||||||
-- upb.FieldDef{label=upb.LABEL_REQUIRED, name="my_field", number=5, |
-- Other members are often dependent on type, so set that first. |
||||||
-- type=upb.TYPE_INT32, default_value=12, type_name="Foo"} |
if init.type then |
||||||
upb.FieldDef = function(init) |
f:set_type(init.type) |
||||||
local f = RealFieldDef() |
init.type = nil |
||||||
|
|
||||||
if init then |
|
||||||
-- Other members are often dependent on type, so set that first. |
|
||||||
if init.type then |
|
||||||
f:set_type(init.type) |
|
||||||
init.type = nil |
|
||||||
end |
|
||||||
|
|
||||||
set_named(f, init) |
|
||||||
end |
end |
||||||
|
|
||||||
return f |
set_named(f, init) |
||||||
end |
end |
||||||
|
|
||||||
|
return f |
||||||
|
end |
||||||
|
|
||||||
-- MessageDef constructor; a wrapper around the real constructor that can |
|
||||||
-- set initial properties. |
|
||||||
-- |
|
||||||
-- User can specify initialization values like so: |
|
||||||
-- upb.MessageDef{full_name="MyMessage", extstart=8000, fields={...}} |
|
||||||
upb.MessageDef = function(init) |
|
||||||
local m = RealMessageDef() |
|
||||||
|
|
||||||
if init then |
|
||||||
for _, f in pairs(init.fields or {}) do |
|
||||||
m:add(f) |
|
||||||
end |
|
||||||
init.fields = nil |
|
||||||
|
|
||||||
set_named(m, init) |
-- MessageDef constructor; a wrapper around the real constructor that can |
||||||
|
-- set initial properties. |
||||||
|
-- |
||||||
|
-- User can specify initialization values like so: |
||||||
|
-- upb.MessageDef{full_name="MyMessage", extstart=8000, fields={...}} |
||||||
|
upb.MessageDef = function(init) |
||||||
|
local m = RealMessageDef() |
||||||
|
|
||||||
|
if init then |
||||||
|
for _, f in pairs(init.fields or {}) do |
||||||
|
m:add(f) |
||||||
end |
end |
||||||
|
init.fields = nil |
||||||
|
|
||||||
return m |
set_named(m, init) |
||||||
end |
end |
||||||
|
|
||||||
-- EnumDef constructor; a wrapper around the real constructor that can |
return m |
||||||
-- set initial properties. |
end |
||||||
-- |
|
||||||
-- User can specify initialization values like so: |
-- EnumDef constructor; a wrapper around the real constructor that can |
||||||
-- upb.EnumDef{full_name="MyEnum", |
-- set initial properties. |
||||||
-- values={ |
-- |
||||||
-- {"FOO_VALUE_1", 1}, |
-- User can specify initialization values like so: |
||||||
-- {"FOO_VALUE_2", 2} |
-- upb.EnumDef{full_name="MyEnum", |
||||||
-- } |
-- values={ |
||||||
-- } |
-- {"FOO_VALUE_1", 1}, |
||||||
upb.EnumDef = function(init) |
-- {"FOO_VALUE_2", 2} |
||||||
local e = RealEnumDef() |
-- } |
||||||
|
-- } |
||||||
if init then |
upb.EnumDef = function(init) |
||||||
for _, val in pairs(init.values or {}) do |
local e = RealEnumDef() |
||||||
e:add(val[1], val[2]) |
|
||||||
end |
if init then |
||||||
init.values = nil |
for _, val in pairs(init.values or {}) do |
||||||
|
e:add(val[1], val[2]) |
||||||
set_named(e, init) |
|
||||||
end |
end |
||||||
|
init.values = nil |
||||||
|
|
||||||
return e |
set_named(e, init) |
||||||
end |
end |
||||||
|
|
||||||
-- SymbolTable constructor; a wrapper around the real constructor that can |
return e |
||||||
-- add an initial set of defs. |
end |
||||||
upb.SymbolTable = function(defs) |
|
||||||
local s = RealSymbolTable() |
|
||||||
|
|
||||||
if defs then |
-- SymbolTable constructor; a wrapper around the real constructor that can |
||||||
s:add(defs) |
-- add an initial set of defs. |
||||||
end |
upb.SymbolTable = function(defs) |
||||||
|
local s = RealSymbolTable() |
||||||
|
|
||||||
return s |
if defs then |
||||||
|
s:add(defs) |
||||||
end |
end |
||||||
|
|
||||||
|
return s |
||||||
end |
end |
||||||
|
|
||||||
|
return upb |
||||||
|
@ -0,0 +1,11 @@ |
|||||||
|
--[[-------------------------------------------------------------------- |
||||||
|
|
||||||
|
upb - a minimalist implementation of protocol buffers. |
||||||
|
|
||||||
|
Copyright (c) 2009 Google Inc. See LICENSE for details. |
||||||
|
Author: Josh Haberman <jhaberman@gmail.com> |
||||||
|
|
||||||
|
--------------------------------------------------------------------]]-- |
||||||
|
|
||||||
|
require "upb" |
||||||
|
return require "upb.pb_c" |
@ -0,0 +1,11 @@ |
|||||||
|
--[[-------------------------------------------------------------------- |
||||||
|
|
||||||
|
upb - a minimalist implementation of protocol buffers. |
||||||
|
|
||||||
|
Copyright (c) 2009 Google Inc. See LICENSE for details. |
||||||
|
Author: Josh Haberman <jhaberman@gmail.com> |
||||||
|
|
||||||
|
--------------------------------------------------------------------]]-- |
||||||
|
|
||||||
|
require "upb" |
||||||
|
return require "upb.table_c" |
Loading…
Reference in new issue