
1 // 2 // Copyright (c) 2006, Brian Frank and Andy Frank 3 // Licensed under the Academic Free License version 3.0 4 // 5 // History: 6 // 4 Nov 06 Brian Frank Creation 7 // 8 9 ** 10 ** Target models a build target which may be executed independently 11 ** within a build script. Targets are the top level unit for organizing 12 ** build scripts - each script publishes its available targets via 13 ** `BuildScript.targets`. 14 ** 15 class Target 16 { 17 18 ////////////////////////////////////////////////////////////////////////// 19 // Construction 20 ////////////////////////////////////////////////////////////////////////// 21 22 ** 23 ** Construct a target to run under the specified build script. 24 ** The name is the key used to invoke this target from the command 25 ** line. Description is used for usage summary. Method is invoked 26 ** when this target is executed. 27 ** 28 new make(BuildScript script, Str name, Str description, Func func) 29 { 30 this.script = script 31 this.name = name 32 this.description = description 33 this.func = func 34 } 35 36 ////////////////////////////////////////////////////////////////////////// 37 // Identity 38 ////////////////////////////////////////////////////////////////////////// 39 40 ** 41 ** Return the parent build script associated with this task. 42 ** 43 readonly BuildScript script 44 45 ** 46 ** Name is the key used to invoke this target from the command line. 47 ** 48 readonly Str name 49 50 ** 51 ** Description is used for usage summary. 52 ** 53 readonly Str description 54 55 ** 56 ** Function to invoke when this target is executed. 57 ** 58 readonly Func func 59 60 ** 61 ** Return name. 62 ** 63 override Str toStr() { return name } 64 65 ////////////////////////////////////////////////////////////////////////// 66 // Run 67 ////////////////////////////////////////////////////////////////////////// 68 69 ** 70 ** Run this target by invoking the target's method. If the target 71 ** fails to run then it should report errors via the log and throw 72 ** FatalBuildErr. 73 ** 74 virtual Void run() 75 { 76 try 77 { 78 func.call0() 79 } 80 catch (FatalBuildErr err) 81 { 82 throw err 83 } 84 catch (Err err) 85 { 86 script.log.error("Target '$name' failed [$script.toStr]") 87 err.trace 88 throw FatalBuildErr.make(null, err) 89 } 90 } 91 92 }