forked from HaxeFoundation/haxe
-
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.
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import sys.FileSystem; | ||
|
||
final FILE = "out/main.c"; | ||
|
||
function deleteDirectory(path:String) { | ||
if (!FileSystem.isDirectory(path)) | ||
return FileSystem.deleteFile(path); | ||
|
||
for (item in FileSystem.readDirectory(path)) | ||
deleteDirectory('$path/$item'); | ||
|
||
FileSystem.deleteDirectory(path); | ||
} | ||
|
||
function main() { | ||
final args = Sys.args(); | ||
|
||
final code = | ||
try { | ||
switch args { | ||
case [""]: | ||
checkForEmptySourceHeader(FILE); | ||
case [expected]: | ||
checkSourceHeader(FILE, expected); | ||
case _: | ||
throw "Incorrect number of arguments to script."; | ||
} | ||
0; | ||
} catch (e){ | ||
Sys.stderr().writeString(e + "\n"); | ||
1; | ||
} | ||
|
||
deleteDirectory("out"); | ||
Sys.exit(code); | ||
} | ||
|
||
function checkForEmptySourceHeader(path:String) { | ||
final content = getCSourceContent(path); | ||
|
||
if (StringTools.startsWith(content, "// ")) | ||
throw "File has a source header when none was expected: " + content.split("\n")[0]; | ||
} | ||
|
||
function checkSourceHeader(path:String, expected:String) { | ||
final content = getCSourceContent(path); | ||
|
||
if (!StringTools.startsWith(content, "// " + expected)) | ||
throw "File source header does not start with expected: // " + expected + | ||
"\nSource header: " + content.split("\n")[0]; | ||
} | ||
|
||
function getCSourceContent(path:String) { | ||
// have to skip the BOM character | ||
return sys.io.File.getContent(path).substr(1); | ||
} |
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,5 @@ | ||
--main CheckSourceHeader | ||
--hl out/main.c | ||
-D no-compilation | ||
-D source-header=custom | ||
--cmd haxe --run CheckSourceHeader custom |
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,5 @@ | ||
--main CheckSourceHeader | ||
--hl out/main.c | ||
-D no-compilation | ||
|
||
--cmd haxe --run CheckSourceHeader "Generated by HLC" |
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,5 @@ | ||
--main CheckSourceHeader | ||
--hl out/main.c | ||
-D no-compilation | ||
-D source-header= | ||
--cmd haxe --run CheckSourceHeader "" |