
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 ** CompilerInput encapsulates all the input needed run the compiler. 11 ** The compiler can be run in one of two modes - file or str. In 12 ** file mode the source code and resource files are read from the 13 ** file system. In str mode we compile a single source file from 14 ** an in-memory string. 15 ** 16 class CompilerInput 17 { 18 19 ////////////////////////////////////////////////////////////////////////// 20 // Fields 21 ////////////////////////////////////////////////////////////////////////// 22 23 ** 24 ** Location to use for reporting errors associated with the input 25 ** itself - typically this is mapped to the build script. 26 ** 27 Location inputLoc := Location.make("CompilerInput") 28 29 ** 30 ** Required name of output pod 31 ** 32 Str podName 33 34 ** 35 ** Flag to indicate if we are are compiling a script. Scripts 36 ** don't require explicit depends and can import any type via the 37 ** using statement or with qualified type names. 38 ** 39 Bool isScript := false 40 41 ** 42 ** Version to include in ouput pod's manifest. 43 ** 44 Version version := Version.fromStr("0.0.0") 45 46 ** 47 ** Description to include in output pod's manifest. 48 ** 49 Str description := "" 50 51 ** 52 ** User defined pod level facets. 53 ** 54 Str:Obj podFacets := Str:Obj[:] 55 56 ** 57 ** List of this pod's dependencies used for both the 58 ** compiler checking and output in the pod's manifest. 59 ** 60 Depend[] depends := Depend[,] 61 62 ** 63 ** The directory to look in for the dependency pod file (and 64 ** potentially their recursive dependencies). If null then we 65 ** use the compiler's own pod definitions via reflection (which 66 ** is more efficient). 67 ** 68 File dependsDir := null 69 70 ** 71 ** What type of output should be generated - the compiler 72 ** can be used to generate a transient in-memory pod or 73 ** to write out a pod zip file to disk. 74 ** 75 CompilerOutputMode output := null 76 77 ** 78 ** Log used for reporting compile status 79 ** 80 CompilerLog log := CompilerLog.make 81 82 ** 83 ** Output directory to write pod to, defaults to the 84 ** current runtime's lib directory 85 ** 86 File outDir := Sys.homeDir + `lib/fan/` 87 88 ** 89 ** Include fandoc in output pod, default is false 90 ** 91 Bool includeDoc := false 92 93 ** 94 ** Include source code in output pod, default is false 95 ** 96 Bool includeSrc := false 97 98 ** 99 ** Is this compile process being run inside a test, default is false 100 ** 101 Bool isTest := false 102 103 ** 104 ** This mode determines whether the source code is input 105 ** from the file system or from an in-memory string. 106 ** 107 CompilerInputMode mode := null 108 109 ////////////////////////////////////////////////////////////////////////// 110 // CompilerInputMode.file 111 ////////////////////////////////////////////////////////////////////////// 112 113 ** 114 ** Root directory of source tree - this directory is used to create 115 ** the relative paths of the resource files in the pod zip. 116 ** 117 File homeDir 118 119 ** 120 ** List of directories containing fan source files (file mode only) 121 ** 122 File[] srcDirs 123 124 ** 125 ** Optional list of directories containing resources files to 126 ** include in the pod zip (file mode only) 127 ** 128 File[] resDirs := File[,] 129 130 ////////////////////////////////////////////////////////////////////////// 131 // CompilerInputMode.str 132 ////////////////////////////////////////////////////////////////////////// 133 134 ** 135 ** Fan source code to compile (str mode only) 136 ** 137 Str srcStr 138 139 ** 140 ** Location to use for SourceFile facet (str mode only) 141 ** 142 Location srcStrLocation 143 144 ////////////////////////////////////////////////////////////////////////// 145 // Validation 146 ////////////////////////////////////////////////////////////////////////// 147 148 ** 149 ** Validate the CompilerInput is correctly 150 ** configured, throw CompilerErr is not. 151 ** 152 internal Void validate() 153 { 154 validateReqField("podName") 155 validateReqField("version") 156 validateReqField("description") 157 validateReqField("depends") 158 validateReqField("output") 159 validateReqField("outDir") 160 validateReqField("includeDoc") 161 validateReqField("includeSrc") 162 validateReqField("isTest") 163 validateReqField("mode") 164 switch (mode) 165 { 166 case CompilerInputMode.file: 167 validateReqField("homeDir") 168 validateReqField("srcDirs") 169 validateReqField("resDirs") 170 case CompilerInputMode.str: 171 validateReqField("srcStr") 172 validateReqField("srcStrLocation") 173 } 174 } 175 176 ** 177 ** Check that the specified field is non-null, if not 178 ** then log an error and return false. 179 ** 180 private Void validateReqField(Str field) 181 { 182 val := type.field(field).get(this) 183 if (val == null) 184 throw CompilerErr.make("CompilerInput.${field} not set", null) 185 } 186 } 187 188 ************************************************************************** 189 ** CompilerInputMode 190 ************************************************************************** 191 192 ** 193 ** Input source from the file system 194 ** 195 enum CompilerInputMode 196 { 197 file, 198 str 199 } 200