Skip to content

Commit 297eeb3

Browse files
committed
Merge pull request scala#4499 from lrytz/removeAsm
Move ASM out of the repository [ci: last-only]
2 parents 4b0e3bc + 6fc2a68 commit 297eeb3

File tree

95 files changed

+92
-31833
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+92
-31833
lines changed

build-ant-macros.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191

9292
<macrodef name="simple-javac">
9393
<attribute name="project"/>
94-
<!-- project: asm/forkjoin -->
94+
<!-- project: forkjoin -->
9595
<attribute name="args" default=""/>
9696
<attribute name="jar" default="yes"/>
9797
<sequential>
@@ -371,6 +371,10 @@
371371
<then>
372372
<mkdir dir="${build-pack.dir}/${@{project}.targetdir}"/>
373373
<pre/>
374+
<!-- can't check if a fileset is defined, so we have an additional property -->
375+
<if><not><isset property="pack.@{project}.include-jars.defined"/></not><then>
376+
<fileset id="pack.@{project}.include-jars" dir="." excludes="**" />
377+
</then></if>
374378
<if>
375379
<not>
376380
<equals arg1="@{manifest}" arg2=""/>
@@ -380,6 +384,7 @@
380384
<!-- update="true" makes no difference on my machine, so starting from scratch-->
381385
<jar-opts/>
382386
<path refid="pack.@{project}.files"/>
387+
<zipgroupfileset refid="pack.@{project}.include-jars"/>
383388
</jar>
384389
</then>
385390
<else>

build.sbt

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ val partestDep = withoutScalaLang("org.scala-lang.modules" %% "scala-partest" %
6161
val partestInterfaceDep = withoutScalaLang("org.scala-lang.modules" %% "scala-partest-interface" % "0.5.0")
6262
val junitDep = "junit" % "junit" % "4.11"
6363
val junitIntefaceDep = "com.novocode" % "junit-interface" % "0.11" % "test"
64+
val asmDep = "org.scala-lang.modules" % "scala-asm" % versionProps("scala-asm.version")
6465
val jlineDep = "jline" % "jline" % versionProps("jline.version")
6566
val antDep = "org.apache.ant" % "ant" % "1.9.4"
6667
val scalacheckDep = withoutScalaLang("org.scalacheck" %% "scalacheck" % "1.11.4")
@@ -169,17 +170,22 @@ lazy val compiler = configureAsSubproject(project)
169170
.settings(generatePropertiesFileSettings: _*)
170171
.settings(
171172
name := "scala-compiler",
172-
libraryDependencies += antDep,
173+
libraryDependencies ++= Seq(antDep, asmDep),
173174
// this a way to make sure that classes from interactive and scaladoc projects
174175
// end up in compiler jar (that's what Ant build does)
175176
// we need to use LocalProject references (with strings) to deal with mutual recursion
176177
mappings in Compile in packageBin :=
177178
(mappings in Compile in packageBin).value ++
179+
dependencyClasses(
180+
(externalDependencyClasspath in Compile).value,
181+
modules = Set(asmDep),
182+
keep = "*.class" || "scala-asm.properties",
183+
streams.value.cacheDirectory) ++
178184
(mappings in Compile in packageBin in LocalProject("interactive")).value ++
179185
(mappings in Compile in packageBin in LocalProject("scaladoc")).value ++
180186
(mappings in Compile in packageBin in LocalProject("repl")).value,
181187
includeFilter in unmanagedResources in Compile := compilerIncludes)
182-
.dependsOn(library, reflect, asm)
188+
.dependsOn(library, reflect)
183189

184190
lazy val interactive = configureAsSubproject(project)
185191
.settings(disableDocsAndPublishingTasks: _*)
@@ -209,8 +215,6 @@ lazy val actors = configureAsSubproject(project)
209215

210216
lazy val forkjoin = configureAsForkOfJavaProject(project)
211217

212-
lazy val asm = configureAsForkOfJavaProject(project)
213-
214218
lazy val partestExtras = configureAsSubproject(Project("partest-extras", file(".") / "src" / "partest-extras"))
215219
.dependsOn(repl)
216220
.settings(clearSourceAndResourceDirectories: _*)
@@ -231,9 +235,9 @@ lazy val junit = project.in(file("test") / "junit")
231235
)
232236

