diff --git a/.gitmodules b/.gitmodules index 6cfa9dd05e6883..8e64741bab9d0e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -250,3 +250,6 @@ url = https://github.com/bouffalolab/bl_iot_sdk_matter.git branch = bl602_release platforms = bl602 +[submodule "editline"] + path = third_party/editline/repo + url = https://github.com/troglobit/editline.git diff --git a/build_overrides/editline.gni b/build_overrides/editline.gni new file mode 100644 index 00000000000000..cd3133fdc3397b --- /dev/null +++ b/build_overrides/editline.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +declare_args() { + # Root directory for editline. + editline_root = "//third_party/editline" +} diff --git a/examples/build_overrides/editline.gni b/examples/build_overrides/editline.gni new file mode 100644 index 00000000000000..7f20e53733eeb7 --- /dev/null +++ b/examples/build_overrides/editline.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +declare_args() { + # Root directory for editline. + editline_root = "//third_party/connectedhomeip/third_party/editline" +} diff --git a/examples/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn index 7edc8fdeb48506..e8124b1902cd62 100644 --- a/examples/chip-tool/BUILD.gn +++ b/examples/chip-tool/BUILD.gn @@ -19,6 +19,10 @@ import("${chip_root}/build/chip/tools.gni") import("${chip_root}/examples/chip-tool/chip-tool.gni") import("${chip_root}/src/lib/core/core.gni") +if (config_use_interactive_mode) { + import("//build_overrides/editline.gni") +} + assert(chip_build_tools) config("config") { @@ -35,10 +39,6 @@ config("config") { ] cflags = [ "-Wconversion" ] - - if (config_use_interactive_mode) { - libs = [ "readline" ] - } } static_library("chip-tool-utils") { @@ -71,8 +71,11 @@ static_library("chip-tool-utils") { "config/PersistentStorage.cpp", ] + deps = [] + if (config_use_interactive_mode) { sources += [ "commands/interactive/InteractiveCommands.cpp" ] + deps += [ "${editline_root}:editline" ] } if (config_enable_yaml_tests) { diff --git a/examples/chip-tool/commands/interactive/InteractiveCommands.cpp b/examples/chip-tool/commands/interactive/InteractiveCommands.cpp index d43ccdd992e227..24ce39d5431691 100644 --- a/examples/chip-tool/commands/interactive/InteractiveCommands.cpp +++ b/examples/chip-tool/commands/interactive/InteractiveCommands.cpp @@ -18,8 +18,7 @@ #include "InteractiveCommands.h" -#include -#include +#include char kInteractiveModeName[] = ""; constexpr const char * kInteractiveModePrompt = ">>> "; diff --git a/examples/darwin-framework-tool/BUILD.gn b/examples/darwin-framework-tool/BUILD.gn new file mode 100644 index 00000000000000..5469315293126e --- /dev/null +++ b/examples/darwin-framework-tool/BUILD.gn @@ -0,0 +1,109 @@ +# Copyright (c) 2022 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") + +import("${chip_root}/build/chip/tools.gni") +import("${chip_root}/examples//chip-tool/chip-tool.gni") + +if (config_use_interactive_mode) { + import("//build_overrides/editline.gni") +} + +assert(chip_build_tools) + +config("config") { + include_dirs = [ + ".", + "${chip_root}/src/darwin/Framework/CHIP/zap-generated", + "${chip_root}/src/darwin/Framework/CHIP", + "${chip_root}/examples/darwin-framework-tool/commands/common", + "${chip_root}/zzz_generated/darwin-framework-tool", + "${chip_root}/zzz_generated/controller-clusters", + "${chip_root}/examples/chip-tool/commands/clusters/ComplexArgument.h", + "/tmp/macos_framework_output", + ] + + framework_dirs = [ "/tmp/macos_framework_output" ] + + defines = [ + "CONFIG_ENABLE_YAML_TESTS=${config_enable_yaml_tests}", + "CONFIG_USE_INTERACTIVE_MODE=${config_use_interactive_mode}", + ] + + cflags = [ + "-Wconversion", + "-fobjc-arc", + ] +} + +executable("darwin-framework-tool") { + sources = [ + # We have to include privilege-storage.cpp here, not in the "Darwin + # framework" library, because otherwise the weak symbols from + # RequiredPrivilege.cpp mean we never actually pull in the function from + # privilege-storage.cpp. + "${chip_root}/src/app/util/privilege-storage.cpp", + "${chip_root}/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp", + "${chip_root}/zzz_generated/controller-clusters/zap-generated/CHIPClusters.h", + "commands/clusters/ClusterCommandBridge.h", + "commands/clusters/ModelCommandBridge.mm", + "commands/clusters/ReportCommandBridge.h", + "commands/clusters/WriteAttributeCommandBridge.h", + "commands/common/CHIPCommandBridge.mm", + "commands/common/CHIPCommandStorageDelegate.mm", + "commands/common/CHIPToolKeypair.mm", + "commands/common/MTRError.mm", + "commands/common/MTRError_Utils.h", + "commands/common/MTRLogging.h", + "commands/pairing/Commands.h", + "commands/pairing/OpenCommissioningWindowCommand.h", + "commands/pairing/OpenCommissioningWindowCommand.mm", + "commands/pairing/PairingCommandBridge.mm", + "commands/pairing/PairingDelegateBridge.mm", + "commands/payload/SetupPayloadParseCommand.mm", + "commands/storage/Commands.h", + "commands/storage/StorageManagementCommand.mm", + "main.mm", + ] + + if (config_use_interactive_mode) { + sources += [ "commands/interactive/InteractiveCommands.mm" ] + deps += [ "${editline_root}:editline" ] + } + + if (config_enable_yaml_tests) { + sources += [ "${chip_root}/zzz_generated/darwin-framework-tool/zap-generated/cluster/MTRTestClustersObjc.mm" ] + } + + deps = [ + "${chip_root}/examples/chip-tool:chip-tool-utils", + "${chip_root}/src/app/server", + "${chip_root}/src/darwin/Framework/CHIP:static-matter", + "${chip_root}/src/lib", + "${chip_root}/src/platform", + "${chip_root}/third_party/inipp", + "${chip_root}/third_party/jsoncpp", + ] + + frameworks = [ + "Matter.framework", + "Security.framework", + ] + + public_configs = [ ":config" ] + + output_dir = root_out_dir +} diff --git a/third_party/editline/BUILD.gn b/third_party/editline/BUILD.gn new file mode 100644 index 00000000000000..9eb8a2cd495fda --- /dev/null +++ b/third_party/editline/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2022 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. + +config("editline_config") { + include_dirs = [ "repo/include" ] +} + +static_library("editline") { + public = [ "repo/include/editline.h" ] + + sources = [ + "repo/src/complete.c", + "repo/src/editline.c", + "repo/src/editline.h", + "repo/src/sysunix.c", + "repo/src/unix.h", + ] + + public_configs = [ ":editline_config" ] + + include_dirs = [ "include" ] +} diff --git a/third_party/editline/include/config.h b/third_party/editline/include/config.h new file mode 100644 index 00000000000000..b4dad5de3a8444 --- /dev/null +++ b/third_party/editline/include/config.h @@ -0,0 +1,171 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if the `closedir' function returns void instead of int. */ +/* #undef CLOSEDIR_VOID */ + +/* Define to include ANSI arrow keys support. */ +#define CONFIG_ANSI_ARROWS 1 + +/* Define to enable EOF (Ctrl-D) key. */ +#define CONFIG_EOF 1 + +/* Define to enable SIGINT (Ctrl-C) key. */ +#define CONFIG_SIGINT 1 + +/* Define to enable SIGSTOP (Ctrl-Z) key. */ +/* #undef CONFIG_SIGSTOP */ + +/* Define to enable terminal bell on completion. */ +/* #undef CONFIG_TERMINAL_BELL */ + +/* Define to skip duplicate lines in the scrollback history. */ +#define CONFIG_UNIQUE_HISTORY 1 + +/* Define to use the termcap library for terminal size. */ +/* #undef CONFIG_USE_TERMCAP */ + +/* Define to 1 if `TIOCGWINSZ' requires . */ +#define GWINSZ_IN_SYS_IOCTL 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +#define HAVE_DIRENT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `curses' library (-lcurses). */ +/* #undef HAVE_LIBCURSES */ + +/* Define to 1 if you have the `ncurses' library (-lncurses). */ +/* #undef HAVE_LIBNCURSES */ + +/* Define to 1 if you have the `termcap' library (-ltermcap). */ +/* #undef HAVE_LIBTERMCAP */ + +/* Define to 1 if you have the `terminfo' library (-lterminfo). */ +/* #undef HAVE_LIBTERMINFO */ + +/* Define to 1 if you have the `tinfo' library (-ltinfo). */ +/* #undef HAVE_LIBTINFO */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_MALLOC_H */ + +/* Define to 1 if you have the header file, and it defines `DIR'. */ +/* #undef HAVE_NDIR_H */ + +/* Define to 1 if you have the `perror' function. */ +#define HAVE_PERROR 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SGTTY_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if `stat' has the bug that it succeeds when given the + zero-length file name argument. */ +/* #undef HAVE_STAT_EMPTY_STRING_BUG */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strchr' function. */ +#define HAVE_STRCHR 1 + +/* Define to 1 if you have the `strdup' function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strrchr' function. */ +#define HAVE_STRRCHR 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_DIR_H */ + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_NDIR_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the `tcgetattr' function. */ +#define HAVE_TCGETATTR 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TERMCAP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TERMIOS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TERMIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if `lstat' dereferences a symlink specified with a trailing + slash. */ +#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1 + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "editline" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "https://github.com/troglobit/editline/issues" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "editline" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "editline 1.17.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "editline" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.17.1" + +/* Define to 1 if the `S_IS*' macros in do not work properly. */ +/* #undef STAT_MACROS_BROKEN */ + +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ +#define STDC_HEADERS 1 + +/* Default to UNIX backend, should be detected. */ +#define SYS_UNIX 1 + +/* Version number of package */ +#define VERSION "1.17.1" + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ diff --git a/third_party/editline/repo b/third_party/editline/repo new file mode 160000 index 00000000000000..9fa05ba3841f3a --- /dev/null +++ b/third_party/editline/repo @@ -0,0 +1 @@ +Subproject commit 9fa05ba3841f3a7776b0b3645a3a92f32259d988