-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from uber/generator-collect_parsing_info-master
Expand tracking task ID to collecting more information
- Loading branch information
Showing
7 changed files
with
87 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Generator/Sources/NeedleFramework/Utilities/ProcessUtilities.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// Copyright (c) 2018. Uber Technologies | ||
// | ||
// 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 Foundation | ||
|
||
/// Check if the sourcekit daemon process is running by searching through | ||
/// all processes without ttys. | ||
var isSourceKitRunning: Bool { | ||
// Select processes without controlling ttys in jobs format. | ||
let result = ProcessUtilities.execute(process: "/bin/ps", withArguments: ["-xj"]).lowercased() | ||
// These process names are found in library_wrapper_sourcekitd.swift | ||
// of SourceKittenFramework. | ||
return result.contains("libsourcekitdInProc") || result.contains("sourcekitd.framework") | ||
} | ||
|
||
/// A set of utility functions for running processes. | ||
class ProcessUtilities { | ||
|
||
/// Execute the given process with given arguments and return the | ||
/// standard output as a `String`. | ||
/// | ||
/// - parameter process: The process to run. | ||
/// - parameter arguments: The list of arguments to supply to the | ||
/// process. | ||
/// - returns: The standard output content as a single `String`. | ||
static func execute(process: String, withArguments arguments: [String] = []) -> String { | ||
let task = Process() | ||
task.launchPath = process | ||
task.arguments = arguments | ||
let pipe = Pipe() | ||
task.standardOutput = pipe | ||
task.launch() | ||
|
||
let handle = pipe.fileHandleForReading | ||
let data = handle.readDataToEndOfFile() | ||
return String(data: data, encoding: .utf8) ?? "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters