Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaking #1057

Merged
merged 11 commits into from
Jun 1, 2022
26 changes: 10 additions & 16 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ object packager extends ScalaModule with Bloop.Module {

object `generate-reference-doc` extends SbtModule with ScalaCliScalafixModule {
def scalaVersion = Scala.defaultInternal
def scalacOptions = T {
super.scalacOptions() ++ Seq("-Ywarn-unused")
}
def moduleDeps = Seq(
cli
)
Expand Down Expand Up @@ -867,28 +864,25 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
launcherTask: T[PathRef],
cliKind: String
) {
def doTest(args: String*) =
T.command {
val argsTask = T.task {
val launcher = launcherTask().path
val extraArgs = Seq(
s"-Dtest.scala-cli.path=$launcher",
s"-Dtest.scala-cli.kind=$cliKind"
)
args ++ extraArgs
}
testTask(argsTask, T.task(Seq.empty[String]))
def test(args: String*) = {
val argsTask = T.task {
val launcher = launcherTask().path
val extraArgs = Seq(
s"-Dtest.scala-cli.path=$launcher",
s"-Dtest.scala-cli.kind=$cliKind"
)
args ++ extraArgs
}
def test(args: String*) =
T.command {
val res = doTest(args: _*)()
val res = testTask(argsTask, T.task(Seq.empty[String]))()
val dotScalaInRoot = os.pwd / workspaceDirName
assert(
!os.isDir(dotScalaInRoot),
s"Expected $workspaceDirName ($dotScalaInRoot) not to have been created"
)
res
}
}
}

def test(args: String*) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ final case class PublishOptions(

@Group("Publishing")
@Hidden
ivy2LocalLike: Option[Boolean] = None
ivy2LocalLike: Option[Boolean] = None,

@Group("Publishing")
@Hidden
parallelUpload: Option[Boolean] = None
)
// format: on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ final case class PublishRepositoryOptions(
@Group("Publishing")
@HelpMessage("Password to use with publishing repository")
@ValueDescription("value:…")
password: Option[PasswordOption] = None
password: Option[PasswordOption] = None,

@Group("Publishing")
@HelpMessage("Realm to use when passing credentials to publishing repository")
@ValueDescription("realm")
realm: Option[String] = None

)
// format: on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ final case class SharedPublishOptions(

@Group("Publishing")
@Hidden
forceSigningBinary: Boolean = false
forceSigningBinary: Boolean = false,

@Group("Publishing")
@Hidden
checksum: List[String] = Nil
)
// format: on

