Skip to content

Commit bf3753e

Browse files
fix: Don't compile docs if there is no need (#3503)
* fix: Don't compile docs if there is no need * Add testcase for publishing without docs --------- Co-authored-by: ghostbuster91 <ghostbuster91@users.noreply.github.com>
1 parent 0f90c77 commit bf3753e

File tree

4 files changed

+67
-11
lines changed

4 files changed

+67
-11
lines changed

modules/cli/src/main/scala/scala/cli/commands/publish/Publish.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
230230
).orExit(logger)
231231
val threads = BuildThreads.create()
232232

233-
val compilerMaker = options.shared.compilerMaker(threads)
234-
val docCompilerMaker = options.shared.compilerMaker(threads, scaladoc = true)
233+
val compilerMaker = options.shared.compilerMaker(threads)
234+
val docCompilerMakerOpt = options.sharedPublish.docCompilerMakerOpt
235235

236236
val cross = options.compileCross.cross.getOrElse(false)
237237

@@ -256,7 +256,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
256256
logger,
257257
initialBuildOptions,
258258
compilerMaker,
259-
docCompilerMaker,
259+
docCompilerMakerOpt,
260260
cross,
261261
workingDir,
262262
ivy2HomeOpt,
@@ -278,7 +278,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
278278
logger: Logger,
279279
initialBuildOptions: BuildOptions,
280280
compilerMaker: ScalaCompilerMaker,
281-
docCompilerMaker: ScalaCompilerMaker,
281+
docCompilerMaker: Option[ScalaCompilerMaker],
282282
cross: Boolean,
283283
workingDir: => os.Path,
284284
ivy2HomeOpt: Option[os.Path],
@@ -299,7 +299,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
299299
inputs,
300300
initialBuildOptions,
301301
compilerMaker,
302-
Some(docCompilerMaker),
302+
docCompilerMaker,
303303
logger,
304304
crossBuilds = cross,
305305
buildTests = false,
@@ -333,7 +333,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
333333
inputs,
334334
initialBuildOptions,
335335
compilerMaker,
336-
Some(docCompilerMaker),
336+
docCompilerMaker,
337337
logger,
338338
crossBuilds = cross,
339339
buildTests = false,

modules/cli/src/main/scala/scala/cli/commands/publish/PublishLocal.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ object PublishLocal extends ScalaCommand[PublishLocalOptions] {
5151
).orExit(logger)
5252
val threads = BuildThreads.create()
5353

54-
val compilerMaker = options.shared.compilerMaker(threads)
55-
val docCompilerMaker = options.shared.compilerMaker(threads, scaladoc = true)
54+
val compilerMaker = options.shared.compilerMaker(threads)
55+
val docCompilerMakerOpt = options.sharedPublish.docCompilerMakerOpt
5656

5757
val cross = options.compileCross.cross.getOrElse(false)
5858

@@ -75,7 +75,7 @@ object PublishLocal extends ScalaCommand[PublishLocalOptions] {
7575
logger,
7676
initialBuildOptions,
7777
compilerMaker,
78-
docCompilerMaker,
78+
docCompilerMakerOpt,
7979
cross,
8080
workingDir,
8181
ivy2HomeOpt,

modules/cli/src/main/scala/scala/cli/commands/publish/SharedPublishOptions.scala

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package scala.cli.commands.publish
22

33
import caseapp.*
44

5+
import scala.build.compiler.{ScalaCompilerMaker, SimpleScalaCompilerMaker}
56
import scala.cli.commands.shared.HelpGroup
67
import scala.cli.commands.tags
78

@@ -85,8 +86,15 @@ final case class SharedPublishOptions(
8586
@HelpMessage("Proceed as if publishing, but do not upload / write artifacts to the remote repository")
8687
@Tag(tags.implementation)
8788
dummy: Boolean = false
88-
)
89-
// format: on
89+
){
90+
// format: on
91+
92+
def docCompilerMakerOpt: Option[ScalaCompilerMaker] =
93+
if (doc.contains(false)) // true by default
94+
None
95+
else
96+
Some(SimpleScalaCompilerMaker("java", Nil, scaladoc = true))
97+
}
9098

9199
object SharedPublishOptions {
92100
implicit lazy val parser: Parser[SharedPublishOptions] = Parser.derive

modules/integration/src/test/scala/scala/cli/integration/PublishLocalTestDefinitions.scala

+48
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,52 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
258258
}
259259
}
260260

261+
test("publish local without docs") {
262+
val expectedFiles = {
263+
val modName = s"${PublishTestInputs.testName}_$testedPublishedScalaVersion"
264+
val base = os.rel / PublishTestInputs.testOrg / modName / testPublishVersion
265+
val baseFiles = Seq(
266+
base / "jars" / s"$modName.jar",
267+
base / "srcs" / s"$modName-sources.jar",
268+
base / "poms" / s"$modName.pom",
269+
base / "ivys" / "ivy.xml"
270+
)
271+
baseFiles
272+
.flatMap { f =>
273+
val md5 = f / os.up / s"${f.last}.md5"
274+
val sha1 = f / os.up / s"${f.last}.sha1"
275+
Seq(f, md5, sha1)
276+
}
277+
.toSet
278+
}
279+
280+
PublishTestInputs.inputs()
281+
.fromRoot { root =>
282+
os.proc(
283+
TestUtil.cli,
284+
"--power",
285+
"publish",
286+
"local",
287+
".",
288+
"--ivy2-home",
289+
os.rel / "ivy2",
290+
extraOptions,
291+
"--doc=false"
292+
)
293+
.call(cwd = root)
294+
val ivy2Local = root / "ivy2" / "local"
295+
val foundFiles = os.walk(ivy2Local)
296+
.filter(os.isFile(_))
297+
.map(_.relativeTo(ivy2Local))
298+
.toSet
299+
val missingFiles = expectedFiles -- foundFiles
300+
val unexpectedFiles = foundFiles -- expectedFiles
301+
if (missingFiles.nonEmpty)
302+
pprint.err.log(missingFiles)
303+
if (unexpectedFiles.nonEmpty)
304+
pprint.err.log(unexpectedFiles)
305+
expect(missingFiles.isEmpty)
306+
expect(unexpectedFiles.isEmpty)
307+
}
308+
}
261309
}

0 commit comments

Comments
 (0)