Skip to content

Commit

Permalink
reproduce scala#13994 in cmdTest
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Dec 7, 2021
1 parent a433f47 commit 2eea369
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 6 deletions.
8 changes: 3 additions & 5 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,6 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint

def process()(using Context) = {

def parseSource()(using Context) =
if (unit.isJava) new JavaParser(unit.source).parse()
else new Parser(unit.source).parse()

def enterTrees()(using Context) =
ctx.typer.lateEnter(unit.untpdTree)
def typeCheckUnit()(using Context) =
Expand All @@ -321,7 +317,9 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
if compiling then finalizeActions += (() => typeCheckUnit()(using typerCtx))
else typeCheckUnit()(using typerCtx)

unit.untpdTree = parseSource()
unit.untpdTree =
if (unit.isJava) new JavaParser(unit.source).parse()
else new Parser(unit.source).parse()
val namerCtx =
// inline body annotations are set in namer, capturing the current context
// we need to prepare the context for inlining.
Expand Down
8 changes: 8 additions & 0 deletions project/scripts/bootstrapCmdTests
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ clear_out "$OUT"
./bin/scalac -d "$OUT/out.jar" tests/pos/i12973.scala
echo "Bug12973().check" | TERM=dumb ./bin/scala -cp "$OUT/out.jar" > "$tmp" 2>&1
grep -qe "Bug12973 is fixed" "$tmp"

echo "testing -sourcepath with inlining"
cwd=$(pwd)
java_prop="pack.version.file=$cwd/dist/target/pack/VERSION"
(cd "$cwd/tests/cmdTest-sbt-tests/sourcepath-with-inline" && "$SBT" "-D$java_prop" ";clean;prepareSources;compile;copyChanges;compile")
rm -rf "$cwd/tests/cmdTest-sbt-tests/sourcepath-with-inline/target"
rm -rf "$cwd/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/target"
rm -f "$cwd/tests/cmdTest-sbt-tests/sourcepath-with-inline/src/main/scala/a/zz.scala"
4 changes: 3 additions & 1 deletion project/scripts/cmdTestsCommon.inc.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
set -eux

SBT="./project/scripts/sbt" # if run on CI
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/../.."

SBT="$ROOT/project/scripts/sbt" # if run on CI
# SBT="sbt" # if run locally

SOURCE="tests/pos/HelloWorld.scala"
Expand Down
7 changes: 7 additions & 0 deletions tests/cmdTest-sbt-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Readme

Do not use this directory for testing sbt projects in general, add a test case to `dotty/sbt-test`

This directory is for sbt tests that can not be reproduced with sbt scripted tests.

Adding a test here will reduce the performance of running all tests.
17 changes: 17 additions & 0 deletions tests/cmdTest-sbt-tests/sourcepath-with-inline/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.Properties

val prepareSources = taskKey[Unit]("Copy changes to the src directory")
val copyChanges = taskKey[Unit]("Copy changes to the src directory")

val srcDir = settingKey[File]("The directory to copy changes to")
val changesDir = settingKey[File]("The directory to copy changes from")

srcDir := (ThisBuild / baseDirectory).value / "src" / "main" / "scala"
changesDir := (ThisBuild / baseDirectory).value / "changes"

prepareSources := IO.copyFile(changesDir.value / "zz.original.scala", srcDir.value / "a" / "zz.scala")
copyChanges := IO.copyFile(changesDir.value / "zz.new.scala", srcDir.value / "a" / "zz.scala")

(Compile / scalacOptions) ++= Seq(
"-sourcepath", (Compile / sourceDirectories).value.map(_.getAbsolutePath).distinct.mkString(java.io.File.pathSeparator),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package a

object Foo: // note that `Foo` is defined in `zz.scala`
class Local
inline def foo(using Local): Nothing =
???
???
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package a

object Foo: // note that `Foo` is defined in `zz.scala`
class Local
inline def foo(using Local): Nothing =
???
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sbt._
import Keys._

import java.util.Properties
import java.io.File

object DottyInjectedPlugin extends AutoPlugin {
override def requires = plugins.JvmPlugin
override def trigger = allRequirements

private val packProperties = settingKey[Properties]("The properties of the dist/pack command")

override val projectSettings = Seq(
packProperties := {
val prop = new Properties()
IO
.read(new File(sys.props("pack.version.file")))
.linesIterator
.foreach { line =>
val Array(key, value) = line.split(":=")
prop.setProperty(key, value)
}
prop
},
scalaVersion := packProperties.value.getProperty("version")
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.5.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package a

object Bar:
given Foo.Local()
def Bar = Foo.foo

0 comments on commit 2eea369

Please sign in to comment.