forked from dense-analysis/ale
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a wrapper program for running linters which cannot receive stdin …
…input on Windows.
- Loading branch information
Showing
6 changed files
with
112 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/init.vim | ||
/doc/tags | ||
.* | ||
*.obj |
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
Binary file not shown.
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,84 @@ | ||
// Author: w0rp <devw0rp@gmail.com> | ||
// Description: This file provides a D program for implementing | ||
// the stdin-wrapper on Windows. | ||
|
||
import std.algorithm; | ||
import std.array; | ||
import std.file; | ||
import std.process; | ||
import std.stdio; | ||
import std.path; | ||
|
||
@safe | ||
auto createTemporaryFilename(string fileExtension) { | ||
import std.uuid; | ||
|
||
string filename; | ||
|
||
do { | ||
const randomPart = randomUUID().toString.replace("-", "_"); | ||
|
||
filename = buildPath(tempDir(), "ale_" ~ randomPart ~ fileExtension); | ||
} while (exists(filename)); | ||
|
||
return filename; | ||
} | ||
|
||
@trusted | ||
void readStdinToFile(ref File tempFile) { | ||
stdin.byChunk(4096).copy(tempFile.lockingTextWriter()); | ||
} | ||
|
||
// Expand program names like "csslint" to "csslint.cmd" | ||
// D is not able to perform this kind of expanstion in spawnProcess | ||
@safe | ||
string expandedProgramName(string name) { | ||
auto extArray = environment["PATHEXT"].split(";"); | ||
|
||
foreach(pathDir; environment["PATH"].split(";")) { | ||
foreach(extension; extArray) { | ||
const candidate = buildPath(pathDir, name ~ extension); | ||
|
||
if (exists(candidate)) { | ||
return candidate; | ||
} | ||
} | ||
} | ||
|
||
// We were given a full path for a program name, so use that. | ||
if (exists(name)) { | ||
return name; | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
@trusted | ||
int runLinterProgram(string[] args) { | ||
const expandedName = expandedProgramName(args[0]); | ||
|
||
writeln(expandedName); | ||
|
||
if (expandedName) { | ||
return wait(spawnProcess([expandedName] ~ args[1..$])); | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
@safe | ||
int main(string[] args) { | ||
const filename = createTemporaryFilename(args[1]); | ||
|
||
auto tempFile = File(filename, "w"); | ||
|
||
scope(exit) { | ||
tempFile.close(); | ||
remove(filename); | ||
} | ||
|
||
readStdinToFile(tempFile); | ||
tempFile.close(); | ||
|
||
return runLinterProgram(args[2..$] ~ [filename]); | ||
} |