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 ** List of this pod's dependencies used for both the
53 ** compiler checking and output in the pod's manifest.
54 **
55 Depend[] depends := Depend[,]
56
57 **
58 ** The directory to look in for the dependency pod file (and
59 ** potentially their recursive dependencies). If null then we
60 ** use the compiler's own pod definitions via reflection (which
61 ** is more efficient).
62 **
63 File dependsDir := null
64
65 **
66 ** What type of output should be generated - the compiler
67 ** can be used to generate a transient in-memory pod or
68 ** to write out a pod zip file to disk.
69 **
70 CompilerOutputMode output := null
71
72 **
73 ** Log used for reporting compile status
74 **
75 CompilerLog log := CompilerLog.make
76
77 **
78 ** Output directory to write pod to, defaults to the
79 ** current runtime's lib directory
80 **
81 File outDir := Sys.homeDir + `lib/fan/`
82
83 **
84 ** Include fandoc in output pod, default is false
85 **
86 Bool includeDoc := false
87
88 **
89 ** Include source code in output pod, default is false
90 **
91 Bool includeSrc := false
92
93 **
94 ** Is this compile process being run inside a test, default is false
95 **
96 Bool isTest := false
97
98 **
99 ** This mode determines whether the source code is input
100 ** from the file system or from an in-memory string.
101 **
102 CompilerInputMode mode := null
103
104 //////////////////////////////////////////////////////////////////////////
105 // CompilerInputMode.file
106 //////////////////////////////////////////////////////////////////////////
107
108 **
109 ** Root directory of source tree - this directory is used to create
110 ** the relative paths of the resource files in the pod zip.
111 **
112 File homeDir
113
114 **
115 ** List of directories containing fan source files (file mode only)
116 **
117 File[] srcDirs
118
119 **
120 ** Optional list of directories containing resources files to
121 ** include in the pod zip (file mode only)
122 **
123 File[] resDirs := File[,]
124
125 //////////////////////////////////////////////////////////////////////////
126 // CompilerInputMode.str
127 //////////////////////////////////////////////////////////////////////////
128
129 **
130 ** Fan source code to compile (str mode only)
131 **
132 Str srcStr
133
134 **
135 ** Location to use for SourceFile facet (str mode only)
136 **
137 Location srcStrLocation
138
139 //////////////////////////////////////////////////////////////////////////
140 // Validation
141 //////////////////////////////////////////////////////////////////////////
142
143 **
144 ** Validate the CompilerInput is correctly
145 ** configured, throw CompilerErr is not.
146 **
147 internal Void validate()
148 {
149 validateReqField("podName")
150 validateReqField("version")
151 validateReqField("description")
152 validateReqField("depends")
153 validateReqField("output")
154 validateReqField("outDir")
155 validateReqField("includeDoc")
156 validateReqField("includeSrc")
157 validateReqField("isTest")
158 validateReqField("mode")
159 switch (mode)
160 {
161 case CompilerInputMode.file:
162 validateReqField("homeDir")
163 validateReqField("srcDirs")
164 validateReqField("resDirs")
165 case CompilerInputMode.str:
166 validateReqField("srcStr")
167 validateReqField("srcStrLocation")
168 }
169 }
170
171 **
172 ** Check that the specified field is non-null, if not
173 ** then log an error and return false.
174 **
175 private Void validateReqField(Str field)
176 {
177 val := type.field(field).get(this)
178 if (val == null)
179 throw CompilerErr.make("CompilerInput.${field} not set", null)
180 }
181 }
182
183 **************************************************************************
184 ** CompilerInputMode
185 **************************************************************************
186
187 **
188 ** Input source from the file system
189 **
190 enum CompilerInputMode
191 {
192 file,
193 str
194 }
195
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 ** List of this pod's dependencies used for both the
53 ** compiler checking and output in the pod's manifest.
54 **
55 Depend[] depends := Depend[,]
56
57 **
58 ** The directory to look in for the dependency pod file (and
59 ** potentially their recursive dependencies). If null then we
60 ** use the compiler's own pod definitions via reflection (which
61 ** is more efficient).
62 **
63 File dependsDir := null
64
65 **
66 ** What type of output should be generated - the compiler
67 ** can be used to generate a transient in-memory pod or
68 ** to write out a pod zip file to disk.
69 **
70 CompilerOutputMode output := null
71
72 **
73 ** Log used for reporting compile status
74 **
75 CompilerLog log := CompilerLog.make
76
77 **
78 ** Output directory to write pod to, defaults to the
79 ** current runtime's lib directory
80 **
81 File outDir := Sys.homeDir + `lib/fan/`
82
83 **
84 ** Include fandoc in output pod, default is false
85 **
86 Bool includeDoc := false
87
88 **
89 ** Include source code in output pod, default is false
90 **
91 Bool includeSrc := false
92
93 **
94 ** Is this compile process being run inside a test, default is false
95 **
96 Bool isTest := false
97
98 **
99 ** This mode determines whether the source code is input
100 ** from the file system or from an in-memory string.
101 **
102 CompilerInputMode mode := null
103
104 //////////////////////////////////////////////////////////////////////////
105 // CompilerInputMode.file
106 //////////////////////////////////////////////////////////////////////////
107
108 **
109 ** Root directory of source tree - this directory is used to create
110 ** the relative paths of the resource files in the pod zip.
111 **
112 File homeDir
113
114 **
115 ** List of directories containing fan source files (file mode only)
116 **
117 File[] srcDirs
118
119 **
120 ** Optional list of directories containing resources files to
121 ** include in the pod zip (file mode only)
122 **
123 File[] resDirs := File[,]
124
125 //////////////////////////////////////////////////////////////////////////
126 // CompilerInputMode.str
127 //////////////////////////////////////////////////////////////////////////
128
129 **
130 ** Fan source code to compile (str mode only)
131 **
132 Str srcStr
133
134 **
135 ** Location to use for SourceFile facet (str mode only)
136 **
137 Location srcStrLocation
138
139 //////////////////////////////////////////////////////////////////////////
140 // Validation
141 //////////////////////////////////////////////////////////////////////////
142
143 **
144 ** Validate the CompilerInput is correctly
145 ** configured, throw CompilerErr is not.
146 **
147 internal Void validate()
148 {
149 validateReqField("podName")
150 validateReqField("version")
151 validateReqField("description")
152 validateReqField("depends")
153 validateReqField("output")
154 validateReqField("outDir")
155 validateReqField("includeDoc")
156 validateReqField("includeSrc")
157 validateReqField("isTest")
158 validateReqField("mode")
159 switch (mode)
160 {
161 case CompilerInputMode.file:
162 validateReqField("homeDir")
163 validateReqField("srcDirs")
164 validateReqField("resDirs")
165 case CompilerInputMode.str:
166 validateReqField("srcStr")
167 validateReqField("srcStrLocation")
168 }
169 }
170
171 **
172 ** Check that the specified field is non-null, if not
173 ** then log an error and return false.
174 **
175 private Void validateReqField(Str field)
176 {
177 val := type.field(field).get(this)
178 if (val == null)
179 throw CompilerErr.make("CompilerInput.${field} not set", null)
180 }
181 }
182
183 **************************************************************************
184 ** CompilerInputMode
185 **************************************************************************
186
187 **
188 ** Input source from the file system
189 **
190 enum CompilerInputMode
191 {
192 file,
193 str
194 }
195