Add -dryrun flag for testing, improve the behavior of 'rebuild'

This commit is contained in:
Joshua Granick
2014-11-20 09:43:27 -08:00
parent 11a5eee0e9
commit 451a1ccc9a
6 changed files with 118 additions and 64 deletions

View File

@@ -19,8 +19,6 @@
<section unless="display || lime-legacy"> <section unless="display || lime-legacy">
<haxelib name="hxcpp" if="cpp" />
<ndll name="std" haxelib="hxcpp" if="cpp" /> <ndll name="std" haxelib="hxcpp" if="cpp" />
<ndll name="regexp" haxelib="hxcpp" if="cpp" /> <ndll name="regexp" haxelib="hxcpp" if="cpp" />
<ndll name="zlib" haxelib="hxcpp" if="cpp" /> <ndll name="zlib" haxelib="hxcpp" if="cpp" />

View File

@@ -1560,6 +1560,10 @@ class CommandLineTools {
argument = "-verbose"; argument = "-verbose";
LogHelper.verbose = true; LogHelper.verbose = true;
} else if (argument == "-dryrun") {
ProcessHelper.dryRun = true;
} else if (argument == "-notrace") { } else if (argument == "-notrace") {
traceEnabled = false; traceEnabled = false;

View File

@@ -14,6 +14,7 @@ class CPPHelper {
private static var rebuiltLibraries = new Map <String, Bool> (); private static var rebuiltLibraries = new Map <String, Bool> ();
private static var rebuiltPaths = new Map <String, Bool> ();
public static function compile (project:HXProject, path:String, flags:Array<String> = null, buildFile:String = "Build.xml"):Void { public static function compile (project:HXProject, path:String, flags:Array<String> = null, buildFile:String = "Build.xml"):Void {
@@ -128,6 +129,7 @@ class CPPHelper {
var defines = StringMapHelper.copy (project.defines); var defines = StringMapHelper.copy (project.defines);
defines.set ("rebuild", 1); defines.set ("rebuild", 1);
var haxelibProject = HXProject.fromHaxelib (haxelib, defines); var haxelibProject = HXProject.fromHaxelib (haxelib, defines);
if (haxelibProject == null) { if (haxelibProject == null) {
@@ -140,7 +142,13 @@ class CPPHelper {
StringMapHelper.copyKeys (project.targetFlags, haxelibProject.targetFlags); StringMapHelper.copyKeys (project.targetFlags, haxelibProject.targetFlags);
rebuiltLibraries.set (haxelib.name, true); rebuiltLibraries.set (haxelib.name, true);
rebuild (haxelibProject, commands);
if (!rebuiltPaths.exists (haxelibProject.config.get ("project.rebuild.path"))) {
rebuiltPaths.set (haxelibProject.config.get ("project.rebuild.path"), true);
rebuild (haxelibProject, commands);
}
} }
@@ -198,7 +206,11 @@ class CPPHelper {
} }
if (!FileSystem.exists (path)) return; if (path == null || !FileSystem.exists (path)) {
return;
}
if (buildFile == null && project.config.exists ("project.rebuild.file")) { if (buildFile == null && project.config.exists ("project.rebuild.file")) {
@@ -208,7 +220,11 @@ class CPPHelper {
if (buildFile == null) buildFile = "Build.xml"; if (buildFile == null) buildFile = "Build.xml";
if (!FileSystem.exists (PathHelper.combine (path, buildFile))) return; if (!FileSystem.exists (PathHelper.combine (path, buildFile))) {
return;
}
var args = [ "run", project.config.getString ("cpp.buildLibrary", "hxcpp"), buildFile ]; var args = [ "run", project.config.getString ("cpp.buildLibrary", "hxcpp"), buildFile ];

View File

@@ -188,8 +188,13 @@ class PathHelper {
try { try {
var cacheDryRun = ProcessHelper.dryRun;
ProcessHelper.dryRun = false;
output = ProcessHelper.runProcess (Sys.getEnv ("HAXEPATH"), "haxelib", [ "path", name ], true, true, true); output = ProcessHelper.runProcess (Sys.getEnv ("HAXEPATH"), "haxelib", [ "path", name ], true, true, true);
ProcessHelper.dryRun = cacheDryRun;
} catch (e:Dynamic) { } } catch (e:Dynamic) { }
LogHelper.verbose = cache; LogHelper.verbose = cache;

View File

@@ -12,6 +12,7 @@ import sys.FileSystem;
class ProcessHelper { class ProcessHelper {
public static var dryRun:Bool = false;
public static var processorCores (get_processorCores, null):Int; public static var processorCores (get_processorCores, null):Int;
private static var _processorCores:Int = 0; private static var _processorCores:Int = 0;
@@ -183,8 +184,12 @@ class ProcessHelper {
LogHelper.info ("", " - \x1b[1mChanging directory:\x1b[0m " + path + ""); LogHelper.info ("", " - \x1b[1mChanging directory:\x1b[0m " + path + "");
oldPath = Sys.getCwd (); if (!dryRun) {
Sys.setCwd (path);
oldPath = Sys.getCwd ();
Sys.setCwd (path);
}
} }
@@ -212,19 +217,23 @@ class ProcessHelper {
var result = 0; var result = 0;
if (args != null && args.length > 0) { if (!dryRun) {
result = Sys.command (command, args); if (args != null && args.length > 0) {
result = Sys.command (command, args);
} else {
result = Sys.command (command);
}
} else { if (oldPath != "") {
result = Sys.command (command); Sys.setCwd (oldPath);
} }
if (oldPath != "") {
Sys.setCwd (oldPath);
} }
@@ -306,8 +315,12 @@ class ProcessHelper {
LogHelper.info ("", " - \x1b[1mChanging directory:\x1b[0m " + path + ""); LogHelper.info ("", " - \x1b[1mChanging directory:\x1b[0m " + path + "");
oldPath = Sys.getCwd (); if (!dryRun) {
Sys.setCwd (path);
oldPath = Sys.getCwd ();
Sys.setCwd (path);
}
} }
@@ -332,72 +345,76 @@ class ProcessHelper {
var output = ""; var output = "";
var result = 0; var result = 0;
var process = new Process (command, args); if (!dryRun) {
var buffer = new BytesOutput ();
if (waitForOutput) {
var waiting = true; var process = new Process (command, args);
var buffer = new BytesOutput ();
while (waiting) { if (waitForOutput) {
try { var waiting = true;
while (waiting) {
var current = process.stdout.readAll (1024); try {
buffer.write (current);
var current = process.stdout.readAll (1024);
if (current.length == 0) { buffer.write (current);
if (current.length == 0) {
waiting = false;
}
} catch (e:Eof) {
waiting = false; waiting = false;
} }
} catch (e:Eof) {
waiting = false;
} }
} result = process.exitCode ();
process.close();
result = process.exitCode ();
process.close();
//if (result == 0) {
output = buffer.getBytes ().toString (); //if (result == 0) {
if (output == "") {
var error = process.stderr.readAll ().toString (); output = buffer.getBytes ().toString ();
if (ignoreErrors) { if (output == "") {
output = error; var error = process.stderr.readAll ().toString ();
} else { if (ignoreErrors) {
output = error;
} else {
LogHelper.error (error);
}
LogHelper.error (error); return null;
/*if (error != "") {
LogHelper.error (error);
}*/
} }
return null; //}
/*if (error != "") {
LogHelper.error (error);
}*/
}
//} }
} if (oldPath != "") {
if (oldPath != "") { Sys.setCwd (oldPath);
Sys.setCwd (oldPath); }
} }
@@ -415,6 +432,9 @@ class ProcessHelper {
public static function get_processorCores ():Int { public static function get_processorCores ():Int {
var cacheDryRun = dryRun;
dryRun = false;
if (_processorCores < 1) { if (_processorCores < 1) {
var result = null; var result = null;
@@ -471,6 +491,8 @@ class ProcessHelper {
} }
dryRun = cacheDryRun;
return _processorCores; return _processorCores;
} }

View File

@@ -49,6 +49,15 @@ class PlatformTarget {
if (!Reflect.hasField (metaFields.rebuild, "ignore") && (command == "rebuild" || project.targetFlags.exists ("rebuild"))) { if (!Reflect.hasField (metaFields.rebuild, "ignore") && (command == "rebuild" || project.targetFlags.exists ("rebuild"))) {
LogHelper.info ("", "\n" + LogHelper.accentColor + "Running command: REBUILD" + LogHelper.resetColor); LogHelper.info ("", "\n" + LogHelper.accentColor + "Running command: REBUILD" + LogHelper.resetColor);
// hack for now, need to move away from project.rebuild.path, probably
if (project.targetFlags.exists ("rebuild")) {
project.config.set ("project.rebuild.path", null);
}
rebuild (); rebuild ();
} }