| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
define(["require", "dojo/has"], function(require, has){ |
| 37 |
|
| 38 |
|
| 39 |
if(has("host-node")){ |
| 40 |
define("commandLineArgs", function(){ |
| 41 |
|
| 42 |
return process.argv.slice(2); |
| 43 |
}); |
| 44 |
|
| 45 |
|
| 46 |
var util = require.nodeRequire("util"); |
| 47 |
debug = function(it, depth, inspect){ |
| 48 |
util.debug(inspect ? util.inspect(it, false, depth) : it); |
| 49 |
}; |
| 50 |
|
| 51 |
has.add("is-windows", process.platform == "win32"); |
| 52 |
}else if(has("host-rhino")){ |
| 53 |
define("commandLineArgs", [], function(){ |
| 54 |
var result = []; |
| 55 |
require.rawConfig.commandLineArgs.forEach(function(item){ |
| 56 |
var parts = item.split("="); |
| 57 |
if(parts[0]!="baseUrl"){ |
| 58 |
result.push(item); |
| 59 |
} |
| 60 |
}); |
| 61 |
return result; |
| 62 |
}); |
| 63 |
|
| 64 |
has.add("is-windows", /indows/.test(environment["os.name"])); |
| 65 |
}else{ |
| 66 |
console.log("unknown environment; terminating."); |
| 67 |
return 0; |
| 68 |
} |
| 69 |
|
| 70 |
this.require.scopeify = function(moduleList){ |
| 71 |
for(var p, mid, module, text = "", contextRequire = this, args = moduleList.split(","), i = 0; i<args.length;){ |
| 72 |
mid = args[i++].match(/\S+/)[0]; |
| 73 |
module = contextRequire(mid); |
| 74 |
mid = mid.match(/[^\/]+$/)[0]; |
| 75 |
for(p in module){ |
| 76 |
text+= "var " + p + "=" + mid + "." + p + ";\n"; |
| 77 |
} |
| 78 |
} |
| 79 |
return text; |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
require(["./buildControl", "./process"], function(bc, process){ |
| 84 |
var |
| 85 |
gateListeners = bc.gateListeners = [], |
| 86 |
|
| 87 |
transforms = bc.transforms, |
| 88 |
transformJobs = bc.transformJobs, |
| 89 |
transformJobsLength = transformJobs.length, |
| 90 |
|
| 91 |
|
| 92 |
resources = [], |
| 93 |
|
| 94 |
reportError = function(resource, err){ |
| 95 |
bc.log("transformFailed", ["resource", resource.src, "transform", resource.jobPos, "error", err]); |
| 96 |
resource.error = true; |
| 97 |
}, |
| 98 |
|
| 99 |
returnFromAsyncProc = function(resource, err){ |
| 100 |
bc.waiting--; |
| 101 |
if(err){ |
| 102 |
|
| 103 |
reportError(resource, err); |
| 104 |
} |
| 105 |
advance(resource, true); |
| 106 |
}, |
| 107 |
|
| 108 |
advance = function(resource, continuingSameGate){ |
| 109 |
if(resource.error){ |
| 110 |
return; |
| 111 |
} |
| 112 |
if(!continuingSameGate){ |
| 113 |
|
| 114 |
bc.waiting++; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
var err, nextJobPos, candidate; |
| 119 |
while(1){ |
| 120 |
nextJobPos = resource.jobPos + 1; |
| 121 |
candidate = nextJobPos<resource.job.length && resource.job[nextJobPos]; |
| 122 |
|
| 123 |
if(candidate && candidate[1]<=bc.currentGate){ |
| 124 |
resource.jobPos++; |
| 125 |
bc.waiting++; |
| 126 |
err = candidate[0](resource, returnFromAsyncProc); |
| 127 |
if(err===returnFromAsyncProc){ |
| 128 |
|
| 129 |
return; |
| 130 |
} |
| 131 |
bc.waiting--; |
| 132 |
if(err){ |
| 133 |
|
| 134 |
reportError(resource, err); |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
break; |
| 139 |
} |
| 140 |
}else{ |
| 141 |
break; |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
passGate(); |
| 147 |
}, |
| 148 |
|
| 149 |
advanceGate = function(currentGate){ |
| 150 |
while(1){ |
| 151 |
bc.currentGate = ++currentGate; |
| 152 |
bc.log("pacify", "starting " + bc.gates[bc.currentGate][2] + "..."); |
| 153 |
gateListeners.forEach(function(listener){ |
| 154 |
listener(bc.gates[bc.currentGate][1]); |
| 155 |
}); |
| 156 |
if(currentGate==bc.gates.length-1 || bc.gates[currentGate+1][0]){ |
| 157 |
|
| 158 |
return; |
| 159 |
} |
| 160 |
} |
| 161 |
}, |
| 162 |
|
| 163 |
passGate = bc.passGate = function(){ |
| 164 |
if(--bc.waiting){ |
| 165 |
return; |
| 166 |
} |
| 167 |
|
| 168 |
if(bc.checkDiscovery){ |
| 169 |
|
| 170 |
process.exit(0); |
| 171 |
} |
| 172 |
|
| 173 |
if(bc.currentGate<bc.gates.length-1){ |
| 174 |
advanceGate(bc.currentGate); |
| 175 |
|
| 176 |
bc.waiting++; |
| 177 |
resources.forEach(function(resource){ advance(resource, 0); }); |
| 178 |
|
| 179 |
passGate(); |
| 180 |
}else{ |
| 181 |
if(!resources.length){ |
| 182 |
bc.log("discoveryFailed"); |
| 183 |
} |
| 184 |
bc.log("pacify", "Process finished normally.\n\terrors: " + bc.getErrorCount() + "\n\twarnings: " + bc.getWarnCount() + "\n\tbuild time: " + ((new Date()).getTime() - bc.startTimestamp.getTime()) / 1000 + " seconds"); |
| 185 |
if(!bc.exitCode && bc.getErrorCount()){ |
| 186 |
bc.exitCode = 1; |
| 187 |
} |
| 188 |
process.exit(bc.exitCode); |
| 189 |
|
| 190 |
} |
| 191 |
}; |
| 192 |
|
| 193 |
bc.start = function(resource){ |
| 194 |
|
| 195 |
var |
| 196 |
src = resource.src, |
| 197 |
dest = resource.dest; |
| 198 |
if(bc.resourcesByDest[src]){ |
| 199 |
|
| 200 |
bc.log("overwrite", ["input", src, "resource destined for same location: ", bc.resourcesByDest[src].src]); |
| 201 |
return; |
| 202 |
} |
| 203 |
if(bc.resourcesByDest[dest]){ |
| 204 |
|
| 205 |
if(src !== bc.resourcesByDest[dest].src){ |
| 206 |
bc.log("outputCollide", ["source-1", src, "source-2", bc.resourcesByDest[dest].src]); |
| 207 |
} |
| 208 |
return; |
| 209 |
} |
| 210 |
|
| 211 |
bc.resources[resource.src] = resource; |
| 212 |
bc.resourcesByDest[resource.dest] = resource; |
| 213 |
|
| 214 |
if(bc.checkDiscovery){ |
| 215 |
bc.log("pacify", src + "-->" + dest); |
| 216 |
return; |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
for(var i = 0; i<transformJobsLength; i++){ |
| 221 |
if(transformJobs[i][0](resource, bc)){ |
| 222 |
|
| 223 |
|
| 224 |
resources.push(resource); |
| 225 |
resource.job = transformJobs[i][1]; |
| 226 |
resource.jobPos = -1; |
| 227 |
advance(resource); |
| 228 |
return; |
| 229 |
} |
| 230 |
} |
| 231 |
bc.log("noTransform", ["resoures", resource.src]); |
| 232 |
}; |
| 233 |
|
| 234 |
function doBuild(){ |
| 235 |
var |
| 236 |
transformNames = [], |
| 237 |
pluginNames = [], |
| 238 |
deps = []; |
| 239 |
bc.discoveryProcs.forEach(function(mid){ deps.push(mid); }); |
| 240 |
for(var p in bc.transforms){ |
| 241 |
|
| 242 |
transformNames.push(p); |
| 243 |
deps.push(bc.transforms[p][0]); |
| 244 |
} |
| 245 |
for(p in bc.plugins){ |
| 246 |
pluginNames.push(p); |
| 247 |
deps.push(bc.plugins[p]); |
| 248 |
} |
| 249 |
bc.plugins = {}; |
| 250 |
require(deps, function(){ |
| 251 |
|
| 252 |
for(var discoveryProcs = [], argsPos = 0; argsPos<bc.discoveryProcs.length; discoveryProcs.push(arguments[argsPos++])); |
| 253 |
|
| 254 |
|
| 255 |
for(var id, proc, i=0; i<transformNames.length;){ |
| 256 |
id = transformNames[i++]; |
| 257 |
proc = arguments[argsPos++]; |
| 258 |
|
| 259 |
transformJobs.forEach(function(item){ |
| 260 |
|
| 261 |
for(var transforms=item[1], i = 0; i<transforms.length; i++){ |
| 262 |
if(transforms[i][0]==id){ |
| 263 |
transforms[i][0] = proc; |
| 264 |
break; |
| 265 |
} |
| 266 |
} |
| 267 |
}); |
| 268 |
} |
| 269 |
for(i=0; i<pluginNames.length;){ |
| 270 |
bc.plugins[bc.getSrcModuleInfo(pluginNames[i++]).mid] = arguments[argsPos++]; |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
bc.waiting = 1; |
| 277 |
bc.log("pacify", "discovering resources..."); |
| 278 |
advanceGate(-1); |
| 279 |
discoveryProcs.forEach(function(proc){ proc(); }); |
| 280 |
passGate(); |
| 281 |
}); |
| 282 |
} |
| 283 |
|
| 284 |
if(!bc.getErrorCount() && bc.release){ |
| 285 |
doBuild(); |
| 286 |
} |
| 287 |
}); |
| 288 |
}); |