Skip to content

Commit c223195

Browse files
Handle platform from using directives
1 parent 12f1a52 commit c223195

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

modules/build/src/main/scala/scala/build/preprocessing/ScalaPreprocessor.scala

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ import java.util.Locale
88

99
import scala.build.{Inputs, Os, Sources}
1010
import scala.build.internal.AmmUtil
11-
import scala.build.options.{BuildOptions, BuildRequirements, ClassPathOptions, ScalaOptions}
11+
import scala.build.options.{
12+
BuildOptions,
13+
BuildRequirements,
14+
ClassPathOptions,
15+
ScalaJsOptions,
16+
ScalaNativeOptions,
17+
ScalaOptions
18+
}
1219
import scala.collection.JavaConverters._
1320

1421
case object ScalaPreprocessor extends Preprocessor {
@@ -105,8 +112,27 @@ case object ScalaPreprocessor extends Preprocessor {
105112
scalaVersion = Some(scalaVer)
106113
)
107114
)
108-
case _ =>
109-
sys.error(s"Unrecognized using directive: ${dir.values.mkString(" ")}")
115+
case other =>
116+
val maybeOptions =
117+
// TODO Accept several platforms for cross-compilation
118+
if (other.lengthCompare(1) == 0)
119+
isPlatform(normalizePlatform(other.head)).map {
120+
case BuildRequirements.Platform.JVM =>
121+
BuildOptions()
122+
case BuildRequirements.Platform.JS =>
123+
BuildOptions(
124+
scalaJsOptions = ScalaJsOptions(enable = true)
125+
)
126+
case BuildRequirements.Platform.Native =>
127+
BuildOptions(
128+
scalaNativeOptions = ScalaNativeOptions(enable = true)
129+
)
130+
}
131+
else
132+
None
133+
maybeOptions.getOrElse {
134+
sys.error(s"Unrecognized using directive: ${other.mkString(" ")}")
135+
}
110136
}
111137
}
112138
.foldLeft(BuildOptions())(_ orElse _)

0 commit comments

Comments
 (0)