233237
lazy val partestJavaAgent = (project in file(".") / "src" / "partest-javaagent").
234-
dependsOn(asm).
235238
settings(commonSettings: _*).
236239
settings(
240+
libraryDependencies += asmDep,
237241
doc := file("!!! NO DOCS !!!"),
238242
publishLocal := {},
239243
publish := {},
@@ -249,13 +253,13 @@ lazy val partestJavaAgent = (project in file(".") / "src" / "partest-javaagent")
249253
)
250254

251255
lazy val test = project.
252-
dependsOn(compiler, interactive, actors, repl, scalap, partestExtras, partestJavaAgent, asm, scaladoc).
256+
dependsOn(compiler, interactive, actors, repl, scalap, partestExtras, partestJavaAgent, scaladoc).
253257
configs(IntegrationTest).
254258
settings(disableDocsAndPublishingTasks: _*).
255259
settings(commonSettings: _*).
256260
settings(Defaults.itSettings: _*).
257261
settings(
258-
libraryDependencies ++= Seq(partestDep, scalaXmlDep, partestInterfaceDep, scalacheckDep),
262+
libraryDependencies ++= Seq(asmDep, partestDep, scalaXmlDep, partestInterfaceDep, scalacheckDep),
259263
unmanagedBase in Test := baseDirectory.value / "files" / "lib",
260264
unmanagedJars in Test <+= (unmanagedBase) (j => Attributed.blank(j)) map(identity),
261265
// no main sources
@@ -279,7 +283,7 @@ lazy val test = project.
279283
)
280284