Expand Down
15 changes: 6 additions & 9 deletions modules/cli/src/main/scala/scala/cli/commands/Doc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,12 @@ object Doc extends ScalaCommand[DocOptions] {

alreadyExistsCheck()

val outputPath = {
val docJarPath = value(generateScaladocDirPath(build, logger, extraArgs))
alreadyExistsCheck()
if (force) os.copy.over(docJarPath, destPath)
else os.copy(docJarPath, destPath)
destPath
}
val docJarPath = value(generateScaladocDirPath(build, logger, extraArgs))
alreadyExistsCheck()
if (force) os.copy.over(docJarPath, destPath)
else os.copy(docJarPath, destPath)

val printableOutput = CommandUtils.printablePath(outputPath)
val printableOutput = CommandUtils.printablePath(destPath)

logger.message(s"Wrote Scaladoc to $printableOutput")
}
Expand Down Expand Up @@ -178,7 +175,7 @@ object Doc extends ScalaCommand[DocOptions] {
"-d",
destDir.toString,
"-classpath",
build.project.classesDir.toString
build.fullClassPath.map(_.toString).mkString(File.pathSeparator)
) ++
javaSources.map(_.toString)
val retCode = Runner.run(
Expand Down
8 changes: 0 additions & 8 deletions modules/cli/src/main/scala/scala/cli/commands/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ object Run extends ScalaCommand[RunOptions] {
allowTerminate: Boolean
): Either[BuildException, (Process, CompletableFuture[_])] = either {
val process = value(maybeRunOnce(
inputs.workspace,
inputs.projectName,
build,
programArgs,
logger,
Expand Down Expand Up @@ -165,8 +163,6 @@ object Run extends ScalaCommand[RunOptions] {
}

private def maybeRunOnce(
root: os.Path,
projectName: String,
build: Build.Successful,
args: Seq[String],
logger: Logger,
Expand All @@ -189,8 +185,6 @@ object Run extends ScalaCommand[RunOptions] {
if (jvmRunner) (Constants.runnerMainClass, mainClass +: verbosity +: args)
else (mainClass, args)
val res = runOnce(
root,
projectName,
build,
finalMainClass,
finalArgs,
Expand All @@ -201,8 +195,6 @@ object Run extends ScalaCommand[RunOptions] {
}

private def runOnce(
root: os.Path,
projectName: String,
build: Build.Successful,
mainClass: String,
args: Seq[String],
Expand Down
4 changes: 0 additions & 4 deletions modules/cli/src/main/scala/scala/cli/commands/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ object Test extends ScalaCommand[TestOptions] {
System.err.println()
}
val retCodeOrError = testOnce(
inputs.workspace,
inputs.projectName,
s,
options.requireTests,
args.unparsed,
Expand Down Expand Up @@ -152,8 +150,6 @@ object Test extends ScalaCommand[TestOptions] {
}

private def testOnce(
root: os.Path,
projectName: String,
build: Build.Successful,
requireTests: Boolean,
args: Seq[String],
Expand Down
60 changes: 49 additions & 11 deletions modules/cli/src/main/scala/scala/cli/commands/publish/Publish.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ import scala.cli.commands.{
SharedOptions,
WatchUtil
}
import scala.cli.errors.{FailedToSignFileError, MissingPublishOptionError, UploadError}
import scala.cli.errors.{
FailedToSignFileError,
MalformedChecksumsError,
MissingPublishOptionError,
UploadError
}
import scala.cli.packaging.Library
import scala.cli.publish.BouncycastleSignerMaker

Expand Down Expand Up @@ -111,6 +116,7 @@ object Publish extends ScalaCommand[PublishOptions] {
secretKeyPassword = publishParams.secretKeyPassword,
repoUser = publishRepo.user,
repoPassword = publishRepo.password,
repoRealm = publishRepo.realm,
signer = value {
sharedPublish.signer
.map(Positioned.commandLine(_))
Expand All @@ -122,6 +128,11 @@ object Publish extends ScalaCommand[PublishOptions] {
.map(Positioned.commandLine(_))
.map(ComputeVersion.parse(_))
.sequence
},
checksums = {
val input = sharedPublish.checksum.flatMap(_.split(",")).map(_.trim).filter(_.nonEmpty)
if (input.isEmpty) None
else Some(input)
}
)
)
Expand Down Expand Up @@ -176,6 +187,7 @@ object Publish extends ScalaCommand[PublishOptions] {
ivy2HomeOpt,
publishLocal = false,
forceSigningBinary = options.sharedPublish.forceSigningBinary,
parallelUpload = options.parallelUpload.getOrElse(true),
options.watch.watch
)
}
Expand All @@ -191,6 +203,7 @@ object Publish extends ScalaCommand[PublishOptions] {
ivy2HomeOpt: Option[os.Path],
publishLocal: Boolean,
forceSigningBinary: Boolean,
parallelUpload: Boolean,
watch: Boolean
): Unit = {

Expand All @@ -214,7 +227,8 @@ object Publish extends ScalaCommand[PublishOptions] {
publishLocal,
logger,
allowExit = false,
forceSigningBinary = forceSigningBinary
forceSigningBinary = forceSigningBinary,
parallelUpload = parallelUpload
)
}
}
Expand All @@ -240,7 +254,8 @@ object Publish extends ScalaCommand[PublishOptions] {
publishLocal,
logger,
allowExit = true,
forceSigningBinary = forceSigningBinary
forceSigningBinary = forceSigningBinary,
parallelUpload = parallelUpload
)
}
}
Expand All @@ -259,7 +274,8 @@ object Publish extends ScalaCommand[PublishOptions] {
publishLocal: Boolean,
logger: Logger,
allowExit: Boolean,
forceSigningBinary: Boolean
forceSigningBinary: Boolean,
parallelUpload: Boolean
): Unit = {

val allOk = builds.all.forall {
Expand All @@ -286,7 +302,8 @@ object Publish extends ScalaCommand[PublishOptions] {
ivy2HomeOpt,
publishLocal,
logger,
forceSigningBinary
forceSigningBinary,
parallelUpload
)
if (allowExit)
res.orExit(logger)
Expand Down Expand Up @@ -526,7 +543,8 @@ object Publish extends ScalaCommand[PublishOptions] {
ivy2HomeOpt: Option[os.Path],
publishLocal: Boolean,
logger: Logger,
forceSigningBinary: Boolean
forceSigningBinary: Boolean,
parallelUpload: Boolean
): Either[BuildException, Unit] = either {

assert(docBuilds.isEmpty || docBuilds.length == builds.length)
Expand All @@ -548,10 +566,12 @@ object Publish extends ScalaCommand[PublishOptions] {
Executors.newSingleThreadScheduledExecutor(Util.daemonThreadFactory("publish-retry"))

lazy val authOpt = {
val userOpt = publishOptions.repoUser
val passwordOpt = publishOptions.repoPassword.map(_.get())
passwordOpt.map { password =>
Authentication(userOpt.fold("")(_.get().value), password.value)
val userOpt = publishOptions.repoUser
val realmOpt = publishOptions.repoRealm
val auth = Authentication(userOpt.fold("")(_.get().value), password.value)
realmOpt.fold(auth)(auth.withRealm)
}
}

Expand Down Expand Up @@ -613,6 +633,7 @@ object Publish extends ScalaCommand[PublishOptions] {
else os.Path(repoStr, Os.pwd).toNIO.toUri.toASCIIString
MavenRepository(url)
}
.withAuthentication(authOpt)
(
PublishRepository.Simple(repo0),
None,
Expand Down Expand Up @@ -689,7 +710,8 @@ object Publish extends ScalaCommand[PublishOptions] {
)
case None => NopSigner
}
case None => NopSigner
case Some(PSigner.Nop) => NopSigner
case None => NopSigner
}
val signerLogger =
new InteractiveSignerLogger(new OutputStreamWriter(System.err), verbosity = 1)
Expand Down Expand Up @@ -717,8 +739,19 @@ object Publish extends ScalaCommand[PublishOptions] {

val checksumLogger =
new InteractiveChecksumLogger(new OutputStreamWriter(System.err), verbosity = 1)
val checksumTypes = publishOptions.checksums match {
case None => Seq(ChecksumType.MD5, ChecksumType.SHA1)
case Some(Seq("none")) => Nil
case Some(inputs) =>
value {
inputs
.map(ChecksumType.parse)
.sequence
.left.map(errors => new MalformedChecksumsError(inputs, errors))
}
}
val checksums = Checksums(
Seq(ChecksumType.MD5, ChecksumType.SHA1),
checksumTypes,
fileSet1,
now,
ec,
Expand Down Expand Up @@ -747,7 +780,12 @@ object Publish extends ScalaCommand[PublishOptions] {
val uploadLogger = InteractiveUploadLogger.create(System.err, dummy = dummy, isLocal = isLocal)

val errors =
upload.uploadFileSet(retainedRepo, finalFileSet, uploadLogger, Some(ec)).unsafeRun()(ec)
upload.uploadFileSet(
retainedRepo,
finalFileSet,
uploadLogger,
if (parallelUpload) Some(ec) else None
).unsafeRun()(ec)

errors.toList match {
case h :: t =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ object PublishLocal extends ScalaCommand[PublishLocalOptions] {
ivy2HomeOpt,
publishLocal = true,
forceSigningBinary = options.sharedPublish.forceSigningBinary,
parallelUpload = true,
options.watch.watch
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package scala.cli.errors

import scala.build.errors.BuildException

final class MalformedChecksumsError(input: Seq[String], errors: ::[String])
extends BuildException(s"Malformed checksums: ${errors.mkString(", ")}")
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ case object UsingPublishDirectiveHandler extends UsingDirectiveHandler {
"secretKey",
"secretKeyPassword",
"user",
"password"
"password",
"realm"
).map(prefix + _)

override def getValueNumberBounds(key: String) = key match {
Expand Down Expand Up @@ -148,6 +149,8 @@ case object UsingPublishDirectiveHandler extends UsingDirectiveHandler {
PublishOptions(repoUser = Some(value(parsePasswordOption(singleValue.value))))
case "password" =>
PublishOptions(repoPassword = Some(value(parsePasswordOption(singleValue.value))))
case "realm" =>
PublishOptions(repoRealm = Some(singleValue.value))
case _ =>
value(Left(new UnexpectedDirectiveError(scopedDirective.directive.key)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.eed3si9n.expecty.Expecty.expect
abstract class DocTestDefinitions(val scalaVersionOpt: Option[String])
extends munit.FunSuite with TestScalaVersionArgs {

private lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions
protected lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions

test("generate static scala doc") {
val dest = os.rel / "doc-static"
Expand Down
Loading