From bda22dd0f079cfd909fcc69ff366a5691a7061ee Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 28 Apr 2020 17:07:46 -0400 Subject: [PATCH 01/10] Add FDE url_launcher, to have something to test the CI against --- .../url_launcher/url_launcher/linux/Makefile | 108 ++++++++++++++ .../url_launcher/linux/url_launcher_plugin.cc | 136 ++++++++++++++++++ .../url_launcher/linux/url_launcher_plugin.h | 38 +++++ .../url_launcher/url_launcher/pubspec.yaml | 2 + 4 files changed, 284 insertions(+) create mode 100644 packages/url_launcher/url_launcher/linux/Makefile create mode 100644 packages/url_launcher/url_launcher/linux/url_launcher_plugin.cc create mode 100644 packages/url_launcher/url_launcher/linux/url_launcher_plugin.h diff --git a/packages/url_launcher/url_launcher/linux/Makefile b/packages/url_launcher/url_launcher/linux/Makefile new file mode 100644 index 000000000000..843d87813129 --- /dev/null +++ b/packages/url_launcher/url_launcher/linux/Makefile @@ -0,0 +1,108 @@ +# Copyright 2019 Google LLC +# +# 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. + +# The name of the plugin. +PLUGIN_NAME=url_launcher_plugin +# This is changed from the stock Makefile since the class name doesn't match +# the plugin name. This will need to be made more flexible when Linux plugin +# structure is revisited. +PLUGIN_SOURCE_NAME=url_launcher_plugin +# Any files other than the plugin class files that need to be compiled. +EXTRA_SOURCES= +# Extra flags (e.g., for library dependencies). +SYSTEM_LIBRARIES= +EXTRA_CXXFLAGS= +EXTRA_CPPFLAGS= +EXTRA_LDFLAGS= + +# Default build type. For a release build, set BUILD=release. +# Currently this only sets NDEBUG, which is used to control the flags passed +# to the Flutter engine in the example shell, and not the complation settings +# (e.g., optimization level) of the C++ code. +BUILD=debug + +# Plugins must be provided a populated flutter/ephemeral/ dir. Normally this +# would be the ephemeral directory of the application using the plugin. +ifeq ($(strip $(FLUTTER_EPHEMERAL_DIR)),) +$(error FLUTTER_EPHEMERAL_DIR must be provided) +endif + +# Dependency locations +# Default to building in the plugin directory. +OUT_DIR=$(CURDIR)/../build/linux +# Sharing an OUT_DIR will be common, so use a subdirectory for intermediates. +PLUGIN_OUT_DIR=$(OUT_DIR)/$(PLUGIN_NAME) +OBJ_DIR=$(PLUGIN_OUT_DIR)/obj/$(BUILD) + +# Flutter library +FLUTTER_LIB_NAME=flutter_linux_glfw +FLUTTER_LIB=$(FLUTTER_EPHEMERAL_DIR)/lib$(FLUTTER_LIB_NAME).so + +# Add relevant code from the wrapper library, which is intended to be statically +# built into the plugin. +# Use abspath for the wrapper root, which can contain relative paths; the +# intermediate build files will be based on the source path, which will cause +# issues if they start with one or more '../'s. +WRAPPER_ROOT=$(abspath $(FLUTTER_EPHEMERAL_DIR)/cpp_client_wrapper_glfw) +# TODO: Once JSON codec files are merged, make a PLUGIN_CODEC variable in the +# top section. For now, using JSON codec would require changes here. +WRAPPER_SOURCES= \ + $(WRAPPER_ROOT)/engine_method_result.cc \ + $(WRAPPER_ROOT)/plugin_registrar.cc \ + $(WRAPPER_ROOT)/standard_codec.cc + +# Use abspath for extra sources, which may also contain relative paths (see +# note above about WRAPPER_ROOT). +SOURCES=$(PLUGIN_SOURCE_NAME).cc $(WRAPPER_SOURCES) $(abspath $(EXTRA_SOURCES)) + +WRAPPER_INCLUDE_DIR=$(WRAPPER_ROOT)/include +INCLUDE_DIRS=$(FLUTTER_EPHEMERAL_DIR) $(WRAPPER_INCLUDE_DIR) + +# Build settings +CXX=clang++ +CXXFLAGS.release=-DNDEBUG +CXXFLAGS=-std=c++14 -Wall -Werror -fPIC -fvisibility=hidden \ + -DFLUTTER_PLUGIN_IMPL $(CXXFLAGS.$(BUILD)) $(EXTRA_CXXFLAGS) +CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS)) $(EXTRA_CPPFLAGS) +LDFLAGS=-shared -L$(FLUTTER_EPHEMERAL_DIR) -l$(FLUTTER_LIB_NAME) $(EXTRA_LDFLAGS) + +# Final output files that will be used by applications. +LIBRARY_OUT=$(OUT_DIR)/lib$(PLUGIN_NAME).so + +# Intermediate files. +OBJ_FILES=$(SOURCES:%.cc=$(OBJ_DIR)/%.o) +DEPENDENCY_FILES=$(OBJ_FILES:%.o=%.d) + +# Targets + +.PHONY: all +all: $(PLUGIN_NAME) + +.PHONY: $(PLUGIN_NAME) +$(PLUGIN_NAME) : $(LIBRARY_OUT) + +$(LIBRARY_OUT): $(OBJ_FILES) + mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ + +-include $(DEPENDENCY_FILES) + +$(OBJ_DIR)/%.o : %.cc + mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -c $< -o $@ + +.PHONY: clean +clean: + rm -f $(LIBRARY_OUT) + rm -rf $(PLUGINOUT_DIR) diff --git a/packages/url_launcher/url_launcher/linux/url_launcher_plugin.cc b/packages/url_launcher/url_launcher/linux/url_launcher_plugin.cc new file mode 100644 index 000000000000..da69153c6bd4 --- /dev/null +++ b/packages/url_launcher/url_launcher/linux/url_launcher_plugin.cc @@ -0,0 +1,136 @@ +// Copyright 2019 Google LLC +// +// 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. + +#include "url_launcher_plugin.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace { + +using flutter::EncodableMap; +using flutter::EncodableValue; + +// Returns true if |s| starts with |prefix|. +bool StartsWith(const std::string &s, const std::string &prefix) { + return s.compare(0, prefix.size(), prefix) == 0; +} + +class UrlLauncherPlugin : public flutter::Plugin { + public: + static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar); + + virtual ~UrlLauncherPlugin(); + + private: + UrlLauncherPlugin(); + + // Called when a method is called on the plugin's channel; + void HandleMethodCall( + const flutter::MethodCall &method_call, + std::unique_ptr> result); +}; + +// static +void UrlLauncherPlugin::RegisterWithRegistrar( + flutter::PluginRegistrar *registrar) { + auto channel = std::make_unique>( + registrar->messenger(), "plugins.flutter.io/url_launcher", + &flutter::StandardMethodCodec::GetInstance()); + + // Uses new instead of make_unique due to private constructor. + std::unique_ptr plugin(new UrlLauncherPlugin()); + + channel->SetMethodCallHandler( + [plugin_pointer = plugin.get()](const auto &call, auto result) { + plugin_pointer->HandleMethodCall(call, std::move(result)); + }); + + registrar->AddPlugin(std::move(plugin)); +} + +UrlLauncherPlugin::UrlLauncherPlugin() = default; + +UrlLauncherPlugin::~UrlLauncherPlugin() = default; + +void UrlLauncherPlugin::HandleMethodCall( + const flutter::MethodCall &method_call, + std::unique_ptr> result) { + if (method_call.method_name().compare("launch") == 0) { + std::string url; + if (method_call.arguments() && method_call.arguments()->IsMap()) { + const EncodableMap &arguments = method_call.arguments()->MapValue(); + auto url_it = arguments.find(EncodableValue("url")); + if (url_it != arguments.end()) { + url = url_it->second.StringValue(); + } + } + if (url.empty()) { + result->Error("argument_error", "No URL provided"); + return; + } + + pid_t pid = fork(); + if (pid == 0) { + execl("/usr/bin/xdg-open", "xdg-open", url.c_str(), nullptr); + exit(1); + } + int status = 0; + waitpid(pid, &status, 0); + if (status != 0) { + std::ostringstream error_message; + error_message << "Failed to open " << url << ": error " << status; + result->Error("open_error", error_message.str()); + return; + } + result->Success(); + } else if (method_call.method_name().compare("canLaunch") == 0) { + std::string url; + if (method_call.arguments() && method_call.arguments()->IsMap()) { + const EncodableMap &arguments = method_call.arguments()->MapValue(); + auto url_it = arguments.find(EncodableValue("url")); + if (url_it != arguments.end()) { + url = url_it->second.StringValue(); + } + } + if (url.empty()) { + result->Error("argument_error", "No URL provided"); + return; + } + + flutter::EncodableValue response( + StartsWith(url, "https:") || StartsWith(url, "http:") || + StartsWith(url, "ftp:") || StartsWith(url, "file:")); + result->Success(&response); + return; + } else { + result->NotImplemented(); + } +} + +} // namespace + +void UrlLauncherPluginRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar) { + UrlLauncherPlugin::RegisterWithRegistrar( + flutter::PluginRegistrarManager::GetInstance() + ->GetRegistrar(registrar)); +} diff --git a/packages/url_launcher/url_launcher/linux/url_launcher_plugin.h b/packages/url_launcher/url_launcher/linux/url_launcher_plugin.h new file mode 100644 index 000000000000..b88e2d5064d2 --- /dev/null +++ b/packages/url_launcher/url_launcher/linux/url_launcher_plugin.h @@ -0,0 +1,38 @@ +// Copyright 2019 Google LLC +// +// 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. +#ifndef PLUGINS_FLUTTER_PLUGINS_URL_LAUNCHER_FDE_LINUX_URL_LAUNCHER_FDE_PLUGIN_H_ +#define PLUGINS_FLUTTER_PLUGINS_URL_LAUNCHER_FDE_LINUX_URL_LAUNCHER_FDE_PLUGIN_H_ + +// A plugin to control a native menubar. + +#include + +#ifdef FLUTTER_PLUGIN_IMPL +#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default"))) +#else +#define FLUTTER_PLUGIN_EXPORT +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +FLUTTER_PLUGIN_EXPORT void UrlLauncherPluginRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // PLUGINS_FLUTTER_PLUGINS_URL_LAUNCHER_FDE_LINUX_URL_LAUNCHER_FDE_PLUGIN_H_ diff --git a/packages/url_launcher/url_launcher/pubspec.yaml b/packages/url_launcher/url_launcher/pubspec.yaml index 4d1fbafa5095..162d1fb58c4b 100644 --- a/packages/url_launcher/url_launcher/pubspec.yaml +++ b/packages/url_launcher/url_launcher/pubspec.yaml @@ -16,6 +16,8 @@ flutter: default_package: url_launcher_web macos: default_package: url_laucher_macos + linux: + pluginClass: UrlLauncherPlugin dependencies: flutter: From e737ec580ac9f6e3e7379212027a3ac2eabcac98 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 28 Apr 2020 17:08:07 -0400 Subject: [PATCH 02/10] Disable SMS test so that Linux won't fail --- .../url_launcher/example/test_driver/url_launcher_e2e.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/url_launcher/url_launcher/example/test_driver/url_launcher_e2e.dart b/packages/url_launcher/url_launcher/example/test_driver/url_launcher_e2e.dart index e1d75f93b326..f17c7e6590df 100644 --- a/packages/url_launcher/url_launcher/example/test_driver/url_launcher_e2e.dart +++ b/packages/url_launcher/url_launcher/example/test_driver/url_launcher_e2e.dart @@ -16,7 +16,7 @@ void main() { expect(await canLaunch('http://flutter.dev'), true); // Generally all devices should have some default SMS app. - expect(await canLaunch('sms:5555555555'), true); + //expect(await canLaunch('sms:5555555555'), true); // tel: and mailto: links may not be openable on every device. iOS // simulators notably can't open these link types. From c94a9e8219e0dc975ba59192ff5287919329e81f Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 28 Apr 2020 17:23:09 -0400 Subject: [PATCH 03/10] Add a task to run Linux tests. (Excepted to fail without Dockerfile changes) --- .cirrus.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.cirrus.yml b/.cirrus.yml index 2d404e3e5d66..d0568efeb08c 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -95,6 +95,13 @@ task: - fi - export CIRRUS_CHANGE_MESSAGE=`cat /tmp/cirrus_change_message.txt` - export CIRRUS_COMMIT_MESSAGE=`cat /tmp/cirrus_commit_message.txt` + - name: build-linux+drive-examples + install_script: + - flutter config --enable-linux-desktop + build_script: + - flutter channel master + - ./script/incremental_build.sh build-examples --linux --no-ipa + - ./script/incremental_build.sh drive-examples --linux task: # don't run on release tags since it creates O(n^2) tasks where n is the number of plugins From d9a8035f2cbb4696c0962a93e4947e824e89f04a Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 28 Apr 2020 18:11:42 -0400 Subject: [PATCH 04/10] First pass at installing requriments --- .ci/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.ci/Dockerfile b/.ci/Dockerfile index 13ac087498d1..066d9c33de01 100644 --- a/.ci/Dockerfile +++ b/.ci/Dockerfile @@ -27,3 +27,6 @@ RUN yes | sdkmanager --licenses RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list RUN sudo apt-get update && sudo apt-get install -y --no-install-recommends google-chrome-stable + +# Install Linux desktop requirements. +RUN sudo apt-get install -y clang make pkg-config From f654bbb1b6453cfcffd7c95321deff60e569e8a5 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 28 Apr 2020 18:30:28 -0400 Subject: [PATCH 05/10] Add rsync for asset copying --- .ci/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Dockerfile b/.ci/Dockerfile index 066d9c33de01..8743841eaae1 100644 --- a/.ci/Dockerfile +++ b/.ci/Dockerfile @@ -29,4 +29,4 @@ RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | RUN sudo apt-get update && sudo apt-get install -y --no-install-recommends google-chrome-stable # Install Linux desktop requirements. -RUN sudo apt-get install -y clang make pkg-config +RUN sudo apt-get install -y clang make rsync pkg-config From df9976ec2047af83fbe274554922cbc6647cfabd Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 28 Apr 2020 23:23:00 -0700 Subject: [PATCH 06/10] Revert "Disable SMS test so that Linux won't fail" This reverts commit e737ec580ac9f6e3e7379212027a3ac2eabcac98. --- .../url_launcher/example/test_driver/url_launcher_e2e.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/url_launcher/url_launcher/example/test_driver/url_launcher_e2e.dart b/packages/url_launcher/url_launcher/example/test_driver/url_launcher_e2e.dart index f17c7e6590df..e1d75f93b326 100644 --- a/packages/url_launcher/url_launcher/example/test_driver/url_launcher_e2e.dart +++ b/packages/url_launcher/url_launcher/example/test_driver/url_launcher_e2e.dart @@ -16,7 +16,7 @@ void main() { expect(await canLaunch('http://flutter.dev'), true); // Generally all devices should have some default SMS app. - //expect(await canLaunch('sms:5555555555'), true); + expect(await canLaunch('sms:5555555555'), true); // tel: and mailto: links may not be openable on every device. iOS // simulators notably can't open these link types. From ce7d7ac657b4544a73ce1bcb7f21e5683c92de54 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 28 Apr 2020 23:23:06 -0700 Subject: [PATCH 07/10] Revert "Add FDE url_launcher, to have something to test the CI against" This reverts commit bda22dd0f079cfd909fcc69ff366a5691a7061ee. --- .../url_launcher/url_launcher/linux/Makefile | 108 -------------- .../url_launcher/linux/url_launcher_plugin.cc | 136 ------------------ .../url_launcher/linux/url_launcher_plugin.h | 38 ----- .../url_launcher/url_launcher/pubspec.yaml | 2 - 4 files changed, 284 deletions(-) delete mode 100644 packages/url_launcher/url_launcher/linux/Makefile delete mode 100644 packages/url_launcher/url_launcher/linux/url_launcher_plugin.cc delete mode 100644 packages/url_launcher/url_launcher/linux/url_launcher_plugin.h diff --git a/packages/url_launcher/url_launcher/linux/Makefile b/packages/url_launcher/url_launcher/linux/Makefile deleted file mode 100644 index 843d87813129..000000000000 --- a/packages/url_launcher/url_launcher/linux/Makefile +++ /dev/null @@ -1,108 +0,0 @@ -# Copyright 2019 Google LLC -# -# 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. - -# The name of the plugin. -PLUGIN_NAME=url_launcher_plugin -# This is changed from the stock Makefile since the class name doesn't match -# the plugin name. This will need to be made more flexible when Linux plugin -# structure is revisited. -PLUGIN_SOURCE_NAME=url_launcher_plugin -# Any files other than the plugin class files that need to be compiled. -EXTRA_SOURCES= -# Extra flags (e.g., for library dependencies). -SYSTEM_LIBRARIES= -EXTRA_CXXFLAGS= -EXTRA_CPPFLAGS= -EXTRA_LDFLAGS= - -# Default build type. For a release build, set BUILD=release. -# Currently this only sets NDEBUG, which is used to control the flags passed -# to the Flutter engine in the example shell, and not the complation settings -# (e.g., optimization level) of the C++ code. -BUILD=debug - -# Plugins must be provided a populated flutter/ephemeral/ dir. Normally this -# would be the ephemeral directory of the application using the plugin. -ifeq ($(strip $(FLUTTER_EPHEMERAL_DIR)),) -$(error FLUTTER_EPHEMERAL_DIR must be provided) -endif - -# Dependency locations -# Default to building in the plugin directory. -OUT_DIR=$(CURDIR)/../build/linux -# Sharing an OUT_DIR will be common, so use a subdirectory for intermediates. -PLUGIN_OUT_DIR=$(OUT_DIR)/$(PLUGIN_NAME) -OBJ_DIR=$(PLUGIN_OUT_DIR)/obj/$(BUILD) - -# Flutter library -FLUTTER_LIB_NAME=flutter_linux_glfw -FLUTTER_LIB=$(FLUTTER_EPHEMERAL_DIR)/lib$(FLUTTER_LIB_NAME).so - -# Add relevant code from the wrapper library, which is intended to be statically -# built into the plugin. -# Use abspath for the wrapper root, which can contain relative paths; the -# intermediate build files will be based on the source path, which will cause -# issues if they start with one or more '../'s. -WRAPPER_ROOT=$(abspath $(FLUTTER_EPHEMERAL_DIR)/cpp_client_wrapper_glfw) -# TODO: Once JSON codec files are merged, make a PLUGIN_CODEC variable in the -# top section. For now, using JSON codec would require changes here. -WRAPPER_SOURCES= \ - $(WRAPPER_ROOT)/engine_method_result.cc \ - $(WRAPPER_ROOT)/plugin_registrar.cc \ - $(WRAPPER_ROOT)/standard_codec.cc - -# Use abspath for extra sources, which may also contain relative paths (see -# note above about WRAPPER_ROOT). -SOURCES=$(PLUGIN_SOURCE_NAME).cc $(WRAPPER_SOURCES) $(abspath $(EXTRA_SOURCES)) - -WRAPPER_INCLUDE_DIR=$(WRAPPER_ROOT)/include -INCLUDE_DIRS=$(FLUTTER_EPHEMERAL_DIR) $(WRAPPER_INCLUDE_DIR) - -# Build settings -CXX=clang++ -CXXFLAGS.release=-DNDEBUG -CXXFLAGS=-std=c++14 -Wall -Werror -fPIC -fvisibility=hidden \ - -DFLUTTER_PLUGIN_IMPL $(CXXFLAGS.$(BUILD)) $(EXTRA_CXXFLAGS) -CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS)) $(EXTRA_CPPFLAGS) -LDFLAGS=-shared -L$(FLUTTER_EPHEMERAL_DIR) -l$(FLUTTER_LIB_NAME) $(EXTRA_LDFLAGS) - -# Final output files that will be used by applications. -LIBRARY_OUT=$(OUT_DIR)/lib$(PLUGIN_NAME).so - -# Intermediate files. -OBJ_FILES=$(SOURCES:%.cc=$(OBJ_DIR)/%.o) -DEPENDENCY_FILES=$(OBJ_FILES:%.o=%.d) - -# Targets - -.PHONY: all -all: $(PLUGIN_NAME) - -.PHONY: $(PLUGIN_NAME) -$(PLUGIN_NAME) : $(LIBRARY_OUT) - -$(LIBRARY_OUT): $(OBJ_FILES) - mkdir -p $(@D) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ - --include $(DEPENDENCY_FILES) - -$(OBJ_DIR)/%.o : %.cc - mkdir -p $(@D) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -c $< -o $@ - -.PHONY: clean -clean: - rm -f $(LIBRARY_OUT) - rm -rf $(PLUGINOUT_DIR) diff --git a/packages/url_launcher/url_launcher/linux/url_launcher_plugin.cc b/packages/url_launcher/url_launcher/linux/url_launcher_plugin.cc deleted file mode 100644 index da69153c6bd4..000000000000 --- a/packages/url_launcher/url_launcher/linux/url_launcher_plugin.cc +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright 2019 Google LLC -// -// 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. - -#include "url_launcher_plugin.h" - -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace { - -using flutter::EncodableMap; -using flutter::EncodableValue; - -// Returns true if |s| starts with |prefix|. -bool StartsWith(const std::string &s, const std::string &prefix) { - return s.compare(0, prefix.size(), prefix) == 0; -} - -class UrlLauncherPlugin : public flutter::Plugin { - public: - static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar); - - virtual ~UrlLauncherPlugin(); - - private: - UrlLauncherPlugin(); - - // Called when a method is called on the plugin's channel; - void HandleMethodCall( - const flutter::MethodCall &method_call, - std::unique_ptr> result); -}; - -// static -void UrlLauncherPlugin::RegisterWithRegistrar( - flutter::PluginRegistrar *registrar) { - auto channel = std::make_unique>( - registrar->messenger(), "plugins.flutter.io/url_launcher", - &flutter::StandardMethodCodec::GetInstance()); - - // Uses new instead of make_unique due to private constructor. - std::unique_ptr plugin(new UrlLauncherPlugin()); - - channel->SetMethodCallHandler( - [plugin_pointer = plugin.get()](const auto &call, auto result) { - plugin_pointer->HandleMethodCall(call, std::move(result)); - }); - - registrar->AddPlugin(std::move(plugin)); -} - -UrlLauncherPlugin::UrlLauncherPlugin() = default; - -UrlLauncherPlugin::~UrlLauncherPlugin() = default; - -void UrlLauncherPlugin::HandleMethodCall( - const flutter::MethodCall &method_call, - std::unique_ptr> result) { - if (method_call.method_name().compare("launch") == 0) { - std::string url; - if (method_call.arguments() && method_call.arguments()->IsMap()) { - const EncodableMap &arguments = method_call.arguments()->MapValue(); - auto url_it = arguments.find(EncodableValue("url")); - if (url_it != arguments.end()) { - url = url_it->second.StringValue(); - } - } - if (url.empty()) { - result->Error("argument_error", "No URL provided"); - return; - } - - pid_t pid = fork(); - if (pid == 0) { - execl("/usr/bin/xdg-open", "xdg-open", url.c_str(), nullptr); - exit(1); - } - int status = 0; - waitpid(pid, &status, 0); - if (status != 0) { - std::ostringstream error_message; - error_message << "Failed to open " << url << ": error " << status; - result->Error("open_error", error_message.str()); - return; - } - result->Success(); - } else if (method_call.method_name().compare("canLaunch") == 0) { - std::string url; - if (method_call.arguments() && method_call.arguments()->IsMap()) { - const EncodableMap &arguments = method_call.arguments()->MapValue(); - auto url_it = arguments.find(EncodableValue("url")); - if (url_it != arguments.end()) { - url = url_it->second.StringValue(); - } - } - if (url.empty()) { - result->Error("argument_error", "No URL provided"); - return; - } - - flutter::EncodableValue response( - StartsWith(url, "https:") || StartsWith(url, "http:") || - StartsWith(url, "ftp:") || StartsWith(url, "file:")); - result->Success(&response); - return; - } else { - result->NotImplemented(); - } -} - -} // namespace - -void UrlLauncherPluginRegisterWithRegistrar( - FlutterDesktopPluginRegistrarRef registrar) { - UrlLauncherPlugin::RegisterWithRegistrar( - flutter::PluginRegistrarManager::GetInstance() - ->GetRegistrar(registrar)); -} diff --git a/packages/url_launcher/url_launcher/linux/url_launcher_plugin.h b/packages/url_launcher/url_launcher/linux/url_launcher_plugin.h deleted file mode 100644 index b88e2d5064d2..000000000000 --- a/packages/url_launcher/url_launcher/linux/url_launcher_plugin.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2019 Google LLC -// -// 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. -#ifndef PLUGINS_FLUTTER_PLUGINS_URL_LAUNCHER_FDE_LINUX_URL_LAUNCHER_FDE_PLUGIN_H_ -#define PLUGINS_FLUTTER_PLUGINS_URL_LAUNCHER_FDE_LINUX_URL_LAUNCHER_FDE_PLUGIN_H_ - -// A plugin to control a native menubar. - -#include - -#ifdef FLUTTER_PLUGIN_IMPL -#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default"))) -#else -#define FLUTTER_PLUGIN_EXPORT -#endif - -#if defined(__cplusplus) -extern "C" { -#endif - -FLUTTER_PLUGIN_EXPORT void UrlLauncherPluginRegisterWithRegistrar( - FlutterDesktopPluginRegistrarRef registrar); - -#if defined(__cplusplus) -} // extern "C" -#endif - -#endif // PLUGINS_FLUTTER_PLUGINS_URL_LAUNCHER_FDE_LINUX_URL_LAUNCHER_FDE_PLUGIN_H_ diff --git a/packages/url_launcher/url_launcher/pubspec.yaml b/packages/url_launcher/url_launcher/pubspec.yaml index 162d1fb58c4b..4d1fbafa5095 100644 --- a/packages/url_launcher/url_launcher/pubspec.yaml +++ b/packages/url_launcher/url_launcher/pubspec.yaml @@ -16,8 +16,6 @@ flutter: default_package: url_launcher_web macos: default_package: url_laucher_macos - linux: - pluginClass: UrlLauncherPlugin dependencies: flutter: From b37ed367d8746ebe19cc412200557960143d35e2 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 28 Apr 2020 23:23:45 -0700 Subject: [PATCH 08/10] Remove unnecessary flag --- .cirrus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index d0568efeb08c..732906def01b 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -100,7 +100,7 @@ task: - flutter config --enable-linux-desktop build_script: - flutter channel master - - ./script/incremental_build.sh build-examples --linux --no-ipa + - ./script/incremental_build.sh build-examples --linux - ./script/incremental_build.sh drive-examples --linux task: From daee586fca04cb63349fc135f69d31c75dc4d66f Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 5 May 2020 13:48:51 -0700 Subject: [PATCH 09/10] Add TODO --- .cirrus.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.cirrus.yml b/.cirrus.yml index d38ce21f239c..dfb6532740af 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -99,6 +99,7 @@ task: install_script: - flutter config --enable-linux-desktop build_script: + # TODO(stuartmorgan): Include stable once Linux is supported on stable. - flutter channel master - ./script/incremental_build.sh build-examples --linux - ./script/incremental_build.sh drive-examples --linux From 7105d7f1ff0f56fc33dd35488660aad98aec6493 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 5 May 2020 20:51:11 -0700 Subject: [PATCH 10/10] Alternate approach: use a different Dockerfile for Linux desktop --- .ci/Dockerfile | 3 --- .ci/Dockerfile-LinuxDesktop | 19 +++++++++++++++++++ .cirrus.yml | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 .ci/Dockerfile-LinuxDesktop diff --git a/.ci/Dockerfile b/.ci/Dockerfile index 8743841eaae1..13ac087498d1 100644 --- a/.ci/Dockerfile +++ b/.ci/Dockerfile @@ -27,6 +27,3 @@ RUN yes | sdkmanager --licenses RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list RUN sudo apt-get update && sudo apt-get install -y --no-install-recommends google-chrome-stable - -# Install Linux desktop requirements. -RUN sudo apt-get install -y clang make rsync pkg-config diff --git a/.ci/Dockerfile-LinuxDesktop b/.ci/Dockerfile-LinuxDesktop new file mode 100644 index 000000000000..01c6d41ca2ed --- /dev/null +++ b/.ci/Dockerfile-LinuxDesktop @@ -0,0 +1,19 @@ +FROM cirrusci/flutter:stable + +RUN sudo apt-get update -y + +RUN sudo apt-get install -y --no-install-recommends gnupg + +# Add repo for gcloud sdk and install it +RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | \ + sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list + +RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | \ + sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - + +RUN sudo apt-get update && sudo apt-get install -y google-cloud-sdk && \ + gcloud config set core/disable_usage_reporting true && \ + gcloud config set component_manager/disable_update_check true + +# Install Linux desktop requirements. +RUN sudo apt-get install -y clang make cmake ninja-build rsync pkg-config diff --git a/.cirrus.yml b/.cirrus.yml index dfb6532740af..6f78cf7ba773 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -95,6 +95,25 @@ task: - fi - export CIRRUS_CHANGE_MESSAGE=`cat /tmp/cirrus_change_message.txt` - export CIRRUS_COMMIT_MESSAGE=`cat /tmp/cirrus_commit_message.txt` + +task: + # don't run on release tags since it creates O(n^2) tasks where n is the number of plugins + only_if: $CIRRUS_TAG == '' + use_compute_credits: $CIRRUS_USER_COLLABORATOR == 'true' && $CIRRUS_PR == '' + container: + dockerfile: .ci/Dockerfile-LinuxDesktop + cpu: 8 + memory: 16G + env: + E2E_PATH: "./packages/e2e" + upgrade_script: + - flutter channel stable + - flutter upgrade + - flutter channel master + - flutter upgrade + - git fetch origin master + activate_script: pub global activate flutter_plugin_tools + matrix: - name: build-linux+drive-examples install_script: - flutter config --enable-linux-desktop