281285
lazy val root = (project in file(".")).
282-
aggregate(library, forkjoin, reflect, compiler, asm, interactive, repl,
286+
aggregate(library, forkjoin, reflect, compiler, interactive, repl,
283287
scaladoc, scalap, actors, partestExtras, junit).settings(
284288
sources in Compile := Seq.empty,
285289
onLoadMessage := """|*** Welcome to the sbt build definition for Scala! ***
@@ -310,7 +314,7 @@ def configureAsSubproject(project: Project): Project = {
310314

311315
/**
312316
* Configuration for subprojects that are forks of some Java projects
313-
* we depend on. At the moment there are just two: asm and forkjoin.
317+
* we depend on. At the moment there's just forkjoin.
314318
*
315319
* We do not publish artifacts for those projects but we package their
316320
* binaries in a jar of other project (compiler or library).
@@ -382,6 +386,50 @@ lazy val generateVersionPropertiesFileImpl: Def.Initialize[Task[File]] = Def.tas
382386
propFile
383387
}
384388

389+
/**
390+
* Extract selected dependencies to the `cacheDirectory` and return a mapping for the content.
391+
* Heavily inspired by sbt-assembly (https://github.com/sbt/sbt-assembly/blob/0.13.0/src/main/scala/sbtassembly/Assembly.scala#L157)
392+
*/
393+
def dependencyClasses(dependencies: Classpath, modules: Set[ModuleID], keep: FileFilter, cacheDirectory: File): Seq[(File, String)] = {
394+
val dependencyFiles: Seq[File] = dependencies.map(_.data).toSeq
395+
val toInclude = dependencyFiles.filter(f => {
396+
val p = f.getCanonicalPath
397+
modules.exists(m => {
398+
// works for both .m2 (org/scala-lang/modules/scala-asm/5.0.3-scala-3/scala-asm-5.0.3-scala-3.jar)
399+
// and .ivy2 (org.scala-lang.modules/scala-asm/5.0.3-scala-3/bundles/scala-asm.jar)
400+
val nameParts = m.organization.split('.').toSet + m.name + m.revision
401+
nameParts.forall(p.contains)
402+
})
403+
})
404+
assert(toInclude.forall(sbt.classpath.ClasspathUtilities.isArchive), s"Expected JAR files as dependencies: $toInclude")
405+
406+
val tempDir = cacheDirectory / "unpackedDependencies"
407+
408+
def sha1name(f: File): String = bytesToSha1String(f.getCanonicalPath.getBytes("UTF-8"))
409+
def sha1content(f: File): String = bytesToSha1String(IO.readBytes(f))
410+
def bytesToSha1String(bytes: Array[Byte]): String = {
411+
val sha1 = java.security.MessageDigest.getInstance("SHA-1")
412+
val hash = sha1.digest(bytes)
413+
hash map {"%02x".format(_)} mkString
414+
}
415+
416+
val jarDirs: Seq[File] = for (jar <- toInclude) yield {
417+
val jarName = jar.getName
418+
val hash = sha1name(jar) + "_" + sha1content(jar)
419+
val jarNamePath = tempDir / (hash + ".jarName")
420+
val dest = tempDir / hash
421+
if (!jarNamePath.exists || IO.read(jarNamePath) != jar.getCanonicalPath) {
422+
IO.delete(dest)
423+
dest.mkdir()
424+
IO.unzip(jar, dest)
425+
IO.write(jarNamePath, jar.getCanonicalPath, IO.utf8, append = false)
426+
}
427+
dest
428+
}
429+
430+
jarDirs.flatMap(dir => dir ** keep --- dir pair relativeTo(dir))
431+
}
432+
385433
// Defining these settings is somewhat redundant as we also redefine settings that depend on them.
386434
// However, IntelliJ's project import works better when these are set correctly.
387435
def clearSourceAndResourceDirectories = Seq(Compile, Test).flatMap(config => inConfig(config)(Seq(

build.xml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ TODO:
165165
<property name="build.dir" value="${basedir}/build"/>
166166
<property name="build-deps.dir" value="${build.dir}/deps"/>
167167
<property name="build-libs.dir" value="${build.dir}/libs"/>
168-
<property name="build-asm.dir" value="${build-libs.dir}"/>
169168
<property name="build-forkjoin.dir" value="${build-libs.dir}"/>
170169
<property name="build-locker.dir" value="${build.dir}/locker"/>
171170
<property name="build-quick.dir" value="${build.dir}/quick"/>
@@ -353,6 +352,11 @@ TODO:
353352
<prepareCross name="partest"/>
354353
<prepareCross name="scalacheck"/>
355354

355+
<artifact:dependencies pathId="asm.classpath" filesetId="asm.fileset">
356+
<dependency groupId="org.scala-lang.modules" artifactId="scala-asm" version="${scala-asm.version}"/>
357+
</artifact:dependencies>
358+
<copy-deps project="asm"/>
359+
356360
<!-- TODO: delay until absolutely necessary to allow minimal build, also move out partest dependency from scaladoc -->
357361
<artifact:dependencies pathId="partest.classpath" filesetId="partest.fileset" versionsId="partest.versions">
358362
<!-- uncomment the following if you're deploying your own partest locally -->
@@ -624,9 +628,7 @@ TODO:
624628
</then></if>
625629

626630
<path id="forkjoin.classpath" path="${build-forkjoin.dir}/classes/forkjoin"/>
627-
<path id="asm.classpath" path="${build-asm.dir}/classes/asm"/>
628631
<property name="forkjoin-classes" refid="forkjoin.classpath"/>
629-
<property name="asm-classes" refid="asm.classpath"/>
630632

631633
<!-- the following properties fully define staged-docs, staged-pack, make-bundle, copy-bundle and mvn-package for each of the projects -->
632634
<property name="library.description" value="Scala Standard Library"/>
@@ -693,7 +695,7 @@ TODO:
693695
<property name="partest-extras.description" value="Scala Compiler Testing Tool (compiler-specific extras)"/>
694696
<property name="partest-javaagent.description" value="Scala Compiler Testing Tool (compiler-specific java agent)"/>
695697

696-
<!-- projects without project-specific options: asm, forkjoin, manual, bin, repl -->
698+
<!-- projects without project-specific options: forkjoin, manual, bin, repl -->
697699
<for list="actors,compiler,interactive,scaladoc,library,parser-combinators,partest,partest-extras,partest-javaagent,reflect,scalap,swing,xml,continuations-plugin,continuations-library" param="project">
698700
<sequential>
699701
<!-- description is mandatory -->
@@ -878,8 +880,9 @@ TODO:
878880
<fileset dir="${build-quick.dir}/classes/scaladoc"/>
879881
<fileset dir="${build-quick.dir}/classes/interactive"/>
880882
<fileset dir="${build-quick.dir}/classes/repl"/>
881-
<fileset dir="${asm-classes}"/>
882883
</path>
884+
<fileset id="pack.compiler.include-jars" refid="asm.fileset"/>
885+
<property name="pack.compiler.include-jars.defined" value="yeah"/>
883886

884887
<!-- TODO modularize compiler.
885888
<path id="pack.scaladoc.files"> <fileset dir="${build-quick.dir}/classes/scaladoc"/> </path>
@@ -1078,9 +1081,9 @@ TODO:
10781081
<!-- ===========================================================================
10791082
CLEANLINESS
10801083
=============================================================================-->
1081-
<target name="libs.clean"> <clean build="libs"/> <clean build="asm"/> </target>
1082-
<target name="quick.clean" depends="libs.clean"> <clean build="quick"/> <clean build="pack"/> <clean build="strap"/> </target>
1083-
<target name="locker.clean" depends="quick.clean"> <clean build="locker"/> </target>
1084+
<target name="libs.clean"> <clean build="libs"/> </target>
1085+
<target name="quick.clean" depends="libs.clean"> <clean build="quick"/> <clean build="pack"/> <clean build="strap"/> </target>
1086+
<target name="locker.clean" depends="quick.clean"> <clean build="locker"/> </target>
10841087

10851088
<target name="docs.clean"> <clean build="docs"/> <delete dir="${build.dir}/manmaker" includeemptydirs="yes" quiet="yes" failonerror="no"/> </target>
10861089
<target name="dist.clean"> <delete dir="${dists.dir}" includeemptydirs="yes" quiet="yes" failonerror="no"/> </target>
@@ -1098,7 +1101,6 @@ TODO:
10981101
LOCAL DEPENDENCIES
10991102
============================================================================ -->
11001103

1101-
<target name="asm.done" depends="init"> <simple-javac project="asm" jar="no"/> </target>
11021104
<target name="forkjoin.done" depends="init"> <simple-javac project="forkjoin" args="-XDignore.symbol.file" jar="no"/></target>
11031105

11041106
<!-- For local development only. We only allow released versions of Scala for STARR.
@@ -1121,7 +1123,7 @@ TODO:
11211123
<!-- ===========================================================================
11221124
LOCAL REFERENCE BUILD (LOCKER)
11231125
============================================================================ -->
1124-
<target name="locker.start" depends="asm.done, forkjoin.done">
1126+
<target name="locker.start" depends="forkjoin.done">
11251127
<condition property="locker.locked"><available file="${build-locker.dir}/locker.locked"/></condition></target>
11261128

11271129
<target name="locker.lib" depends="locker.start" unless="locker.locked">
@@ -1189,7 +1191,7 @@ TODO:
11891191
<target name="pack.reflect" depends="quick.reflect"> <staged-pack project="reflect"/> </target>
11901192

11911193
<!-- TODO modularize compiler. Remove other quick targets when they become modules. -->
1192-
<target name="pack.comp" depends="quick.comp, quick.scaladoc, quick.interactive, quick.repl, asm.done">
1194+
<target name="pack.comp" depends="quick.comp, quick.scaladoc, quick.interactive, quick.repl">
11931195
<staged-pack project="compiler" manifest="${build-pack.dir}/META-INF/MANIFEST.MF">
11941196
<pre> <!-- TODO the files copied here do not influence actuality of this target (nor does the manifest) -->
11951197
<copy todir="${build-pack.dir}/lib">

src/asm/README

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)