1
1
package scala .build .input
2
2
3
- import java .io .ByteArrayInputStream
3
+ import java .io .{ ByteArrayInputStream , File }
4
4
import java .math .BigInteger
5
5
import java .nio .charset .StandardCharsets
6
6
import java .security .MessageDigest
7
7
8
8
import scala .annotation .tailrec
9
9
import scala .build .Directories
10
- import scala .build .errors .{BuildException , InputsException }
10
+ import scala .build .errors .{BuildException , InputsException , WorkspaceError }
11
11
import scala .build .input .ElementsUtils .*
12
12
import scala .build .internal .Constants
13
13
import scala .build .internal .zip .WrappedZipInputStream
@@ -125,53 +125,14 @@ object Inputs {
125
125
private def forValidatedElems (
126
126
validElems : Seq [Element ],
127
127
baseProjectName : String ,
128
- forcedWorkspace : Option [os.Path ],
128
+ workspace : os.Path ,
129
+ needsHash : Boolean ,
130
+ workspaceOrigin : WorkspaceOrigin ,
129
131
enableMarkdown : Boolean ,
130
132
allowRestrictedFeatures : Boolean ,
131
133
extraClasspathWasPassed : Boolean
132
134
): Inputs = {
133
135
assert(extraClasspathWasPassed || validElems.nonEmpty)
134
- val (inferredWorkspace, inferredNeedsHash, workspaceOrigin) = {
135
- val settingsFiles = validElems.projectSettingsFiles
136
- val dirsAndFiles = validElems.collect {
137
- case d : Directory => d
138
- case f : SourceFile => f
139
- }
140
- settingsFiles.headOption.map { s =>
141
- if (settingsFiles.length > 1 )
142
- System .err.println(
143
- s " Warning: more than one ${Constants .projectFileName} file has been found. Setting ${s.base} as the project root directory for this run. "
144
- )
145
- (s.base, true , WorkspaceOrigin .SourcePaths )
146
- }.orElse {
147
- dirsAndFiles.collectFirst {
148
- case d : Directory =>
149
- if (dirsAndFiles.length > 1 )
150
- System .err.println(
151
- s " Warning: setting ${d.path} as the project root directory for this run. "
152
- )
153
- (d.path, true , WorkspaceOrigin .SourcePaths )
154
- case f : SourceFile =>
155
- if (dirsAndFiles.length > 1 )
156
- System .err.println(
157
- s " Warning: setting ${f.path / os.up} as the project root directory for this run. "
158
- )
159
- (f.path / os.up, true , WorkspaceOrigin .SourcePaths )
160
- }
161
- }.orElse {
162
- validElems.collectFirst {
163
- case _ : Virtual =>
164
- (os.temp.dir(), true , WorkspaceOrigin .VirtualForced )
165
- }
166
- }.getOrElse((os.pwd, true , WorkspaceOrigin .Forced ))
167
- }
168
-
169
- val (workspace, needsHash, workspaceOrigin0) = forcedWorkspace match {
170
- case None => (inferredWorkspace, inferredNeedsHash, workspaceOrigin)
171
- case Some (forcedWorkspace0) =>
172
- val needsHash0 = forcedWorkspace0 != inferredWorkspace || inferredNeedsHash
173
- (forcedWorkspace0, needsHash0, WorkspaceOrigin .Forced )
174
- }
175
136
val allDirs = validElems.collect { case d : Directory => d.path }
176
137
val updatedElems = validElems.filter {
177
138
case f : SourceFile =>
@@ -189,7 +150,7 @@ object Inputs {
189
150
workspace,
190
151
baseProjectName,
191
152
mayAppendHash = needsHash,
192
- workspaceOrigin = Some (workspaceOrigin0 ),
153
+ workspaceOrigin = Some (workspaceOrigin ),
193
154
enableMarkdown = enableMarkdown,
194
155
allowRestrictedFeatures = allowRestrictedFeatures
195
156
)
@@ -365,7 +326,7 @@ object Inputs {
365
326
enableMarkdown : Boolean ,
366
327
allowRestrictedFeatures : Boolean ,
367
328
extraClasspathWasPassed : Boolean
368
- )(using ScalaCliInvokeData ): Either [BuildException , Inputs ] = {
329
+ )(using invokeData : ScalaCliInvokeData ): Either [BuildException , Inputs ] = {
369
330
val validatedArgs : Seq [Either [String , Seq [Element ]]] =
370
331
validateArgs(
371
332
args,
@@ -386,15 +347,70 @@ object Inputs {
386
347
case Right (elem) => elem
387
348
}.flatten
388
349
assert(extraClasspathWasPassed || validElems.nonEmpty)
350
+ val (inferredWorkspace, inferredNeedsHash, workspaceOrigin) = {
351
+ val settingsFiles = validElems.projectSettingsFiles
352
+ val dirsAndFiles = validElems.collect {
353
+ case d : Directory => d
354
+ case f : SourceFile => f
355
+ }
356
+ settingsFiles.headOption.map { s =>
357
+ if (settingsFiles.length > 1 )
358
+ System .err.println(
359
+ s " Warning: more than one ${Constants .projectFileName} file has been found. Setting ${s.base} as the project root directory for this run. "
360
+ )
361
+ (s.base, true , WorkspaceOrigin .SourcePaths )
362
+ }.orElse {
363
+ dirsAndFiles.collectFirst {
364
+ case d : Directory =>
365
+ if (dirsAndFiles.length > 1 )
366
+ System .err.println(
367
+ s " Warning: setting ${d.path} as the project root directory for this run. "
368
+ )
369
+ (d.path, true , WorkspaceOrigin .SourcePaths )
370
+ case f : SourceFile =>
371
+ if (dirsAndFiles.length > 1 )
372
+ System .err.println(
373
+ s " Warning: setting ${f.path / os.up} as the project root directory for this run. "
374
+ )
375
+ (f.path / os.up, true , WorkspaceOrigin .SourcePaths )
376
+ }
377
+ }.orElse {
378
+ validElems.collectFirst {
379
+ case _ : Virtual =>
380
+ (os.temp.dir(), true , WorkspaceOrigin .VirtualForced )
381
+ }
382
+ }.getOrElse((os.pwd, true , WorkspaceOrigin .Forced ))
383
+ }
389
384
390
- Right (forValidatedElems(
391
- validElems,
392
- baseProjectName,
393
- forcedWorkspace,
394
- enableMarkdown,
395
- allowRestrictedFeatures,
396
- extraClasspathWasPassed
397
- ))
385
+ val (workspace, needsHash, workspaceOrigin0) = forcedWorkspace match {
386
+ case None => (inferredWorkspace, inferredNeedsHash, workspaceOrigin)
387
+ case Some (forcedWorkspace0) =>
388
+ val needsHash0 = forcedWorkspace0 != inferredWorkspace || inferredNeedsHash
389
+ (forcedWorkspace0, needsHash0, WorkspaceOrigin .Forced )
390
+ }
391
+
392
+ if workspace.toString.contains(File .pathSeparator) then
393
+ val prog = invokeData.invocationString
394
+ val argsString = args.mkString(" " )
395
+ Left (new WorkspaceError (
396
+ s """ Invalid workspace path: ${Console .BOLD }$workspace${Console .RESET }
397
+ |Workspace path cannot contain a ${Console .BOLD }${File .pathSeparator}${Console .RESET }.
398
+ |Consider moving your project to a different path.
399
+ |Alternatively, you can force your workspace with the '--workspace' option:
400
+ | ${Console .BOLD }$prog --workspace <alternative-workspace-path> $argsString${Console .RESET }"""
401
+ .stripMargin
402
+ ))
403
+ else
404
+ Right (forValidatedElems(
405
+ validElems,
406
+ baseProjectName,
407
+ workspace,
408
+ needsHash,
409
+ workspaceOrigin0,
410
+ enableMarkdown,
411
+ allowRestrictedFeatures,
412
+ extraClasspathWasPassed
413
+ ))
398
414
}
399
415
else
400
416
Left (new InputsException (invalid.mkString(System .lineSeparator())))
0 commit comments