Skip to content

Commit 7dc6c43

Browse files
authored
Merge pull request #1932 from tgodzik/update-using-dirs
chore: Remove all deprecated using directive styles
2 parents 5f57adb + 1f6ba72 commit 7dc6c43

File tree

8 files changed

+42
-171
lines changed

8 files changed

+42
-171
lines changed

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

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ import scala.collection.mutable
1818
import scala.jdk.CollectionConverters.*
1919

2020
case class ExtractedDirectives(
21-
offset: Int,
2221
directives: Seq[StrictDirective],
2322
positions: Option[DirectivesPositions]
2423
) {
2524
@targetName("append")
2625
def ++(other: ExtractedDirectives): ExtractedDirectives =
27-
ExtractedDirectives(offset, directives ++ other.directives, positions)
26+
ExtractedDirectives(directives ++ other.directives, positions)
2827
}
2928

3029
case class DirectivesPositions(
@@ -35,16 +34,15 @@ case class DirectivesPositions(
3534

3635
object ExtractedDirectives {
3736

38-
def empty: ExtractedDirectives = ExtractedDirectives(0, Seq.empty, None)
37+
def empty: ExtractedDirectives = ExtractedDirectives(Seq.empty, None)
3938

4039
val changeToSpecialCommentMsg =
41-
"Using directive using plain comments are deprecated. Please use a special comment syntax: '//> ...' or '/*> ... */'"
40+
"Using directive using plain comments are deprecated. Please use a special comment syntax: '//> ...'"
4241

4342
def from(
4443
contentChars: Array[Char],
4544
path: Either[String, os.Path],
4645
logger: Logger,
47-
supportedDirectives: Array[UsingDirectiveKind],
4846
cwd: ScopePath,
4947
maybeRecoverOnError: BuildException => Option[BuildException]
5048
): Either[BuildException, ExtractedDirectives] = {
@@ -101,31 +99,24 @@ object ExtractedDirectives {
10199
logger.diagnostic(msg, positions = Seq(position))
102100
}
103101

104-
val usedDirectives =
105-
if (codeDirectives.nonEmpty) {
106-
val msg =
107-
"This using directive is ignored. File contains directives outside comments and those have higher precedence."
108-
reportWarning(
109-
msg,
110-
getDirectives(plainCommentDirectives) ++ getDirectives(specialCommentDirectives)
111-
)
112-
codeDirectives
113-
}
114-
else if (specialCommentDirectives.nonEmpty) {
115-
val msg =
116-
s"This using directive is ignored. $changeToSpecialCommentMsg"
117-
reportWarning(msg, getDirectives(plainCommentDirectives))
118-
specialCommentDirectives
119-
}
120-
else {
121-
reportWarning(changeToSpecialCommentMsg, getDirectives(plainCommentDirectives))
122-
plainCommentDirectives
123-
}
102+
if (codeDirectives.nonEmpty) {
103+
val msg =
104+
"This using directive is ignored. Only using directives starting with //> are supported."
105+
reportWarning(msg, getDirectives(codeDirectives))
106+
}
107+
108+
if (plainCommentDirectives.nonEmpty) {
109+
val msg =
110+
s"This using directive is ignored. $changeToSpecialCommentMsg"
111+
reportWarning(msg, getDirectives(plainCommentDirectives))
112+
}
113+
114+
val usedDirectives = specialCommentDirectives
124115

125116
// All using directives should use just `using` keyword, no @using or require
126117
reportWarning(
127118
"Deprecated using directive syntax, please use keyword `using`.",
128-
getDirectives(usedDirectives).filter(_.getSyntax != UsingDirectiveSyntax.Using),
119+
getDirectives(specialCommentDirectives).filter(_.getSyntax != UsingDirectiveSyntax.Using),
129120
before = false
130121
)
131122

@@ -136,33 +127,13 @@ object ExtractedDirectives {
136127
StrictDirective(k.getPath.asScala.mkString("."), l.asScala.toSeq)
137128
}
138129

139-
val offset =
140-
if (usedDirectives.getKind != UsingDirectiveKind.Code) 0
141-
else usedDirectives.getCodeOffset
142-
if (supportedDirectives.contains(usedDirectives.getKind))
143-
Right(ExtractedDirectives(offset, strictDirectives, directivesPositionsOpt))
144-
else {
145-
val directiveVales =
146-
usedDirectives.getFlattenedMap.values().asScala.toList.flatMap(_.asScala)
147-
val values = DirectiveUtil.concatAllValues(ScopedDirective(
148-
StrictDirective("", directiveVales),
149-
path,
150-
cwd
151-
))
152-
val directiveErrors = new DirectiveErrors(
153-
::(s"Directive '${usedDirectives.getKind}' is not supported in the given context'", Nil),
154-
values.flatMap(_.positions)
155-
)
156-
maybeRecoverOnError(directiveErrors) match {
157-
case Some(e) => Left(e)
158-
case None => Right(ExtractedDirectives.empty)
159-
}
160-
}
130+
Right(ExtractedDirectives(strictDirectives, directivesPositionsOpt))
161131
}
162132
else
163133
maybeCompositeMalformedDirectiveError match {
164134
case Some(e) => Left(e)
165135
case None => Right(ExtractedDirectives.empty)
166136
}
167137
}
138+
168139
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ object MarkdownCodeBlockProcessor {
2626
contentChars = cb.body.toCharArray,
2727
path = reportingPath,
2828
logger = logger,
29-
supportedDirectives = UsingDirectiveKind.values(),
3029
cwd = scopePath / os.up,
3130
maybeRecoverOnError = maybeRecoverOnError
3231
)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ object PreprocessingUtil {
3232
BuildException,
3333
(DirectivesProcessorOutput[BuildOptions], Option[DirectivesPositions])
3434
] = either {
35-
val ExtractedDirectives(_, directives0, directivesPositions) =
35+
val ExtractedDirectives(directives0, directivesPositions) =
3636
value(from(
3737
content.toCharArray,
3838
path,
3939
logger,
40-
Array(UsingDirectiveKind.PlainComment, UsingDirectiveKind.SpecialComment),
4140
scopePath,
4241
maybeRecoverOnError
4342
))

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ case object ScalaPreprocessor extends Preprocessor {
209209
contentWithNoShebang.toCharArray,
210210
path,
211211
logger,
212-
UsingDirectiveKind.values(),
213212
scopeRoot,
214213
maybeRecoverOnError
215214
))
@@ -350,7 +349,7 @@ case object ScalaPreprocessor extends Preprocessor {
350349
): Either[BuildException, StrictDirectivesProcessingOutput] = either {
351350
val contentChars = content.toCharArray
352351

353-
val ExtractedDirectives(codeOffset, directives0, directivesPositions) = extractedDirectives
352+
val ExtractedDirectives(directives0, directivesPositions) = extractedDirectives
354353

355354
val updatedOptions = value {
356355
DirectivesProcessor.process(
@@ -380,28 +379,14 @@ case object ScalaPreprocessor extends Preprocessor {
380379

381380
val unusedDirectives = updatedRequirements.unused
382381

383-
val updatedContentOpt =
384-
if (codeOffset > 0) {
385-
val headerBytes = contentChars
386-
.iterator
387-
.take(codeOffset)
388-
.map(c => if (c.isControl) c else ' ')
389-
.toArray
390-
val mainBytes = contentChars.drop(codeOffset)
391-
val updatedContent = new String(headerBytes ++ mainBytes)
392-
if (updatedContent == content) None
393-
else Some(updatedContent)
394-
}
395-
else None
396-
397382
value {
398383
unusedDirectives match {
399384
case Seq() =>
400385
Right(StrictDirectivesProcessingOutput(
401386
updatedRequirements.global,
402387
updatedOptions.global,
403388
updatedRequirements.scoped,
404-
updatedContentOpt,
389+
strippedContent = None,
405390
directivesPositions
406391
))
407392
case Seq(h, t*) =>
@@ -426,9 +411,6 @@ case object ScalaPreprocessor extends Preprocessor {
426411
)
427412
}
428413

429-
val changeToSpecialCommentMsg =
430-
"Using directive using plain comments are deprecated. Please use a special comment syntax: '//> ...' or '/*> ... */'"
431-
432414
private def parseDependency(str: String, pos: Position): Either[BuildException, AnyDependency] =
433415
DependencyParser.parse(str) match {
434416
case Left(msg) => Left(new DependencyFormatError(str, msg, positionOpt = Some(pos)))

modules/build/src/test/scala/scala/build/tests/DirectiveParsingTest.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class DirectiveParsingTest extends munit.FunSuite {
6161
code,
6262
Right(path),
6363
persistentLogger,
64-
UsingDirectiveKind.values(),
6564
ScopePath.fromPath(path),
6665
maybeRecoverOnError = e => Some(e)
6766
)
@@ -111,20 +110,18 @@ class DirectiveParsingTest extends munit.FunSuite {
111110
}
112111

113112
test("Test warnings about mixing syntax") {
114-
testDiagnostics(directive, specialCommentDirective)(Warn("ignored", 1, 0))
115-
testDiagnostics(directive, commentDirective)(Warn("ignored", 1, 0))
113+
testDiagnostics(directive, specialCommentDirective)(Warn("ignored", 0, 0))
114+
testDiagnostics(directive, commentDirective)(Warn("ignored", 0, 0))
116115
testDiagnostics(specialCommentDirective, commentDirective)(Warn("ignored", 1, 0))
117116
testDiagnostics(commentDirective, specialCommentDirective)(Warn("deprecated", 0, 0))
118117
}
119118

120-
test("Plain comment only result in no ignored warning") {
121-
testDiagnostics(commentDirective)(NoWarn("ignored"))
119+
test("Plain comment result in ignored warning") {
120+
testDiagnostics(commentDirective)(Warn("ignored", 0, 0))
122121
}
123122

124123
test("@using is deprecated") {
125124
def addAt(s: String) = s.replace("using ", "@using ")
126-
testDiagnostics(addAt(commentDirective))(Warn("syntax", 0, 3), Warn("keyword", 0, 3))
127-
testDiagnostics(addAt(directive))(Warn("syntax", 0, 0), Warn("keyword", 0, 0))
128125
testDiagnostics(addAt(specialCommentDirective))(Warn("syntax", 0, 4), Warn("keyword", 0, 4))
129126
}
130127

modules/build/src/test/scala/scala/build/tests/SourcesTests.scala

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -245,27 +245,6 @@ class SourcesTests extends munit.FunSuite {
245245
}
246246
}
247247

248-
test("should fail dependencies in .java with using keyword") {
249-
val testInputs = TestInputs(
250-
os.rel / "Something.java" ->
251-
"""using dep "org3:::name3:3.3"
252-
|
253-
|public class Something {
254-
| public Int a = 1;
255-
|}
256-
|""".stripMargin
257-
)
258-
testInputs.withInputs { (_, inputs) =>
259-
val crossSources = CrossSources.forInputs(
260-
inputs,
261-
preprocessors,
262-
TestLogger(),
263-
SuppressWarningOptions()
264-
)
265-
expect(crossSources.isLeft)
266-
}
267-
}
268-
269248
test("should fail for ammonite imports in .sc - $ivy") {
270249
val testInputs = TestInputs(
271250
os.rel / "something.sc" ->

project/deps.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ object Deps {
182182
def swoval = ivy"com.swoval:file-tree-views:2.1.9"
183183
def testInterface = ivy"org.scala-sbt:test-interface:1.0"
184184
def toolkit = ivy"org.virtuslab:toolkit:0.1.0"
185-
def usingDirectives = ivy"org.virtuslab:using_directives:0.0.10"
185+
def usingDirectives = ivy"org.virtuslab:using_directives:0.1.0"
186186
// Lives at https://github.com/scala-cli/no-crc32-zip-input-stream, see #865
187187
// This provides a ZipInputStream that doesn't verify CRC32 checksums, that users
188188
// can enable by setting SCALA_CLI_VENDORED_ZIS=true in the environment, to workaround

0 commit comments

Comments
 (0)