@@ -2,6 +2,8 @@ package scala.build
2
2
3
3
import java .nio .charset .StandardCharsets
4
4
5
+ import scala .build .EitherCps .{either , value }
6
+ import scala .build .errors .BuildException
5
7
import scala .build .info .{BuildInfo , ScopedBuildInfo }
6
8
import scala .build .options .{BuildOptions , HasScope , Scope }
7
9
import scala .build .preprocessing .ScriptPreprocessor
@@ -50,7 +52,11 @@ final case class ScopedSources(
50
52
* @return
51
53
* [[Sources ]] instance that belong to specified scope
52
54
*/
53
- def sources (scope : Scope , baseOptions : BuildOptions ): Sources =
55
+ def sources (
56
+ scope : Scope ,
57
+ baseOptions : BuildOptions ,
58
+ workspace : os.Path
59
+ ): Either [BuildException , Sources ] = either {
54
60
val combinedOptions = combinedBuildOptions(scope, baseOptions)
55
61
56
62
val codeWrapper = ScriptPreprocessor .getScriptWrapper(combinedOptions)
@@ -62,12 +68,16 @@ final case class ScopedSources(
62
68
val needsBuildInfo = combinedOptions.sourceGeneratorOptions.useBuildInfo.getOrElse(false )
63
69
64
70
val maybeBuildInfoSource = if (needsBuildInfo && scope == Scope .Main )
65
- Seq (Sources .InMemory (
66
- Left (" build-info" ),
67
- os.rel / " BuildInfo.scala" ,
68
- buildInfo(combinedOptions).generateContents().getBytes(StandardCharsets .UTF_8 ),
69
- None
70
- ))
71
+ Seq (
72
+ Sources .InMemory (
73
+ Left (" build-info" ),
74
+ os.rel / " BuildInfo.scala" ,
75
+ value(buildInfo(combinedOptions, workspace)).generateContents().getBytes(
76
+ StandardCharsets .UTF_8
77
+ ),
78
+ None
79
+ )
80
+ )
71
81
else Nil
72
82
73
83
Sources (
@@ -77,6 +87,7 @@ final case class ScopedSources(
77
87
resourceDirs.flatMap(_.valueFor(scope).toSeq),
78
88
combinedOptions
79
89
)
90
+ }
80
91
81
92
/** Combine build options that had no requirements (console and using directives) or their
82
93
* requirements have been resolved (e.g. target using directives) with build options that require
@@ -94,24 +105,25 @@ final case class ScopedSources(
94
105
buildOptionsFor(scope)
95
106
.foldRight(baseOptions)(_ orElse _)
96
107
97
- def buildInfo (baseOptions : BuildOptions ): BuildInfo = {
98
- def getScopedBuildInfo (scope : Scope ): ScopedBuildInfo =
99
- val combinedOptions = combinedBuildOptions(scope, baseOptions)
100
- val sourcePaths = paths.flatMap(_.valueFor(scope).toSeq).map(_._1.toString)
101
- val inMemoryPaths =
102
- (inMemory.flatMap(_.valueFor(scope).toSeq).flatMap(_.originalPath.toOption) ++
103
- unwrappedScripts.flatMap(_.valueFor(scope).toSeq).flatMap(_.originalPath.toOption))
104
- .map(_._2.toString)
108
+ def buildInfo (baseOptions : BuildOptions , workspace : os.Path ): Either [BuildException , BuildInfo ] =
109
+ either {
110
+ def getScopedBuildInfo (scope : Scope ): ScopedBuildInfo =
111
+ val combinedOptions = combinedBuildOptions(scope, baseOptions)
112
+ val sourcePaths = paths.flatMap(_.valueFor(scope).toSeq).map(_._1.toString)
113
+ val inMemoryPaths =
114
+ (inMemory.flatMap(_.valueFor(scope).toSeq).flatMap(_.originalPath.toOption) ++
115
+ unwrappedScripts.flatMap(_.valueFor(scope).toSeq).flatMap(_.originalPath.toOption))
116
+ .map(_._2.toString)
105
117
106
- ScopedBuildInfo (combinedOptions, sourcePaths ++ inMemoryPaths)
118
+ ScopedBuildInfo (combinedOptions, sourcePaths ++ inMemoryPaths)
107
119
108
- val baseBuildInfo = BuildInfo (combinedBuildOptions(Scope .Main , baseOptions))
120
+ val baseBuildInfo = value( BuildInfo (combinedBuildOptions(Scope .Main , baseOptions), workspace ))
109
121
110
- val mainBuildInfo = getScopedBuildInfo(Scope .Main )
111
- val testBuildInfo = getScopedBuildInfo(Scope .Test )
122
+ val mainBuildInfo = getScopedBuildInfo(Scope .Main )
123
+ val testBuildInfo = getScopedBuildInfo(Scope .Test )
112
124
113
- baseBuildInfo
114
- .withScope(Scope .Main .name, mainBuildInfo)
115
- .withScope(Scope .Test .name, testBuildInfo)
116
- }
125
+ baseBuildInfo
126
+ .withScope(Scope .Main .name, mainBuildInfo)
127
+ .withScope(Scope .Test .name, testBuildInfo)
128
+ }
117
129
}
0 commit comments