Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.67 KB | None | 0 0
  1. /*
  2. * Zinc - The incremental compiler for Scala.
  3. * Copyright 2011 - 2017, Lightbend, Inc.
  4. * Copyright 2008 - 2010, Mark Harrah
  5. * This software is released under the terms written in LICENSE.
  6. */
  7.  
  8. package xsbti.compile;
  9.  
  10. import xsbti.*;
  11.  
  12. import java.io.File;
  13.  
  14. /*
  15. * This API is subject to change.
  16. *
  17. * It is the client's responsibility to:
  18. * 1. Manage class loaders. Usually the client will want to:
  19. * i. Keep the class loader used by the ScalaInstance warm.
  20. * ii. Keep the class loader of the incremental recompilation classes (xsbti.compile) warm.
  21. * iii. Share the class loader for Scala classes between the incremental compiler implementation and the ScalaInstance where possible (must be binary compatible)
  22. * 2. Manage the compiler interface jar. The interface must be compiled against the exact Scala version used for compilation and a compatible Java version.
  23. * 3. Manage compilation order between different compilations.
  24. * i. Execute a compilation for each dependency, obtaining an Analysis for each.
  25. * ii. Provide the Analysis from previous compilations to dependent compilations in the analysis map.
  26. * 4. Provide an implementation of JavaCompiler for compiling Java sources.
  27. * 5. Define a function that determines if a classpath entry contains a class (Setup.definesClass).
  28. * i. This is provided by the client so that the client can cache this information across compilations when compiling multiple sets of sources.
  29. * ii. The cache should be cleared for each new compilation run or else recompilation will not properly account for changes to the classpath.
  30. * 6. Provide a cache directory.
  31. * i. This directory is used by IncrementalCompiler to persist data between compilations.
  32. * ii. It should be a different directory for each set of sources being compiled.
  33. * 7. Manage parallel execution.
  34. * i. Each compilation may be performed in a different thread as long as the dependencies have been compiled already.
  35. * ii. Implementations of all types should be immutable and arrays treated as immutable.
  36. * 8. Ensure general invariants:
  37. * i. The implementations of all types are immutable, except for the already discussed Setup.definesClass.
  38. * ii. Arrays are treated as immutable.
  39. * iii. No value is ever null.
  40. */
  41. public interface IncrementalCompiler {
  42.  
  43. /**
  44. * Performs an incremental compilation given an instance of {@link Inputs}.
  45. *
  46. * @param in An instance of {@link Inputs} that collect all the inputs
  47. * required to run the compiler (from sources and classpath, to
  48. * compilation order, previous results, current setup, etc).
  49. * @param logger An instance of {@link Logger} that logs Zinc output.
  50. *
  51. * @see IncrementalCompiler#inputs(CompileOptions, Compilers, Setup, PreviousResult)
  52. * @see IncrementalCompiler#setup(PerClasspathEntryLookup, boolean, File, GlobalsCache, IncOptions, Reporter, Maybe, T2[])
  53. *
  54. * @return An instance of {@link CompileResult} that holds information
  55. * about the results of the compilation.
  56. */
  57. CompileResult compile(Inputs in, Logger logger);
  58.  
  59. /**
  60. * Performs an incremental compilation given its configuration.
  61. *
  62. * @param scalaCompiler The Scala compiler to compile Scala sources.
  63. * @param javaCompiler The Java compiler to compile Java sources.
  64. * @param sources An array of Java and Scala source files to be compiled.
  65. * @param classpath An array of files representing classpath entries.
  66. * @param output An instance of {@link Output} to store the compiler outputs.
  67. * @param globalsCache Directory where previous cached compilers are stored.
  68. * @param scalacOptions An array of options/settings for the Scala compiler.
  69. * @param javacOptions An array of options for the Java compiler.
  70. * @param previousAnalysis Optional previous incremental compilation analysis.
  71. * @param previousSetup Optional previous incremental compilation setup.
  72. * @param perClasspathEntryLookup Lookup of data structures and operations
  73. * for a given classpath entry.
  74. * @param reporter An instance of {@link Reporter} to report compiler output.
  75. * @param compileOrder The order in which Java and Scala sources should
  76. * be compiled.
  77. * @param skip Flag to ignore this compilation run and return previous one.
  78. * @param progress An instance of {@link CompileProgress} to keep track of
  79. * the current compilation progress.
  80. * @param incrementalOptions An Instance of {@link IncOptions} that
  81. * configures the incremental compiler behaviour.
  82. * @param extra An array of sbt tuples with extra options.
  83. * @param logger An instance of {@link Logger} that logs Zinc output.
  84. *
  85. *
  86. * @return An instance of {@link CompileResult} that holds information
  87. * about the results of the compilation.
  88. */
  89. CompileResult compile(ScalaCompiler scalaCompiler,
  90. JavaCompiler javaCompiler,
  91. File[] sources,
  92. File[] classpath,
  93. Output output,
  94. GlobalsCache globalsCache,
  95. String[] scalacOptions,
  96. String[] javacOptions,
  97. Maybe<CompileAnalysis> previousAnalysis,
  98. Maybe<Setup> previousSetup,
  99. PerClasspathEntryLookup perClasspathEntryLookup,
  100. Reporter reporter,
  101. CompileOrder compileOrder,
  102. boolean skip,
  103. Maybe<CompileProgress> progress,
  104. IncOptions incrementalOptions,
  105. T2<String, String>[] extra,
  106. Logger logger);
  107.  
  108. /**
  109. * Create an instance of {@link Inputs} from instances of the internal
  110. * Zinc API to run {@link #compile(Inputs, Logger) compile}.
  111. *
  112. * @param compileOptions An instance of {@link CompileOptions} containing
  113. * input information (e.g. sources, classpaths, etc).
  114. * @param compilers An instance of {@link Compilers} that include both
  115. * Java and Scala compilers.
  116. * @param setup An instance of {@link Setup} that configures incremental
  117. * compilation for both Java and Scala compilers.
  118. * @param previousResult An instance of {@link PreviousResult} that includes
  119. * information about last incremental compilation run.
  120. *
  121. * @return An instance of {@link Inputs}.
  122. */
  123. Inputs inputs(CompileOptions compileOptions,
  124. Compilers compilers,
  125. Setup setup,
  126. PreviousResult previousResult);
  127.  
  128. /**
  129. * Create an instance of {@link Inputs} by passing general compiler options
  130. * as parameters to run {@link #compile(Inputs, Logger) compile}.
  131. *
  132. * @param classpath An array of files representing classpath entries.
  133. * @param sources An array of Java and Scala source files to be compiled.
  134. * @param classesDirectory A file where the classfiles should be stored.
  135. * @param scalacOptions An array of options/settings for the Scala compiler.
  136. * @param javacOptions An array of options for the Java compiler.
  137. * @param maxErrors The maximum number of errors that will be reported.
  138. * @param sourcePositionMappers An array of sbt functions that take a
  139. * position and maps it to a source position.
  140. * @param compileOrder The order in which Java and Scala sources should
  141. * be compiled.
  142. * @param compilers An instance of {@link Compilers} that include both
  143. * Java and Scala compilers.
  144. * @param setup An instance of {@link Setup} that configures incremental
  145. * compilation for both Java and Scala compilers.
  146. * @param previousResult An instance of {@link PreviousResult} that includes
  147. * information about last incremental compilation run.
  148. *
  149. * @return An instance of {@link Inputs} usable to run .
  150. */
  151. Inputs inputs(File[] classpath,
  152. File[] sources,
  153. File classesDirectory,
  154. String[] scalacOptions,
  155. String[] javacOptions,
  156. int maxErrors,
  157. F1<Position, Maybe<Position>>[] sourcePositionMappers,
  158. CompileOrder compileOrder,
  159. Compilers compilers,
  160. Setup setup,
  161. PreviousResult previousResult);
  162.  
  163. /**
  164. * Create an instance of {@link Setup}, useful to create an instance of
  165. * {@link Inputs}.
  166. *
  167. * @param perClasspathEntryLookup Lookup of data structures and operations
  168. * for a given classpath entry.
  169. * @param skip Flag to ignore this compilation run and return previous one.
  170. * @param cacheFile Cache directory for the incremental compiler.
  171. * @param globalsCache Directory where previous cached compilers are stored.
  172. * @param incrementalOptions An Instance of {@link IncOptions} that
  173. * configures the incremental compiler behaviour.
  174. * @param reporter An instance of {@link Reporter} to report compiler output.
  175. * @param progress An instance of {@link CompileProgress} to keep track of
  176. * the current compilation progress.
  177. * @param extra An array of sbt tuples with extra options.
  178. *
  179. * @return A {@link Setup} instance, useful to create {@link Inputs}.
  180. */
  181. Setup setup(PerClasspathEntryLookup perClasspathEntryLookup,
  182. boolean skip,
  183. File cacheFile,
  184. GlobalsCache globalsCache,
  185. IncOptions incrementalOptions,
  186. Reporter reporter,
  187. Maybe<CompileProgress> progress,
  188. T2<String, String>[] extra);
  189.  
  190. /**
  191. * Create a Scala compiler from a {@link ScalaInstance}, the jar defining
  192. * the compiler interface to be used and {@link ClasspathOptions}.
  193. *
  194. * @param scalaInstance The Scala instance to be used.
  195. * @param compilerInterfaceJar The jar file of the compiler interface.
  196. * @param classpathOptions The options of all the classpath that the
  197. * compiler takes in.
  198. *
  199. * @return A Scala compiler with the given configuration.
  200. */
  201. /* ScalaCompiler scalaCompiler(ScalaInstance scalaInstance,
  202. File compilerInterfaceJar,
  203. ClasspathOptions classpathOptions);*/
  204.  
  205. /**
  206. * Compile the compiler interface for a Scala version from concrete sources.
  207. *
  208. * This is necessary to run {@link this#scalaCompiler(ScalaInstance, File, ClasspathOptions)}
  209. * to create a {@link ScalaCompiler} instance that can be used for
  210. * incremental compilation.
  211. *
  212. * It is the client's responsability to manage compiled jars for different
  213. * Scala versions.
  214. *
  215. * @param label A brief name describing the source component for use in error messages
  216. * @param sourceJar The jar file containing the implementation of the compiler interface.
  217. * @param targetJar The directory to store the compiled class files.
  218. * @param interfaceJar The jar file that defines the compiler interface.
  219. * @param instance The ScalaInstance to compile the compiler interface for.
  220. * @param log The logger to use during compilation.
  221. */
  222. /* void compileScalaBridge(String label,
  223. File sourceJar,
  224. File targetJar,
  225. File interfaceJar,
  226. ScalaInstance instance,
  227. Logger log);*/
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement