From 615f2ff77b976fbac34006bb802742dbacf2078f Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 17 Apr 2023 14:57:36 -0400 Subject: [PATCH] Fix Dynamic Bridge example compilation (#26129) * Make dynamic bridge app compile again * Make sure dynamic bridge builds are in CI * Update unit tests * Add license blurb * Restyle * Remove extra namespace usage * Make sure we allow ValueAssign.h to use std::string * Fix regex syntax * Fix naming of output app --- .../workflows/examples-linux-standalone.yaml | 11 +++++ examples/dynamic-bridge-app/linux/BUILD.gn | 3 +- examples/dynamic-bridge-app/linux/main.cpp | 12 ++--- .../bridge/BridgeClustersGlobalStructs.jinja | 13 +++--- .../bridge/BridgeGlobalStructs.h | 1 + .../bridge/BridgeGlobalStructs.h | 1 + .../bridge/BridgeGlobalStructs.h | 9 ++-- .../bridge/BridgeGlobalStructs.h | 1 + .../bridge/BridgeGlobalStructs.h | 1 + scripts/tools/check_includes_config.py | 1 + src/lib/assign/BUILD.gn | 22 +++++++++ src/lib/assign/ValueAssign.h | 45 +++++++++++++++++++ 12 files changed, 103 insertions(+), 17 deletions(-) create mode 100644 src/lib/assign/BUILD.gn create mode 100644 src/lib/assign/ValueAssign.h diff --git a/.github/workflows/examples-linux-standalone.yaml b/.github/workflows/examples-linux-standalone.yaml index fc40301b2b9249..f2931055be403e 100644 --- a/.github/workflows/examples-linux-standalone.yaml +++ b/.github/workflows/examples-linux-standalone.yaml @@ -179,6 +179,17 @@ jobs: linux debug bridge-app \ out/linux-x64-bridge/chip-bridge-app \ /tmp/bloat_reports/ + - name: Build example Dynamic Bridge + timeout-minutes: 10 + run: | + ./scripts/run_in_build_env.sh \ + "./scripts/build/build_examples.py \ + --target linux-x64-dynamic-bridge-ipv6only \ + build" + .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ + linux debug dynamic-bridge-app-ipv6only \ + out/linux-x64-dynamic-bridge-ipv6only/dynamic-chip-bridge-app \ + /tmp/bloat_reports/ - name: Build example OTA Provider timeout-minutes: 10 run: | diff --git a/examples/dynamic-bridge-app/linux/BUILD.gn b/examples/dynamic-bridge-app/linux/BUILD.gn index 03e3cb4fcee25b..52fe054ecdd571 100644 --- a/examples/dynamic-bridge-app/linux/BUILD.gn +++ b/examples/dynamic-bridge-app/linux/BUILD.gn @@ -61,6 +61,7 @@ executable("dynamic-chip-bridge-app") { "${chip_root}/examples/platform/linux:app-main", "${chip_root}/src/app/tests/suites/credentials:dac_provider", "${chip_root}/src/lib", + "${chip_root}/src/lib/assign", ] include_dirs = [ @@ -116,7 +117,7 @@ executable("dynamic-chip-bridge-app") { output_dir = root_out_dir - configs += ["${chip_root}/src:includes"] + configs += [ "${chip_root}/src:includes" ] } group("linux") { diff --git a/examples/dynamic-bridge-app/linux/main.cpp b/examples/dynamic-bridge-app/linux/main.cpp index d67b7bf0be2edf..e91f8d4d4e95ee 100644 --- a/examples/dynamic-bridge-app/linux/main.cpp +++ b/examples/dynamic-bridge-app/linux/main.cpp @@ -184,12 +184,6 @@ chip::Optional LookupClusterByName(const char * name) return chip::Optional(); } -std::unique_ptr CreateCluster(const char * name) -{ - auto id = LookupClusterByName(name); - return id.HasValue() ? CreateCluster(id.Value()) : nullptr; -} - std::unique_ptr CreateCluster(chip::ClusterId id) { for (const auto & cluster : clusters::kKnownClusters) @@ -202,6 +196,12 @@ std::unique_ptr CreateCluster(chip::ClusterId id) return nullptr; } +std::unique_ptr CreateCluster(const char * name) +{ + auto id = LookupClusterByName(name); + return id.HasValue() ? CreateCluster(id.Value()) : nullptr; +} + CHIP_ERROR TLVWriteValue(chip::TLV::TLVWriter & wr, const Span & v) { return wr.PutString(chip::TLV::AnonymousTag(), v); diff --git a/scripts/py_matter_idl/matter_idl/generators/bridge/BridgeClustersGlobalStructs.jinja b/scripts/py_matter_idl/matter_idl/generators/bridge/BridgeClustersGlobalStructs.jinja index 8486f07211fe74..548f8af5fc71e7 100644 --- a/scripts/py_matter_idl/matter_idl/generators/bridge/BridgeClustersGlobalStructs.jinja +++ b/scripts/py_matter_idl/matter_idl/generators/bridge/BridgeClustersGlobalStructs.jinja @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -15,9 +16,9 @@ struct {{struct.name}} chip::app::Clusters::detail::Structs::{{struct.name}}::DecodableType t; CHIP_ERROR err = t.Decode(reader); if(err == CHIP_NO_ERROR) { - {%- for field in struct.fields %} - {{field.name}} = t.{{field.name}}; - {%- endfor %} + {%- for field in struct.fields %} + chip::Value::Assign({{field.name}}, t.{{field.name}}); + {%- endfor %} } return err; } @@ -25,9 +26,9 @@ struct {{struct.name}} CHIP_ERROR Encode(chip::TLV::TLVWriter & writer, chip::TLV::Tag tag) const { chip::app::Clusters::detail::Structs::{{struct.name}}::Type t; - {%- for field in struct.fields %} - t.{{field.name}} = {{field.name}}; - {%- endfor %} + {%- for field in struct.fields %} + chip::Value::Assign(t.{{field.name}}, {{field.name}}); + {%- endfor %} return t.Encode(writer, tag); } diff --git a/scripts/py_matter_idl/matter_idl/tests/outputs/cluster_struct_attribute/bridge/BridgeGlobalStructs.h b/scripts/py_matter_idl/matter_idl/tests/outputs/cluster_struct_attribute/bridge/BridgeGlobalStructs.h index d3e85ed7e34601..d8fdc6c0b4556a 100644 --- a/scripts/py_matter_idl/matter_idl/tests/outputs/cluster_struct_attribute/bridge/BridgeGlobalStructs.h +++ b/scripts/py_matter_idl/matter_idl/tests/outputs/cluster_struct_attribute/bridge/BridgeGlobalStructs.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/scripts/py_matter_idl/matter_idl/tests/outputs/cluster_with_commands/bridge/BridgeGlobalStructs.h b/scripts/py_matter_idl/matter_idl/tests/outputs/cluster_with_commands/bridge/BridgeGlobalStructs.h index d3e85ed7e34601..d8fdc6c0b4556a 100644 --- a/scripts/py_matter_idl/matter_idl/tests/outputs/cluster_with_commands/bridge/BridgeGlobalStructs.h +++ b/scripts/py_matter_idl/matter_idl/tests/outputs/cluster_with_commands/bridge/BridgeGlobalStructs.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/scripts/py_matter_idl/matter_idl/tests/outputs/global_struct_attribute/bridge/BridgeGlobalStructs.h b/scripts/py_matter_idl/matter_idl/tests/outputs/global_struct_attribute/bridge/BridgeGlobalStructs.h index d448f606c747ac..19f6189f7b59b2 100644 --- a/scripts/py_matter_idl/matter_idl/tests/outputs/global_struct_attribute/bridge/BridgeGlobalStructs.h +++ b/scripts/py_matter_idl/matter_idl/tests/outputs/global_struct_attribute/bridge/BridgeGlobalStructs.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -15,8 +16,8 @@ struct LabelStruct chip::app::Clusters::detail::Structs::LabelStruct::DecodableType t; CHIP_ERROR err = t.Decode(reader); if(err == CHIP_NO_ERROR) { - label = t.label; - value = t.value; + chip::Value::Assign(label, t.label); + chip::Value::Assign(value, t.value); } return err; } @@ -24,8 +25,8 @@ struct LabelStruct CHIP_ERROR Encode(chip::TLV::TLVWriter & writer, chip::TLV::Tag tag) const { chip::app::Clusters::detail::Structs::LabelStruct::Type t; - t.label = label; - t.value = value; + chip::Value::Assign(t.label, label); + chip::Value::Assign(t.value, value); return t.Encode(writer, tag); } std::string label; diff --git a/scripts/py_matter_idl/matter_idl/tests/outputs/several_clusters/bridge/BridgeGlobalStructs.h b/scripts/py_matter_idl/matter_idl/tests/outputs/several_clusters/bridge/BridgeGlobalStructs.h index d3e85ed7e34601..d8fdc6c0b4556a 100644 --- a/scripts/py_matter_idl/matter_idl/tests/outputs/several_clusters/bridge/BridgeGlobalStructs.h +++ b/scripts/py_matter_idl/matter_idl/tests/outputs/several_clusters/bridge/BridgeGlobalStructs.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/scripts/py_matter_idl/matter_idl/tests/outputs/simple_attribute/bridge/BridgeGlobalStructs.h b/scripts/py_matter_idl/matter_idl/tests/outputs/simple_attribute/bridge/BridgeGlobalStructs.h index d3e85ed7e34601..d8fdc6c0b4556a 100644 --- a/scripts/py_matter_idl/matter_idl/tests/outputs/simple_attribute/bridge/BridgeGlobalStructs.h +++ b/scripts/py_matter_idl/matter_idl/tests/outputs/simple_attribute/bridge/BridgeGlobalStructs.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/scripts/tools/check_includes_config.py b/scripts/tools/check_includes_config.py index ac237e415deedb..9f82f3b80017df 100644 --- a/scripts/tools/check_includes_config.py +++ b/scripts/tools/check_includes_config.py @@ -33,6 +33,7 @@ '/Test', '/tests/', '/tools/', + r'/lib/assign/ValueAssign\.h', # Platforms can opt in or out. '/darwin/', diff --git a/src/lib/assign/BUILD.gn b/src/lib/assign/BUILD.gn new file mode 100644 index 00000000000000..12eec411187142 --- /dev/null +++ b/src/lib/assign/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2023 Project CHIP 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 +# +# http://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. + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +static_library("assign") { + sources = [ "ValueAssign.h" ] + + public_deps = [ "${chip_root}/src/lib/support" ] +} diff --git a/src/lib/assign/ValueAssign.h b/src/lib/assign/ValueAssign.h new file mode 100644 index 00000000000000..945777e4291548 --- /dev/null +++ b/src/lib/assign/ValueAssign.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 Project CHIP 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 + * + * http://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. + */ +#pragma once + +#include +#include + +namespace chip { +namespace Value { + +template +SRC & Assign(SRC & dest, const DEST & src) +{ + return dest = src; +} + +template <> +std::string & Assign(std::string & dest, const CharSpan & src) +{ + dest = std::string(src.begin(), src.end()); + return dest; +} + +template <> +CharSpan & Assign(CharSpan & dest, const std::string & src) +{ + dest = CharSpan(src.c_str(), src.size()); + return dest; +} + +} // namespace Value +} // namespace chip