-
Notifications
You must be signed in to change notification settings - Fork 28.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPARK-1094 Support MiMa for reporting binary compatibility accross versions. #207
Closed
Closed
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
651844c
Support MiMa for reporting binary compatibility accross versions.
ScrapCodes b551519
adding a new exclude after rebasing with master
ScrapCodes 4c771e0
Added a tool to generate mima excludes and also adapted build to pick…
ScrapCodes c39f3b5
Some enhancements to binary checking.
pwendell 647c547
Reveiw feedback.
pwendell 0e0f570
Small fix and removing directory listings
pwendell 3666cf1
Minor style change
pwendell 6c2030d
Merge remote-tracking branch 'apache/master' into mima
pwendell 22ae267
New binary changes after upmerge
pwendell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
sbt/*.jar | ||
.settings | ||
.cache | ||
.mima-excludes | ||
/build/ | ||
work/ | ||
out/ | ||
|
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
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,62 @@ | ||
import com.typesafe.tools.mima.plugin.MimaKeys.{binaryIssueFilters, previousArtifact} | ||
import com.typesafe.tools.mima.plugin.MimaPlugin.mimaDefaultSettings | ||
import sbt._ | ||
|
||
object MimaBuild { | ||
|
||
def ignoredABIProblems(base: File) = { | ||
import com.typesafe.tools.mima.core._ | ||
import com.typesafe.tools.mima.core.ProblemFilters._ | ||
|
||
// Excludes placed here will be used for all Spark versions | ||
val defaultExcludes = Seq() | ||
|
||
// Read package-private excludes from file | ||
val excludeFilePath = (base.getAbsolutePath + "/.mima-excludes") | ||
val excludeFile = file(excludeFilePath) | ||
val packagePrivateList: Seq[String] = | ||
if (!excludeFile.exists()) { | ||
Seq() | ||
} else { | ||
IO.read(excludeFile).split("\n") | ||
} | ||
|
||
def excludeClass(className: String) = { | ||
Seq( | ||
excludePackage(className), | ||
ProblemFilters.exclude[MissingClassProblem](className), | ||
ProblemFilters.exclude[MissingTypesProblem](className), | ||
excludePackage(className + "$"), | ||
ProblemFilters.exclude[MissingClassProblem](className + "$"), | ||
ProblemFilters.exclude[MissingTypesProblem](className + "$") | ||
) | ||
} | ||
def excludeSparkClass(className: String) = excludeClass("org.apache.spark." + className) | ||
|
||
val packagePrivateExcludes = packagePrivateList.flatMap(excludeClass) | ||
|
||
/* Excludes specific to a given version of Spark. When comparing the given version against | ||
its immediate predecessor, the excludes listed here will be applied. */ | ||
val versionExcludes = | ||
SparkBuild.SPARK_VERSION match { | ||
case v if v.startsWith("1.0") => | ||
Seq(excludePackage("org.apache.spark.api.java")) ++ | ||
excludeSparkClass("rdd.ClassTags") ++ | ||
excludeSparkClass("util.XORShiftRandom") ++ | ||
excludeSparkClass("mllib.recommendation.MFDataGenerator") ++ | ||
excludeSparkClass("mllib.optimization.SquaredGradient") ++ | ||
excludeSparkClass("mllib.regression.RidgeRegressionWithSGD") ++ | ||
excludeSparkClass("mllib.regression.LassoWithSGD") ++ | ||
excludeSparkClass("mllib.regression.LinearRegressionWithSGD") | ||
case _ => Seq() | ||
} | ||
|
||
defaultExcludes ++ packagePrivateExcludes ++ versionExcludes | ||
} | ||
|
||
def mimaSettings(sparkHome: File) = mimaDefaultSettings ++ Seq( | ||
previousArtifact := None, | ||
binaryIssueFilters ++= ignoredABIProblems(sparkHome) | ||
) | ||
|
||
} |
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
131 changes: 131 additions & 0 deletions
131
tools/src/main/scala/org/apache/spark/tools/GenerateMIMAIgnore.scala
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,131 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.tools | ||
|
||
import java.io.File | ||
import java.util.jar.JarFile | ||
|
||
import scala.collection.mutable | ||
import scala.collection.JavaConversions._ | ||
import scala.reflect.runtime.universe.runtimeMirror | ||
|
||
/** | ||
* A tool for generating classes to be excluded during binary checking with MIMA. It is expected | ||
* that this tool is run with ./spark-class. | ||
* | ||
* MIMA itself only supports JVM-level visibility and doesn't account for package-private classes. | ||
* This tool looks at all currently package-private classes and generates exclusions for them. Note | ||
* that this approach is not sound. It can lead to false positives if we move or rename a previously | ||
* package-private class. It can lead to false negatives if someone explicitly makes a class | ||
* package-private that wasn't before. This exists only to help catch certain classes of changes | ||
* which might be difficult to catch during review. | ||
*/ | ||
object GenerateMIMAIgnore { | ||
private val classLoader = Thread.currentThread().getContextClassLoader | ||
private val mirror = runtimeMirror(classLoader) | ||
|
||
private def classesPrivateWithin(packageName: String): Set[String] = { | ||
|
||
val classes = getClasses(packageName, classLoader) | ||
val privateClasses = mutable.HashSet[String]() | ||
|
||
def isPackagePrivate(className: String) = { | ||
try { | ||
/* Couldn't figure out if it's possible to determine a-priori whether a given symbol | ||
is a module or class. */ | ||
|
||
val privateAsClass = mirror | ||
.staticClass(className) | ||
.privateWithin | ||
.fullName | ||
.startsWith(packageName) | ||
|
||
val privateAsModule = mirror | ||
.staticModule(className) | ||
.privateWithin | ||
.fullName | ||
.startsWith(packageName) | ||
|
||
privateAsClass || privateAsModule | ||
} catch { | ||
case _: Throwable => { | ||
println("Error determining visibility: " + className) | ||
false | ||
} | ||
} | ||
} | ||
|
||
for (className <- classes) { | ||
val directlyPrivateSpark = isPackagePrivate(className) | ||
|
||
/* Inner classes defined within a private[spark] class or object are effectively | ||
invisible, so we account for them as package private. */ | ||
val indirectlyPrivateSpark = { | ||
val maybeOuter = className.toString.takeWhile(_ != '$') | ||
if (maybeOuter != className) { | ||
isPackagePrivate(maybeOuter) | ||
} else { | ||
false | ||
} | ||
} | ||
if (directlyPrivateSpark || indirectlyPrivateSpark) privateClasses += className | ||
} | ||
privateClasses.flatMap(c => Seq(c, c.replace("$", "#"))).toSet | ||
} | ||
|
||
def main(args: Array[String]) { | ||
scala.tools.nsc.io.File(".mima-excludes"). | ||
writeAll(classesPrivateWithin("org.apache.spark").mkString("\n")) | ||
println("Created : .mima-excludes in current directory.") | ||
} | ||
|
||
|
||
private def shouldExclude(name: String) = { | ||
// Heuristic to remove JVM classes that do not correspond to user-facing classes in Scala | ||
name.contains("anon") || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I keep trying to come up with a valid class name that contains "anon". In the dictionary, there seems to be Canon, Lebanon, and, of course, anonymous. We're probably safe? |
||
name.endsWith("$class") || | ||
name.contains("$sp") | ||
} | ||
|
||
/** | ||
* Scans all classes accessible from the context class loader which belong to the given package | ||
* and subpackages both from directories and jars present on the classpath. | ||
*/ | ||
private def getClasses(packageName: String, | ||
classLoader: ClassLoader = Thread.currentThread().getContextClassLoader): Set[String] = { | ||
val path = packageName.replace('.', '/') | ||
val resources = classLoader.getResources(path) | ||
|
||
val jars = resources.filter(x => x.getProtocol == "jar") | ||
.map(_.getFile.split(":")(1).split("!")(0)).toSeq | ||
val classesFromJars = jars.map(getClassesFromJar(_, path)).flatten | ||
|
||
classesFromJars.map(_.getName).filterNot(shouldExclude).toSet | ||
} | ||
|
||
/** | ||
* Get all classes in a package from a jar file. | ||
*/ | ||
private def getClassesFromJar(jarPath: String, packageName: String) = { | ||
val jar = new JarFile(new File(jarPath)) | ||
val enums = jar.entries().map(_.getName).filter(_.startsWith(packageName)) | ||
val classes = for (entry <- enums if entry.endsWith(".class")) | ||
yield Class.forName(entry.replace('/', '.').stripSuffix(".class")) | ||
classes | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, about how long does it take to run this? I'm just wondering if it will lengthen our test time significantly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line takes about 5 seconds. I think including the subsequent check it's less than 1 minute.