@@ -11,16 +11,10 @@ import java.nio.charset.StandardCharsets
11
11
import java .nio .file .Path
12
12
13
13
import scala .build .errors .BuildException
14
+ import scala .build .info .{BuildInfo , ScopedBuildInfo }
14
15
import scala .build .internal .Constants
15
16
import scala .build .internal .Runner .frameworkName
16
- import scala .build .options .{
17
- BuildOptions ,
18
- JavaOptions ,
19
- Platform ,
20
- ScalaJsOptions ,
21
- ScalaNativeOptions ,
22
- Scope
23
- }
17
+ import scala .build .options .{BuildOptions , Scope }
24
18
import scala .build .testrunner .AsmTestRunner
25
19
import scala .build .{Logger , Positioned , Sources }
26
20
import scala .cli .util .SeqHelpers .*
@@ -31,136 +25,25 @@ final case class JsonProjectDescriptor(
31
25
) extends ProjectDescriptor {
32
26
private val charSet = StandardCharsets .UTF_8
33
27
34
- private def scalaVersionSettings (options : BuildOptions ): JsonProject = {
35
- val sv = options.scalaOptions.scalaVersion
36
- .flatMap(_.versionOpt)
37
- .getOrElse(Constants .defaultScalaVersion)
38
-
39
- JsonProject (scalaVersion = Some (sv))
40
- }
41
-
42
- private def scalaJsSettings (options : ScalaJsOptions ): JsonProject = {
43
-
44
- val scalaJsVersion = Some (options.version.getOrElse(Constants .scalaJsVersion))
45
-
46
- JsonProject (
47
- platform = Some (Platform .JS .repr),
48
- scalaJsVersion = scalaJsVersion,
49
- jsEsVersion = options.esVersionStr
50
- )
51
- }
52
-
53
- private def scalaNativeSettings (options : ScalaNativeOptions ): JsonProject = {
54
- val scalaNativeVersion = Some (options.version.getOrElse(Constants .scalaNativeVersion))
55
-
56
- JsonProject (
57
- platform = Some (Platform .Native .repr),
58
- scalaNativeVersion = scalaNativeVersion
59
- )
60
- }
61
-
62
- private def jvmSettings (options : JavaOptions ): JsonProject =
63
- JsonProject (
64
- platform = Some (Platform .JVM .repr),
65
- jvmVersion = options.jvmIdOpt.map(_.value)
66
- )
67
-
68
- private def platformSettings (options : BuildOptions ): JsonProject =
69
- options.scalaOptions.platform.map(_.value) match {
70
- case Some (Platform .JS ) =>
71
- scalaJsSettings(options.scalaJsOptions)
72
- case Some (Platform .Native ) =>
73
- scalaNativeSettings(options.scalaNativeOptions)
74
- case _ => jvmSettings(options.javaOptions)
75
- }
76
-
77
- private def scalacOptionsSettings (options : BuildOptions ): ScopedJsonProject =
78
- ScopedJsonProject (scalacOptions = options.scalaOptions.scalacOptions.toSeq.map(_.value.value))
79
-
80
- private def sourcesSettings (sources : Sources ): ScopedJsonProject =
81
- ScopedJsonProject (sources =
82
- ProjectDescriptor .sources(sources, charSet).map(_._1.toNIO.toString)
83
- )
84
-
85
- private def scalaCompilerPlugins (options : BuildOptions ): ScopedJsonProject =
86
- val compilerPlugins = options.scalaOptions.compilerPlugins.map(_.value)
87
- .map(ExportDependencyFormat (_, options.scalaParams.getOrElse(None )))
88
-
89
- ScopedJsonProject (scalaCompilerPlugins = compilerPlugins)
90
-
91
- private def dependencySettings (options : BuildOptions ): ScopedJsonProject = {
92
- val directDeps = options.classPathOptions.extraDependencies.toSeq.map(_.value)
93
- .map(ExportDependencyFormat (_, options.scalaParams.getOrElse(None )))
94
-
95
- ScopedJsonProject (dependencies = directDeps)
96
- }
97
-
98
- private def repositorySettings (options : BuildOptions ): ScopedJsonProject = {
99
- val resolvers = options.finalRepositories
100
- .getOrElse(Nil )
101
- .appended(Repositories .central)
102
- .appended(LocalRepositories .ivy2Local)
103
- .collect {
104
- case repo : MavenRepository => repo.root
105
- case repo : IvyRepository => s " ivy: ${repo.pattern.string}"
106
- }
107
- .distinct
108
-
109
- ScopedJsonProject (resolvers = resolvers)
110
- }
111
-
112
- private def customResourcesSettings (options : BuildOptions ): ScopedJsonProject =
113
- ScopedJsonProject (resourcesDirs = options.classPathOptions.resourcesDir.map(_.toNIO.toString))
114
-
115
- private def customJarsSettings (options : BuildOptions ): ScopedJsonProject = {
116
-
117
- val customCompileOnlyJarsDecls =
118
- options.classPathOptions.extraCompileOnlyJars.map(_.toNIO.toString)
119
-
120
- val customJarsDecls = options.classPathOptions.extraClassPath.map(_.toNIO.toString)
121
-
122
- ScopedJsonProject (
123
- customJarsDecls = customCompileOnlyJarsDecls ++ customJarsDecls
124
- )
125
- }
126
-
127
28
def `export` (
128
29
optionsMain : BuildOptions ,
129
30
optionsTest : BuildOptions ,
130
31
sourcesMain : Sources ,
131
32
sourcesTest : Sources
132
33
): JsonProject = {
133
- val baseJsonProject = Seq (
134
- JsonProject (
135
- projectName = projectName,
136
- mainClass = optionsMain.mainClass
137
- ),
138
- scalaVersionSettings(optionsMain),
139
- platformSettings(optionsMain)
140
- )
141
- .foldLeft(JsonProject ())(_ + _)
34
+ def getScopedBuildInfo (options : BuildOptions , sources : Sources ) =
35
+ val sourcePaths = sources.paths.map(_._1.toString)
36
+ val inMemoryPaths = sources.inMemory.flatMap(_.originalPath.toSeq.map(_._2.toString))
142
37
143
- val mainJsonProject = exportScope(optionsMain, sourcesMain)
144
- val testJsonProject = exportScope(optionsTest, sourcesTest)
38
+ ScopedBuildInfo (options, sourcePaths ++ inMemoryPaths)
145
39
146
- baseJsonProject
147
- .withScope(Scope .Main .name, mainJsonProject)
148
- .withScope(Scope .Test .name, testJsonProject)
149
- }
40
+ val baseBuildInfo = BuildInfo (optionsMain)
150
41
151
- def exportScope (
152
- options : BuildOptions ,
153
- sources : Sources
154
- ): ScopedJsonProject =
155
- Seq (
156
- scalaCompilerPlugins(options),
157
- scalacOptionsSettings(options),
158
- sourcesSettings(sources),
159
- dependencySettings(options),
160
- repositorySettings(options),
161
- customResourcesSettings(options),
162
- customJarsSettings(options)
163
- )
164
- .foldLeft(ScopedJsonProject ())(_ + _)
165
- .sorted
42
+ val mainBuildInfo = getScopedBuildInfo(optionsMain, sourcesMain)
43
+ val testBuildInfo = getScopedBuildInfo(optionsTest, sourcesTest)
44
+
45
+ JsonProject (baseBuildInfo
46
+ .withScope(Scope .Main .name, mainBuildInfo)
47
+ .withScope(Scope .Test .name, testBuildInfo))
48
+ }
166
49
}
0 commit comments