Skip to content

Commit

Permalink
Switch from readline to editline (project-chip#20330)
Browse files Browse the repository at this point in the history
Readline is GPL'd software and may not be available in the build
environment.

Vendor editline which is permissively licensed and drop it in as a
replacement for readline.
  • Loading branch information
mspang authored and cpagravel committed Jul 12, 2022
1 parent f54d47d commit 24f89d2
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions build_overrides/editline.gni
Original file line number Diff line number Diff line change
@@ -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"
}
18 changes: 18 additions & 0 deletions examples/build_overrides/editline.gni
Original file line number Diff line number Diff line change
@@ -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"
}
11 changes: 7 additions & 4 deletions examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -35,10 +39,6 @@ config("config") {
]

cflags = [ "-Wconversion" ]

if (config_use_interactive_mode) {
libs = [ "readline" ]
}
}

static_library("chip-tool-utils") {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

#include "InteractiveCommands.h"

#include <readline/history.h>
#include <readline/readline.h>

#include <editline.h>
#include <iomanip>
#include <sstream>

char kInteractiveModeName[] = "";
constexpr const char * kInteractiveModePrompt = ">>> ";
Expand Down
109 changes: 109 additions & 0 deletions examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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
}
33 changes: 33 additions & 0 deletions third_party/editline/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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" ]
}
Loading

0 comments on commit 24f89d2

Please sign in to comment.