1# Test correct relative paths and creation of intermediate directories
2# when input files are part of a multi-level directory structure:
3#
4# user@host:.../build$ nanopb_generator -D . -I ../proto ../proto/simple.proto
5# user@host:.../build$ nanopb_generator -D . -I ../proto ../proto/protobuf/any.proto
6#
7# should result in:
8#
9# |-- build
10# |   |-- protobuf
11# |   |   +-- any.pb.c
12# |   |   +-- any.pb.h
13# |   +-- simple.pb.c
14# |   +-- simple.pb.h
15# +-- proto
16#     |-- protobuf
17#     |   +-- any.proto
18#     +-- simple.proto
19
20
21Import('env')
22import os, sys
23
24# As of 0.4.2, SCons rules still go through protoc that handles paths correctly
25# by itself. To test direct nanopb_generator usage we invoke it manually here.
26env.Command(["build/protobuf/any.pb.h", "build/simple.pb.h", "build/protobuf/any.pb.c", "build/simple.pb.c",],
27            ["proto/protobuf/any.proto", "proto/simple.proto"],
28[
29    Delete("$BUILDDIR/generator_relative_paths/build"),
30    Mkdir("$BUILDDIR/generator_relative_paths/build"),
31    env['NANOPB_GENERATOR'] + " -D$BUILDDIR/generator_relative_paths/build -I$BUILDDIR/generator_relative_paths/proto $SOURCES"
32])
33
34env.Match("simple_pb_h_ok", ["build/simple.pb.h", "simple.expected"])
35env.Match("simple_pb_c_ok", ["build/simple.pb.c", "simple.expected"])
36env.Match("any_pb_h_ok", ["build/protobuf/any.pb.h", "any.expected"])
37env.Match("any_pb_c_ok", ["build/protobuf/any.pb.c", "any.expected"])
38
39# Test when not using -D
40env.Command(["test.pb.c", "test.pb.h"], "test.proto",
41            env['NANOPB_GENERATOR'] + " test.proto",
42            chdir = True)
43env.Match("test_pb_h_ok", ["test.pb.h", "test.expected"])
44env.Match("test_pb_c_ok", ["test.pb.c", "test.expected"])
45