Skip to content

Commit

Permalink
Merge pull request #61 from terhechte/less-dependencies
Browse files Browse the repository at this point in the history
- Update to Swift 4.0 and possibly 4.1
- Reduced dependency overhead by using Embassy instead of Vapor
- Linux port was started and advanced on quite a bit:
--> Compiles after a 4.1 Foundation bugfix. 
--> Crashes while testing. Seems to be caused by a force unwrapping of a null value.
  • Loading branch information
felix91gr authored Feb 28, 2018
2 parents 759bd94 + de8114a commit 90eeb56
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 91 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Carthage/Build
.build
dist
SourceKittenDaemon.pkg
Packages
Packages
Package.pins
11 changes: 2 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ clean:
rm -rf "$(BUILD)"

.PHONY: install
install: $(DIST)$(BINARIES_FOLDER)/sourcekittendaemon $(DIST)$(LIB_FOLDER)/libCYaml.dylib $(DIST)$(LIB_FOLDER)/libCLibreSSL.dylib
install: $(DIST)$(BINARIES_FOLDER)/sourcekittendaemon
mkdir -p "$(PREFIX)$(BINARIES_FOLDER)"
mkdir -p "$(PREFIX)$(LIB_FOLDER)"
cp -f "$(DIST)$(BINARIES_FOLDER)/sourcekittendaemon" "$(PREFIX)$(BINARIES_FOLDER)/"
cp -f "$(DIST)$(LIB_FOLDER)/libCYaml.dylib" "$(PREFIX)$(LIB_FOLDER)/"
cp -f "$(DIST)$(LIB_FOLDER)/libCLibreSSL.dylib" "$(PREFIX)$(LIB_FOLDER)/"

.PHONY: test
test:
Expand All @@ -32,7 +30,7 @@ test:
FIXTURE_PROJECT_FILE_PATH="$(ROOT_DIR)/Tests/SourceKittenDaemonTests/Fixtures/Project/Fixture.xcodeproj" \
swift test

SourceKittenDaemon.pkg: $(DIST)$(BINARIES_FOLDER)/sourcekittendaemon $(DIST)$(LIB_FOLDER)/libCYaml.dylib $(DIST)$(LIB_FOLDER)/libCLibreSSL.dylib
SourceKittenDaemon.pkg: $(DIST)$(BINARIES_FOLDER)/sourcekittendaemon
pkgbuild \
--identifier "$(IDENTIFIER)" \
--root "$(DIST)" \
Expand All @@ -43,16 +41,11 @@ SourceKittenDaemon.pkg: $(DIST)$(BINARIES_FOLDER)/sourcekittendaemon $(DIST)$(LI
$(DIST)$(BINARIES_FOLDER)/sourcekittendaemon: $(BUILD)/release/sourcekittend
mkdir -p $(@D)
cp $< $@
install_name_tool -change $(PWD)/$(BUILD)/release/libCYaml.dylib $(PREFIX)$(LIB_FOLDER)/libCYaml.dylib $@
install_name_tool -change $(PWD)/$(BUILD)/release/libCLibreSSL.dylib $(PREFIX)$(LIB_FOLDER)/libCLibreSSL.dylib $@

$(DIST)$(LIB_FOLDER)/%.dylib: $(BUILD)/release/%.dylib
mkdir -p $(@D)
cp $< $@

$(BUILD)/release/libCYaml.dylib: $(BUILD)/release/sourcekittend
$(BUILD)/release/libCLibreSSL.dylib: $(BUILD)/release/sourcekittend

$(BUILD)/release/sourcekittend: $(SRC_FILES)
mkdir -p $(@D)
swift build -c release --build-path $(BUILD)
Expand Down
72 changes: 72 additions & 0 deletions Package.pins
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"autoPin": true,
"pins": [
{
"package": "Clang_C",
"reason": null,
"repositoryURL": "https://github.com/norio-nomura/Clang_C.git",
"version": "1.0.2"
},
{
"package": "Commandant",
"reason": null,
"repositoryURL": "https://github.com/Carthage/Commandant.git",
"version": "0.12.0"
},
{
"package": "Embassy",
"reason": null,
"repositoryURL": "https://github.com/envoy/Embassy.git",
"version": "3.1.0"
},
{
"package": "FileSystemWatcher",
"reason": null,
"repositoryURL": "https://github.com/felix91gr/FileSystemWatcher.git",
"version": "1.1.2"
},
{
"package": "inotify",
"reason": null,
"repositoryURL": "https://github.com/felix91gr/inotify.git",
"version": "1.0.2"
},
{
"package": "Result",
"reason": null,
"repositoryURL": "https://github.com/antitypical/Result.git",
"version": "3.2.2"
},
{
"package": "SourceKit",
"reason": null,
"repositoryURL": "https://github.com/norio-nomura/SourceKit.git",
"version": "1.0.1"
},
{
"package": "SourceKitten",
"reason": null,
"repositoryURL": "https://github.com/jpsim/SourceKitten.git",
"version": "0.17.5"
},
{
"package": "SWXMLHash",
"reason": null,
"repositoryURL": "https://github.com/drmohundro/SWXMLHash.git",
"version": "3.1.0"
},
{
"package": "XcodeEdit",
"reason": null,
"repositoryURL": "https://github.com/felix91gr/XcodeEdit.git",
"version": "1.1.2"
},
{
"package": "Yams",
"reason": null,
"repositoryURL": "https://github.com/jpsim/Yams.git",
"version": "0.3.2"
}
],
"version": 1
}
13 changes: 9 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PackageDescription

