Skip to content

Commit

Permalink
feat(): add support for macOS (pauldemarco#626)
Browse files Browse the repository at this point in the history
* feat(): add support for macOS

* fix(): remove conflicting flutter.plugin keys from pubspec.yaml

The flutter.plugin.platforms key cannot be used in combination with the old flutter.plugin.{androidPackage,iosPrefix,pluginClass} keys. See: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin
  • Loading branch information
blaugold authored Aug 22, 2020
1 parent 34665b9 commit 207943a
Show file tree
Hide file tree
Showing 36 changed files with 1,487 additions and 3 deletions.
6 changes: 6 additions & 0 deletions example/macos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Flutter-related
**/Flutter/ephemeral/
**/Pods/

# Xcode-related
**/xcuserdata/
2 changes: 2 additions & 0 deletions example/macos/Flutter/Flutter-Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
2 changes: 2 additions & 0 deletions example/macos/Flutter/Flutter-Release.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
12 changes: 12 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Generated file. Do not edit.
//

import FlutterMacOS
import Foundation

import flutter_blue

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterBluePlugin.register(with: registry.registrar(forPlugin: "FlutterBluePlugin"))
}
82 changes: 82 additions & 0 deletions example/macos/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
platform :osx, '10.13'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def parse_KV_file(file, separator='=')
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return [];
end
pods_ary = []
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) { |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
pods_ary.push({:name => podname, :path => podpath});
else
puts "Invalid plugin specification: #{line}"
end
}
return pods_ary
end

def pubspec_supports_macos(file)
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return false;
end
File.foreach(file_abs_path) { |line|
return true if line =~ /^\s*macos:/
}
return false
end

target 'Runner' do
use_frameworks!
use_modular_headers!

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
ephemeral_dir = File.join('Flutter', 'ephemeral')
symlink_dir = File.join(ephemeral_dir, '.symlinks')
symlink_plugins_dir = File.join(symlink_dir, 'plugins')
system("rm -rf #{symlink_dir}")
system("mkdir -p #{symlink_plugins_dir}")

# Flutter Pods
generated_xcconfig = parse_KV_file(File.join(ephemeral_dir, 'Flutter-Generated.xcconfig'))
if generated_xcconfig.empty?
puts "Flutter-Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
end
generated_xcconfig.map { |p|
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
symlink = File.join(symlink_dir, 'flutter')
File.symlink(File.dirname(p[:path]), symlink)
pod 'FlutterMacOS', :path => File.join(symlink, File.basename(p[:path]))
end
}

# Plugin Pods
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.map { |p|
symlink = File.join(symlink_plugins_dir, p[:name])
File.symlink(p[:path], symlink)
if pubspec_supports_macos(File.join(symlink, 'pubspec.yaml'))
pod p[:name], :path => File.join(symlink, 'macos')
end
}
end

# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true
32 changes: 32 additions & 0 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
PODS:
- flutter_blue (0.0.1):
- flutter_blue/Protos (= 0.0.1)
- FlutterMacOS
- flutter_blue/Protos (0.0.1):
- FlutterMacOS
- Protobuf (~> 3.11.4)
- FlutterMacOS (1.0.0)
- Protobuf (3.11.4)

DEPENDENCIES:
- flutter_blue (from `Flutter/ephemeral/.symlinks/plugins/flutter_blue/macos`)
- FlutterMacOS (from `Flutter/ephemeral/.symlinks/flutter/darwin-x64`)

SPEC REPOS:
trunk:
- Protobuf

EXTERNAL SOURCES:
flutter_blue:
:path: Flutter/ephemeral/.symlinks/plugins/flutter_blue/macos
FlutterMacOS:
:path: Flutter/ephemeral/.symlinks/flutter/darwin-x64

SPEC CHECKSUMS:
flutter_blue: 2756506bb10a51e075832da287b48bf5377bdc28
FlutterMacOS: 15bea8a44d2fa024068daa0140371c020b4b6ff9
Protobuf: 176220c526ad8bd09ab1fb40a978eac3fef665f7

PODFILE CHECKSUM: 91a45292e3c63eb73c6e52036eeb01a52e7ae4df

COCOAPODS: 1.9.2
Loading

0 comments on commit 207943a

Please sign in to comment.