0
# Compiler Management
1
2
Core compiler creation, caching, and incremental compilation execution functionality.
3
4
## Capabilities
5
6
### Compiler Factory Methods
7
8
Factory methods for creating and managing compiler instances with caching support.
9
10
```scala { .api }
11
/**
12
* Get or create cached compiler instance
13
* @param setup Compiler configuration and jar locations
14
* @param log Logger for compilation messages
15
* @return Compiler instance (cached or newly created)
16
*/
17
def apply(setup: Setup, log: Logger): Compiler
18
19
/**
20
* Java API for getting or creating compiler instance
21
* @param setup Compiler configuration and jar locations
22
* @param log Logger for compilation messages
23
* @return Compiler instance (cached or newly created)
24
*/
25
def getOrCreate(setup: Setup, log: Logger): Compiler
26
27
/**
28
* Create new compiler instance (bypassing cache)
29
* @param setup Compiler configuration and jar locations
30
* @param log Logger for compilation messages
31
* @return New compiler instance
32
*/
33
def create(setup: Setup, log: Logger): Compiler
34
```
35
36
### Scala Compiler Creation
37
38
Create Scala compiler instances with proper configuration.
39
40
```scala { .api }
41
/**
42
* Create new Scala compiler instance
43
* @param instance Scala instance with compiler jars
44
* @param interfaceJar Compiler interface jar file
45
* @return Analyzing compiler for Scala compilation
46
*/
47
def newScalaCompiler(instance: ScalaInstance, interfaceJar: File): AnalyzingCompiler
48
```
49
50
### Java Compiler Creation
51
52
Create Java compiler instances for mixed compilation.
53
54
```scala { .api }
55
/**
56
* Create new Java compiler instance
57
* @param instance Scala instance for compatibility
58
* @param javaHome Optional Java home directory
59
* @param fork Whether to fork Java compiler process
60
* @return Java compiler instance
61
*/
62
def newJavaCompiler(instance: ScalaInstance, javaHome: Option[File], fork: Boolean): JavaCompiler
63
```
64
65
### Compiler Cache Management
66
67
Create and manage compiler caches for performance optimization.
68
69
```scala { .api }
70
/**
71
* Create resident compiler cache
72
* @param maxCompilers Maximum number of cached compilers
73
* @return Globals cache for compiler instances
74
*/
75
def createResidentCache(maxCompilers: Int): GlobalsCache
76
```
77
78
### Scala Instance Management
79
80
Manage Scala compiler instances and classloaders.
81
82
```scala { .api }
83
/**
84
* Create Scala instance from setup configuration
85
* @param setup Setup containing Scala jar locations
86
* @return Scala instance for compilation
87
*/
88
def scalaInstance(setup: Setup): ScalaInstance
89
90
/**
91
* Create Scala classloader from jar files
92
* @param jars Scala jar files (compiler, library, extras)
93
* @return URL classloader for Scala classes
94
*/
95
def scalaLoader(jars: Seq[File]): URLClassLoader
96
97
/**
98
* Extract Scala version from classloader
99
* @param scalaLoader Scala classloader
100
* @return Optional Scala version string
101
*/
102
def scalaVersion(scalaLoader: ClassLoader): Option[String]
103
```
104
105
### Compiler Interface Management
106
107
Manage compiler interface compilation and caching.
108
109
```scala { .api }
110
/**
111
* Get or compile compiler interface
112
* @param setup Setup with interface source location
113
* @param scalaInstance Scala instance for compilation
114
* @param log Logger for interface compilation
115
* @return Compiled interface jar file
116
*/
117
def compilerInterface(setup: Setup, scalaInstance: ScalaInstance, log: Logger): File
118
119
/**
120
* Generate interface identifier for caching
121
* @param scalaVersion Scala version string
122
* @return Interface identifier string
123
*/
124
def interfaceId(scalaVersion: String): String
125
```
126
127
### Compilation Execution
128
129
Execute incremental compilation with full configuration.
130
131
```scala { .api }
132
/**
133
* Execute incremental compilation
134
* @param inputs Compilation inputs (sources, classpath, options)
135
* @param cwd Optional working directory
136
* @param reporter Reporter for compilation messages and errors
137
* @param progress Progress tracker for compilation phases
138
* @param log Logger for compilation messages
139
*/
140
def compile(inputs: Inputs, cwd: Option[File], reporter: xsbti.Reporter,
141
progress: xsbti.compile.CompileProgress)(log: Logger): Unit
142
```
143
144
### Classpath Management
145
146
Automatic classpath generation for compilation.
147
148
```scala { .api }
149
/**
150
* Generate automatic compilation classpath
151
* @param classesDirectory Output directory for compiled classes
152
* @param allScalaJars All Scala-related jar files
153
* @param javaOnly Whether this is Java-only compilation
154
* @param classpath Base classpath entries
155
* @return Complete classpath for compilation
156
*/
157
def autoClasspath(classesDirectory: File, allScalaJars: Seq[File],
158
javaOnly: Boolean, classpath: Seq[File]): Seq[File]
159
```
160
161
## Usage Examples
162
163
```scala
164
import org.pantsbuild.zinc._
165
import org.pantsbuild.zinc.logging._
166
import java.io.File
167
168
// Create compiler setup
169
val settings = Settings.parse(args.toSeq).get
170
val setup = Setup(settings)
171
val log = Loggers.create(Level.Info, color = true)
172
173
// Get cached compiler instance
174
val compiler = Compiler(setup, log)
175
176
// Prepare compilation inputs
177
val inputs = Inputs(log, settings)
178
val reporter = Reporters.create(log, Seq.empty, Seq.empty)
179
val progress = new SimpleCompileProgress(true, true, 10, log)
180
181
// Execute compilation
182
compiler.compile(inputs, Some(new File(".")), reporter, progress)(log)
183
```
184
185
## Constants
186
187
```scala { .api }
188
val CompilerInterfaceId: String // Default compiler interface identifier
189
val JavaClassVersion: String // Java class version requirement
190
```