let package = Package(
var package = Package(
name: "SourceKittenDaemon",

targets: [
Expand All @@ -10,12 +10,17 @@ let package = Package(

dependencies: [
.Package(url: "https://github.com/Carthage/Commandant.git", versions: Version(0, 12, 0)..<Version(0, 12, .max)),
.Package(url: "https://github.com/jpsim/SourceKitten.git", Version(0, 17, 2)),
.Package(url: "https://github.com/vapor/vapor.git", Version(1, 1, 12)),
.Package(url: "https://github.com/nanzhong/Xcode.swift.git", Version(0, 4, 1))
.Package(url: "https://github.com/jpsim/SourceKitten.git", majorVersion: 0, minor: 18),
.Package(url: "https://github.com/envoy/Embassy.git", majorVersion: 4),
.Package(url: "https://github.com/felix91gr/XcodeEdit.git", majorVersion: 1),
],

exclude: [
"Tests/SourceKittenDaemonTests/Fixtures/Sources"
]
)

#if os(Linux)
package.dependencies.append(.Package(url: "https://github.com/felix91gr/FileSystemWatcher.git",
majorVersion: 1))
#endif
87 changes: 71 additions & 16 deletions Sources/SourceKittenDaemon/Completer/Completer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,74 @@
import Foundation
import SourceKittenFramework

#if os(Linux)
import FileSystemWatcher
#endif

private func pingSKD() {
NotificationCenter.default.post(name: Notification.Name(rawValue: "skdrefresh"), object: nil)
}

class FileSystemEventsWrapper {


#if os(Linux)

func pingAux(event: FileSystemEvent) {
pingSKD()
}

let myWatcher : FileSystemWatcher

public init(delay: Int, paths toWatch: [String]) {

myWatcher = FileSystemWatcher(deferringDelay: Double(delay))

myWatcher.watch(
paths: toWatch,
for: [FileSystemEventType.inAllEvents],
thenInvoke: pingAux)

myWatcher.start()
}

deinit {
myWatcher.stop()
}

#else

let eventStream: FSEventStreamRef

public init(delay: Int, paths toWatch: [String]) {

self.eventStream = FSEventStreamCreate(
kCFAllocatorDefault, { (_, _, _, _, _, _) in
pingSKD()
},
nil,
toWatch as CFArray,
FSEventStreamEventId(kFSEventStreamEventIdSinceNow),
CFTimeInterval(delay),
FSEventStreamCreateFlags(kFSEventStreamCreateFlagFileEvents | kFSEventStreamCreateFlagNoDefer))!

let runLoop = RunLoop.main

FSEventStreamScheduleWithRunLoop(eventStream,
runLoop.getCFRunLoop(),
RunLoopMode.defaultRunLoopMode as CFString)

FSEventStreamStart(eventStream)
}

deinit {
FSEventStreamInvalidate(eventStream)
}

#endif

}

/**
This keeps the connection to the XPC via SourceKitten and is being called
from the Completion Server to perform completions. */
Expand All @@ -19,25 +87,12 @@ class Completer {

// Need to monitor changes to the .pbxproject and re-fetch
// project settings.
let eventStream: FSEventStreamRef
let fsEventWrapper : FileSystemEventsWrapper

init(project: Project) {
self.project = project

self.eventStream = FSEventStreamCreate(
kCFAllocatorDefault,
{ (_) in NotificationCenter.default.post(name: Notification.Name(rawValue: "skdrefresh"), object: nil) },
nil,
[project.projectFile.path] as CFArray,
FSEventStreamEventId(kFSEventStreamEventIdSinceNow),
2,
FSEventStreamCreateFlags(kFSEventStreamCreateFlagFileEvents | kFSEventStreamCreateFlagNoDefer))!

let runLoop = RunLoop.main
FSEventStreamScheduleWithRunLoop(eventStream,
runLoop.getCFRunLoop(),
RunLoopMode.defaultRunLoopMode as CFString)
FSEventStreamStart(eventStream)
self.fsEventWrapper = FileSystemEventsWrapper(delay: 2, paths: [project.projectFile.path])

print("[INFO] Monitoring \(project.projectFile.path) for changes")
NotificationCenter.default.addObserver(
Expand All @@ -50,7 +105,7 @@ class Completer {
}

deinit {
FSEventStreamInvalidate(eventStream)

}

func refresh() throws {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SourceKittenDaemon/Extensions/Path+.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import Xcode
import XcodeEdit

extension Path {

Expand Down
4 changes: 2 additions & 2 deletions Sources/SourceKittenDaemon/Project/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import Xcode
import XcodeEdit

public class Project {

Expand Down Expand Up @@ -116,7 +116,7 @@ public class Project {
let sourceType = ProjectObjectSourceType(rawValue: type),
let path = fileRef.path,
let name = path.components(separatedBy: "/").last,
let relativePath = self.xcProjectFile.project.allObjects.fullFilePaths[fileRef.id] {
let relativePath = self.xcProjectFile.project.allObjects.FullFilePaths[fileRef.id] {
return ProjectObject(type: sourceType,
name: name,
relativePath: relativePath,
Expand Down
Loading

0 comments on commit 90eeb56

Please sign in to comment.