File tree 2 files changed +42
-1
lines changed
test/scala/scala/build/tests
2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -190,9 +190,14 @@ object CrossSources {
190
190
191
191
val flattenedInputs = inputs.flattened()
192
192
val allExclude = { // supports only one exclude directive in one source file, which should be the project file.
193
- val projectScalaFileOpt = flattenedInputs.collectFirst {
193
+ val projectScalaFileCandidates = flattenedInputs.collect {
194
194
case f : ProjectScalaFile => f
195
195
}
196
+
197
+ // this relies upon the inferred workspace root being the outermost directory.
198
+ // which is the common case when you pass a single directory.
199
+ val projectScalaFileOpt =
200
+ projectScalaFileCandidates.sortBy(_.subPath.segments.size).headOption
196
201
val excludeFromProjectFile =
197
202
value(preprocessSources(projectScalaFileOpt.toSeq))
198
203
.flatMap(_.options).flatMap(_.internal.exclude)
Original file line number Diff line number Diff line change @@ -213,4 +213,40 @@ class ExcludeTests extends TestUtil.ScalaCliBuildSuite {
213
213
}
214
214
}
215
215
216
+ test(" exclude nested scala-cli project" ) {
217
+ val testInputs = TestInputs (
218
+ os.rel / " Hello.scala" -> " object Hello" ,
219
+ // this project.scala needs to come first so that the inferred workspace is the outermost one.
220
+ os.rel / " project.scala" ->
221
+ """ //> using exclude */examples/*""" ,
222
+ os.rel / " examples" / " fail.scala" ->
223
+ """ val i: Int = "abc";""" ,
224
+ os.rel / " examples" / " project.scala" ->
225
+ """ val unused = 23"""
226
+ )
227
+ testInputs.withInputs { (root, inputs) =>
228
+ val (crossSources, _) =
229
+ CrossSources .forInputs(
230
+ inputs,
231
+ preprocessors,
232
+ TestLogger (),
233
+ SuppressWarningOptions ()
234
+ )(using ScalaCliInvokeData .dummy).orThrow
235
+ val scopedSources = crossSources.scopedSources(BuildOptions ())
236
+ .orThrow
237
+ val sources =
238
+ scopedSources.sources(
239
+ Scope .Main ,
240
+ crossSources.sharedOptions(BuildOptions ()),
241
+ root,
242
+ TestLogger ()
243
+ )
244
+ .orThrow
245
+
246
+ expect(sources.paths.nonEmpty)
247
+ expect(sources.paths.length == 2 )
248
+ expect(sources.paths.map(_._2) == Seq (os.rel / " Hello.scala" , os.rel / " project.scala" ))
249
+ }
250
+ }
251
+
216
252
}
You can’t perform that action at this time.
0 commit comments