Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #351 from scalacenter/protobuf
Add protobuf-based analysis binary store
- Loading branch information
Showing
52 changed files
with
3,431 additions
and
610 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
internal/zinc-compile-core/src/main/java/xsbti/compile/CompilerCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
internal/zinc-persist/src/main/java/xsbti/compile/analysis/GenericMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Zinc - The incremental compiler for Scala. | ||
* Copyright 2011 - 2017, Lightbend, Inc. | ||
* Copyright 2008 - 2010, Mark Harrah | ||
* This software is released under the terms written in LICENSE. | ||
*/ | ||
|
||
package xsbti.compile.analysis; | ||
|
||
import xsbti.compile.MiniSetup; | ||
|
||
import java.io.File; | ||
|
||
|
||
/** | ||
* Defines a generic interface to map the values of the analysis file 1-to-1. | ||
*/ | ||
public interface GenericMapper { | ||
/** | ||
* @param sourceFile A source file to be compiled. | ||
* @return A modified source file. | ||
*/ | ||
File mapSourceFile(File sourceFile); | ||
|
||
/** | ||
* @param binaryFile A binary dependency of the sources to be compiled. | ||
* @return A modified binary file. | ||
*/ | ||
File mapBinaryFile(File binaryFile); | ||
|
||
/** | ||
* @param productFile A product file (class file) produced by the compiler. | ||
* @return A modified product file. | ||
*/ | ||
File mapProductFile(File productFile); | ||
|
||
/** | ||
* @param outputDir The output dir where the compiler will output the products. | ||
* @return A modified output dir. | ||
*/ | ||
File mapOutputDir(File outputDir); | ||
|
||
/** | ||
* @param sourceDir The source dir where the compiler will look for the sources. | ||
* @return A modified source dir. | ||
*/ | ||
File mapSourceDir(File sourceDir); | ||
|
||
/** | ||
* @param classpathEntry The classpath entry to be passed to the compiler. | ||
* @return A modified classpath entry. | ||
*/ | ||
File mapClasspathEntry(File classpathEntry); | ||
|
||
/** | ||
* @param javacOption An option to be passed to the Java compiler. | ||
* @return A compiler option. | ||
*/ | ||
String mapJavacOption(String javacOption); | ||
|
||
/** | ||
* @param scalacOption An options to be passed to the Scala compiler. | ||
* @return A compiler option. | ||
*/ | ||
String mapScalacOption(String scalacOption); | ||
|
||
/** | ||
* @param file The owner of the stamp. | ||
* @param binaryStamp A stamp associated to a binary file. | ||
* @return A transformed stamp. | ||
*/ | ||
Stamp mapBinaryStamp(File file, Stamp binaryStamp); | ||
|
||
/** | ||
* @param file The owner of the stamp. | ||
* @param sourceStamp A stamp associated to a source file. | ||
* @return A transformed stamp. | ||
*/ | ||
Stamp mapSourceStamp(File file, Stamp sourceStamp); | ||
|
||
/** | ||
* @param file The owner of the stamp. | ||
* @param productStamp A stamp associated to a product file. | ||
* @return A transformed stamp. | ||
*/ | ||
Stamp mapProductStamp(File file, Stamp productStamp); | ||
|
||
/** | ||
* @param miniSetup The simple compile setup that is serialized in the analysis file. | ||
* @return A transformed mini setup. | ||
*/ | ||
MiniSetup mapMiniSetup(MiniSetup miniSetup); | ||
} |
149 changes: 149 additions & 0 deletions
149
internal/zinc-persist/src/main/java/xsbti/compile/analysis/ReadMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* Zinc - The incremental compiler for Scala. | ||
* Copyright 2011 - 2017, Lightbend, Inc. | ||
* Copyright 2008 - 2010, Mark Harrah | ||
* This software is released under the terms written in LICENSE. | ||
*/ | ||
|
||
package xsbti.compile.analysis; | ||
|
||
import sbt.internal.inc.mappers.NaiveRelativeReadMapper; | ||
import sbt.internal.inc.mappers.RelativeReadMapper; | ||
import xsbti.compile.MiniSetup; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* Defines a reader-only mapper interface that is used by Zinc after reading | ||
* the analysis from an instance of an {@link xsbti.compile.AnalysisStore}. | ||
* | ||
* This interface is useful to make the analysis file machine-independent and | ||
* allow third parties to distribute them around. | ||
*/ | ||
public interface ReadMapper extends GenericMapper { | ||
|
||
/** | ||
* Defines a mapper that reads from a machine-independent analysis file. | ||
* | ||
* An analysis file is machine independent if all the paths are relative to a path | ||
* and no information about the machine that produced it is stored -- only | ||
* information about the structure of the project from a given build tool is persisted. | ||
* | ||
* The mapper makes sure that the analysis file looks like if it was generated by | ||
* the local machine it's executed on. | ||
* | ||
* <b>Important note</b>: The assumption that all paths can be made relative to a concrete | ||
* position is not always correct. There is no guarantee that the paths of the caches, the | ||
* artifacts, the classpath entries, the compilation inputs and outputs, et cetera share | ||
* the same prefix. If this is not the case this reader will fail at runtime. | ||
* | ||
* Such assumption is broken in our test infrastructure: `lib_managed` does not share | ||
* the same prefix, and without redefining it, it fails. Note that this is a conscious | ||
* design decision of the relative read and write mappers. They are focused on simplicity. | ||
* Build tools that need more careful handling of paths should create their own read and | ||
* write mappers. | ||
* | ||
* | ||
* @param projectRootPath The path on which we want to "mount" all the relative paths in analysis. | ||
* @return A read mapper to pass in to {@link sbt.internal.inc.FileAnalysisStore}. | ||
*/ | ||
static ReadMapper getMachineIndependentMapper(Path projectRootPath) { | ||
return new NaiveRelativeReadMapper(projectRootPath); | ||
} | ||
|
||
/** | ||
* Defines a mapper that reads from a machine-independent analysis file. | ||
* | ||
* An analysis file is machine independent if all the paths are relative to a path | ||
* and no information about the machine that produced it is stored -- only | ||
* information about the structure of the project from a given build tool is persisted. | ||
* | ||
* The mapper makes sure that the analysis file looks like if it was generated by | ||
* the local machine it's executed on. | ||
* | ||
* This mapper will use the paths provided by {@link RootPaths} to make the file relative, | ||
* allowing build tools to pass independent common root paths for different kind of files. | ||
* | ||
* In case users of this machine-independent mapper need further customisation, they | ||
* can use the decorator pattern or roll their own. | ||
* | ||
* @param rootPaths The root paths to use internally by the mapper. | ||
* @return A machine-independent read mapper to pass in to {@link sbt.internal.inc.FileAnalysisStore}. | ||
*/ | ||
static ReadMapper getMachineIndependentMapper(RootPaths rootPaths) { | ||
return new RelativeReadMapper(rootPaths); | ||
} | ||
|
||
/** | ||
* Defines an no-op read mapper. | ||
* | ||
* This is useful when users are not interested in distributing the analysis files | ||
* and need to pass a read mapper to {@link sbt.internal.inc.FileAnalysisStore}. | ||
* | ||
* @return A no-op read mapper. | ||
*/ | ||
static ReadMapper getEmptyMapper() { | ||
return new ReadMapper() { | ||
@Override | ||
public File mapSourceFile(File sourceFile) { | ||
return sourceFile; | ||
} | ||
|
||
@Override | ||
public File mapBinaryFile(File binaryFile) { | ||
return binaryFile; | ||
} | ||
|
||
@Override | ||
public File mapProductFile(File productFile) { | ||
return productFile; | ||
} | ||
|
||
@Override | ||
public File mapOutputDir(File outputDir) { | ||
return outputDir; | ||
} | ||
|
||
@Override | ||
public File mapSourceDir(File sourceDir) { | ||
return sourceDir; | ||
} | ||
|
||
@Override | ||
public File mapClasspathEntry(File classpathEntry) { | ||
return classpathEntry; | ||
} | ||
|
||
@Override | ||
public String mapJavacOption(String javacOption) { | ||
return javacOption; | ||
} | ||
|
||
@Override | ||
public String mapScalacOption(String scalacOption) { | ||
return scalacOption; | ||
} | ||
|
||
@Override | ||
public Stamp mapBinaryStamp(File file, Stamp binaryStamp) { | ||
return binaryStamp; | ||
} | ||
|
||
@Override | ||
public Stamp mapSourceStamp(File file, Stamp sourceStamp) { | ||
return sourceStamp; | ||
} | ||
|
||
@Override | ||
public Stamp mapProductStamp(File file, Stamp productStamp) { | ||
return productStamp; | ||
} | ||
|
||
@Override | ||
public MiniSetup mapMiniSetup(MiniSetup miniSetup) { | ||
return miniSetup; | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.