Skip to content

Commit

Permalink
Return correct exit code even if -q (quiet) is used. Closes #786
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Aug 16, 2014
1 parent b2582aa commit d0577e6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 35 deletions.
4 changes: 2 additions & 2 deletions source/rock/frontend/AstBuilder.ooc
Expand Up @@ -95,7 +95,7 @@ AstBuilder: class {
// in the meantime, I'm (ndd) keeping them around, trying not to use current-gen
// features in current-gen source to facilitate bootstrapping.
if (imp sourcePathElement) {
(impPat2, impElemen2) := params sourcePath getFileInElement(path, imp sourcePathElement)
(impPat2, impElemen2) := params sourcePath getFileInElement(path, imp sourcePathElement, params)
(impPath, impElement) = (impPat2, impElemen2)
} else {
(impPat2, impElemen2) := params sourcePath getFile(path)
Expand All @@ -107,7 +107,7 @@ AstBuilder: class {
// import can also be 'implicitly relative', e.g. io/File can import io/native/FileWin32
// just by doing 'import native/FileWin32'
path = FileUtils resolveRedundancies(parent path + File separator + oocImpPath)
(impPat2, impElemen2) := params sourcePath getFileInElement(path, module pathElement)
(impPat2, impElemen2) := params sourcePath getFileInElement(path, module pathElement, params)
(impPath, impElement) = (impPat2, impElemen2)
}
}
Expand Down
17 changes: 12 additions & 5 deletions source/rock/frontend/BuildParams.ooc
Expand Up @@ -241,10 +241,12 @@ BuildParams: class {
// compilation driver
driver := SequenceDriver new(this)

checkBinaryNameCollision: func (name: String) {
validBinaryName?: func (name: String) -> Bool {
if (File new(name) dir?()) {
stderr write("Naming conflict (output binary) : There is already a directory called %s.\nTry a different name, e.g. '-o=%s2'\n" format(name, name))
CommandLine failure()
false
} else {
true
}
}

Expand All @@ -257,7 +259,9 @@ BuildParams: class {
}

if (binaryPath == "") {
checkBinaryNameCollision(defaultPath)
if (!validBinaryName?(defaultPath)) {
return null
}
defaultPath
} else {
binaryPath
Expand Down Expand Up @@ -329,8 +333,7 @@ BuildParams: class {
if (host != "") {
tokens := host split('-')
if (tokens size < 2) {
CommandLine error("Invalid host value: %s" format(host))
CommandLine failure()
ParamsError new("Invalid host value: %s" format(host)) throw()
}

(archToken, targetToken) := (tokens[0], tokens[1])
Expand Down Expand Up @@ -463,3 +466,7 @@ OptimizationLevel: enum {
Os
}

ParamsError: class extends Exception {
init: func (=message)
}

55 changes: 31 additions & 24 deletions source/rock/frontend/CommandLine.ooc
Expand Up @@ -337,7 +337,7 @@ CommandLine: class {
case "android" => Target ANDROID
case =>
"[ERROR] Unknown target: %s" printfln(targetName)
failure()
failure(params)
null
}
params undoTargetSpecific()
Expand All @@ -349,7 +349,7 @@ CommandLine: class {
params driver = match (driverName) {
case "combine" =>
"[ERROR] The combine driver is deprecated." println()
failure()
failure(params)
params driver
case "sequence" =>
SequenceDriver new(params)
Expand All @@ -362,7 +362,7 @@ CommandLine: class {
DummyDriver new(params)
case =>
"[ERROR] Unknown driver: %s" printfln(driverName)
failure()
failure(params)
null
}

Expand Down Expand Up @@ -476,15 +476,20 @@ CommandLine: class {
case lowerArg contains?(".") =>
// unknown file, complain
"[ERROR] Don't know what to do with argument %s, bailing out" printfln(arg)
failure()
failure(params)
case =>
// probably an ooc file without the extension
modulePaths add(arg + ".ooc")
}
}
}

params bake()
try {
params bake()
} catch (e: ParamsError) {
error(e message)
failure(params)
}

if(modulePaths empty?() && !targetModule) {
if (alreadyDidSomething) {
Expand Down Expand Up @@ -561,15 +566,15 @@ CommandLine: class {

if (!uze sourcePath) {
error("No SourcePath directive in '%s'" format(uzeFile path))
failure()
failure(params)
}

params link = false

base := File new(uze sourcePath)
if (!base exists?()) {
error("SourcePath '%s' doesn't exist" format(base path))
failure()
failure(params)
}

importz := ArrayList<String> new()
Expand Down Expand Up @@ -608,7 +613,7 @@ CommandLine: class {
if(!moduleFile) {
"[ERROR] Could not find main .ooc file: %s" printfln(moduleName)
"[INFO] SourcePath = %s" printfln(params sourcePath toString())
failure()
failure(params)
exit(1)
}

Expand All @@ -635,7 +640,7 @@ CommandLine: class {
if(params onlyparse) {
if(params verbose) println()
// Oookay, we're done here.
success()
success(params)
return
}

Expand All @@ -654,7 +659,7 @@ CommandLine: class {
allModules := module collectDeps()
resolveMs := Time measure(||
if(!Tinkerer new(params) process(allModules)) {
failure()
failure(params)
}
)
if (params timing) {
Expand All @@ -677,16 +682,14 @@ CommandLine: class {
if (params timing) {
"C generation & compiling took %d ms" printfln(compileMs)
}
if(params shout) success()
success(params)
if(params run) {
// FIXME: that's the driver's job
if(params binaryPath && !params binaryPath empty?()) Process new(["./" + params binaryPath]) execute()
else Process new(["./" + module simpleName]) execute()
}
} else {
if(params shout) {
failure()
}
failure(params)
}
}

Expand Down Expand Up @@ -744,18 +747,22 @@ CommandLine: class {
error("%s parameter is deprecated" format(parameter))
}

success: static func {
Terminal setAttr(Attr bright)
Terminal setFgColor(Color green)
"[ OK ]" println()
Terminal reset()
success: static func (params: BuildParams) {
if (params shout) {
Terminal setAttr(Attr bright)
Terminal setFgColor(Color green)
"[ OK ]" println()
Terminal reset()
}
}

failure: static func {
Terminal setAttr(Attr bright)
Terminal setFgColor(Color red)
"[FAIL]" println()
Terminal reset()
failure: static func (params: BuildParams) {
if (params shout) {
Terminal setAttr(Attr bright)
Terminal setFgColor(Color red)
"[FAIL]" println()
Terminal reset()
}

// FIXME: should we *ever* exit(1) ?
exit(1)
Expand Down
6 changes: 3 additions & 3 deletions source/rock/frontend/PathList.ooc
@@ -1,7 +1,7 @@

import io/[File]
import structs/[ArrayList, List, HashMap]
import rock/frontend/CommandLine
import rock/frontend/[CommandLine, BuildParams]

/**
* Somehow like the 'classpath' in Java. E.g. holds where to find ooc
Expand Down Expand Up @@ -118,7 +118,7 @@ PathList: class {
* Find the file in the given path element of the source path.
* @see getFile
*/
getFileInElement: func (path, elementPath: String) -> (File, File) {
getFileInElement: func (path, elementPath: String, params: BuildParams) -> (File, File) {
element := File new(elementPath)
reducedElement := element getReducedPath()
candidate := File new(element, path)
Expand All @@ -128,7 +128,7 @@ PathList: class {
if (!valid) {
// can't escape the sourcepath!
CommandLine error("Import %s was found at %s, but it can't escape source element %s" format(path, reduced, reducedElement))
CommandLine failure()
CommandLine failure(params)
}
return (candidate, element)
}
Expand Down
3 changes: 3 additions & 0 deletions source/rock/frontend/drivers/SequenceDriver.ooc
Expand Up @@ -109,6 +109,9 @@ SequenceDriver: class extends Driver {

link: func (module: Module) -> Int {
binaryPath := params getBinaryPath(module simpleName)
if (!binaryPath) {
return 1
}
binaryName := File new(binaryPath) name

// step 4 b: link that big thin archive
Expand Down
2 changes: 1 addition & 1 deletion source/rock/middle/tinker/Errors.ooc
Expand Up @@ -28,7 +28,7 @@ DefaultErrorHandler: class implements ErrorHandler {
e print()
println()
if(e fatal?() && params fatalError) {
CommandLine failure()
CommandLine failure(params)
}
}

Expand Down

0 comments on commit d0577e6

Please sign in to comment.