Skip to content

Commit

Permalink
Added missing changes to nanopb.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoesch committed Jul 17, 2022
1 parent e3c4547 commit eb41ce8
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions tools/build_script_generator/scons/site_tools/nanopb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ def _nanopb_proto_actions(source, target, env, for_signature):
prefix = os.path.dirname(str(source[-1]))
srcfile = esc(os.path.relpath(str(source[0]), prefix))
include_dirs = '-I.'
for d in env['PROTOCPATH']:
d = env.GetBuildPath(d)
if not os.path.isabs(d): d = os.path.relpath(d, prefix)
include_dirs += ' -I' + esc(d)

nanopb_flags = env['NANOPBFLAGS']
if nanopb_flags:
nanopb_flags = '--source-extension=%s,--header-extension=%s,%s:.' % (".cpp", ".hpp", nanopb_flags)
else:
nanopb_flags = '--source-extension=%s,--header-extension=%s:.' % (".cpp", ".hpp")
# if nanopb_flags:
# nanopb_flags = '--source-extension=%s,--header-extension=%s,%s:.' % (".cpp", ".hpp", nanopb_flags)
# else:
# nanopb_flags = '--source-extension=%s,--header-extension=%s:.' % (".cpp", ".hpp")

return SCons.Action.CommandAction('python "$PROTOC" $PROTOCFLAGS %s --nanopb_out=blub %s %s' % (include_dirs, nanopb_flags, srcfile),
return SCons.Action.CommandAction('python "$PROTOC" $PROTOCFLAGS %s --nanopb_out=. %s %s' % (include_dirs, nanopb_flags, srcfile),
chdir = prefix)

def _nanopb_proto_emitter(target, source, env):
Expand All @@ -33,24 +29,20 @@ def _nanopb_proto_emitter(target, source, env):
header_extension = '.h' + source_extension[2:]
target.append(basename + '.pb' + header_extension)

# This is a bit of a hack. protoc include paths work the sanest
# when the working directory is the same as the source root directory.
# To get that directory in _nanopb_proto_actions, we add SConscript to
# the list of source files.

if os.path.exists(basename + '.options'):
source.append(basename + '.options')
# if os.path.exists(basename + '.options'):
# source.append(basename + '.options')

return target, source

_nanopb_proto_cpp_builder = SCons.Builder.Builder(
generator = _nanopb_proto_actions,
suffix = '.pb.cpp',
suffix = '.pb.c',
src_suffix = '.proto',
emitter = _nanopb_proto_emitter)

def blub(env, sources):
def build_proto(env, sources):
env.Alias("nanopb", env.NanopbProtoCpp(sources))
env.Default("nanopb")

def generate(env, **kw):
env['NANOPB'] = os.path.abspath(os.path.join("./", "ext/nanopb"))
Expand All @@ -61,7 +53,7 @@ def generate(env, **kw):

env['BUILDERS']['NanopbProtoCpp'] = _nanopb_proto_cpp_builder

env.AddMethod(blub, "BuildNanopbProto")
env.AddMethod(build_proto, "BuildNanopbProto")

def exists(env):
return True

0 comments on commit eb41ce8

Please sign in to comment.