Commit a8ac7c97 authored by Drew's avatar Drew

Resolve an issue where autocomplete stops working

for projects with too many dependencies
parent 9be3e212
Pipeline #2800 passed with stage
in 1 minute and 32 seconds
......@@ -39,6 +39,23 @@ func emit(task: Task, testTask: Task?, package: Package) {
}
private func _collectSources(sourceDescriptions: [String], taskForCalculatingPath: Task) -> [String] {
let sources = collectSources(sourceDescriptions: sourceDescriptions, taskForCalculatingPath: taskForCalculatingPath)
//xcode gets frightened if a path has too many symlinks, and autocomplete goes away and refuses to come out to play
//to solve this, we go through python
var normalSources: [String] = []
for source in sources {
var output = ""
guard anarchySystem("python3 -c \"import os.path;import sys; print(os.path.relpath(os.path.realpath(sys.argv[1])))\" \"\(source)\"", environment:[:], redirectOutput: &output) == 0 else {
fatalError("Can't normalize path \(source)")
}
//remove trailing \n
output.remove(at: output.characters.index(before: output.characters.endIndex))
normalSources.append(output)
}
return normalSources
}
func process(tasks: [Task], testTask: Task?, package: Package, xcodeprojGUID: String) -> [PbxprojSerializable] {
let task = tasks[0] //pull off head
//are there dependencies?
......@@ -58,7 +75,7 @@ func process(tasks: [Task], testTask: Task?, package: Package, xcodeprojGUID: St
}
guard let taskname = task["name"]?.string else { fatalError("No task name.")}
guard let sourceDescriptions = task["sources"]?.vector?.flatMap({$0.string}) else { fatalError("Can't find sources for atllbuild.") }
let sources = collectSources(sourceDescriptions: sourceDescriptions, taskForCalculatingPath: task)
let sources = _collectSources(sourceDescriptions: sourceDescriptions, taskForCalculatingPath: task)
//emit the pbxproj
let outputType : OutputType
if task["output-type"]?.string == "executable" {
......
// Copyright (c) 2016 Anarchy Tools Contributors.
//
// 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.
#if os(OSX)
import Darwin
#else
import Glibc
#endif
import atfoundation
private func _WSTATUS(_ status: CInt) -> CInt {
return status & 0x7f
}
private func WIFEXITED(_ status: CInt) -> Bool {
return _WSTATUS(status) == 0
}
private func WEXITSTATUS(_ status: CInt) -> CInt {
return (status >> 8) & 0xff
}
/// convenience wrapper for waitpid
private func waitpid(_ pid: pid_t) -> Int32 {
while true {
var exitStatus: Int32 = 0
let rv = waitpid(pid, &exitStatus, 0)
if rv != -1 {
if WIFEXITED(exitStatus) {
return WEXITSTATUS(exitStatus)
} else {
fatalError("Exit signal")
}
} else if errno == EINTR {
continue // see: man waitpid
} else {
fatalError("waitpid: \(errno)")
}
}
}
///A wrapper for POSIX "system" call.
///If return value is non-zero, we exit (not fatalError)
///See #72 for details.
///- note: This function call is appropriate for commands that are user-perceivable (such as compilation)
///Rather than calls that aren't
func anarchySystem(_ cmd: String, environment: [String: String]) -> Int32 {
var output = ""
return anarchySystem(cmd, environment: environment, redirectOutput: &output)
}
func anarchySystem(_ cmd: String, environment: [String: String],redirectOutput: inout String) -> Int32 {
var pid : pid_t = 0
//copy a few well-known values
var environment = environment
for arg in ["PATH","HOME"] {
if let path = getenv(arg) {
environment[arg] = String(validatingUTF8: path)!
}
}
var cmd = cmd
cmd += ">/tmp/anarchySystem.out"
let args: [String] = ["sh","-c",cmd]
let argv = args.map{ $0.withCString(strdup) }
let env: [UnsafeMutablePointer<CChar>?] = environment.map{ "\($0.0)=\($0.1)".withCString(strdup) }
let directory = try! FS.getWorkingDirectory()
defer {try! FS.changeWorkingDirectory(path: directory)}
if let e = environment["PWD"] {
try! FS.changeWorkingDirectory(path: Path(e))
}
let status = posix_spawn(&pid, "/bin/sh",nil,nil,argv + [nil],env + [nil])
if status != 0 {
fatalError("spawn error \(status)")
}
let returnCode = waitpid(pid)
redirectOutput = try! File(path: Path("/tmp/anarchySystem.out"), mode:.ReadOnly).readAll()!
return returnCode
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment