-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pw_protobuf_compiler: Symlink options to proto root
This fixes nanopb generation for proto_library targets with the import_prefix attribute. Bug: 396230548 Change-Id: I4c869e52e172027ea3ea057e5178e2ff72fbf1a9 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/267936 Docs-Not-Needed: Ted Pudlik <[email protected]> Lint: Lint 🤖 <[email protected]> Reviewed-by: Austin Foxley <[email protected]> Commit-Queue: Ted Pudlik <[email protected]>
- Loading branch information
Showing
6 changed files
with
267 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
pw_protobuf_compiler/nanopb_test_protos/prefix_tests.options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2025 The Pigweed Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
prefixtest.Message.name max_size:64 |
20 changes: 20 additions & 0 deletions
20
pw_protobuf_compiler/nanopb_test_protos/prefix_tests.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2025 The Pigweed Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
syntax = "proto3"; | ||
|
||
package prefixtest; | ||
|
||
message Message { | ||
string name = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2025 The Pigweed Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
#include <string> | ||
|
||
#if !defined(PW_PROTOBUF_COMPILER_IMPORT) | ||
#error "This test requires specifying a value for PW_PROTOBUF_COMPILER_IMPORT!" | ||
#endif | ||
|
||
#define DEFAULT 1 | ||
#define STRIP_IMPORT_PREFIX 2 | ||
#define IMPORT_PREFIX 3 | ||
|
||
#if PW_PROTOBUF_COMPILER_IMPORT == DEFAULT | ||
#include "pw_protobuf_compiler/nanopb_test_protos/prefix_tests.pb.h" | ||
#endif | ||
|
||
#if PW_PROTOBUF_COMPILER_IMPORT == STRIP_IMPORT_PREFIX | ||
#include "prefix_tests.pb.h" | ||
#endif | ||
|
||
#if PW_PROTOBUF_COMPILER_IMPORT == IMPORT_PREFIX | ||
#include "some_prefix/prefix_tests.pb.h" | ||
#endif | ||
|
||
#include "pw_status/status.h" | ||
#include "pw_string/util.h" | ||
#include "pw_unit_test/framework.h" | ||
|
||
namespace pw::protobuf_compiler { | ||
namespace { | ||
|
||
TEST(PrefixTest, Compiles) { | ||
std::string str = "abcd"; | ||
prefixtest_Message proto = prefixtest_Message_init_default; | ||
EXPECT_EQ( | ||
pw::string::Copy(str.c_str(), proto.name, sizeof(proto.name)).status(), | ||
pw::OkStatus()); | ||
} | ||
|
||
} // namespace | ||
} // namespace pw::protobuf_compiler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters