Skip to content

Commit

Permalink
Remove options compile deps in cli-options module
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Sep 5, 2022
1 parent 021916b commit 61bf5b7
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 32 deletions.
7 changes: 2 additions & 5 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,8 @@ trait CliOptions extends SbtModule with ScalaCliPublishModule with ScalaCliCompi
Deps.jsoniterMacros
)
private def scalaVer = Scala.scala213
def compileModuleDeps = Seq(
options
)
def scalaVersion = scalaVer
def repositories = super.repositories ++ customRepositories
def scalaVersion = scalaVer
def repositories = super.repositories ++ customRepositories
}

trait Cli extends SbtModule with ProtoBuildModule with CliLaunchers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package scala.build.options.publish
package scala.cli.commands.publish

import scala.cli.signing.shared.PasswordOption

Expand All @@ -7,11 +7,7 @@ sealed abstract class MaybeConfigPasswordOption extends Product with Serializabl

object MaybeConfigPasswordOption {
final case class ActualOption(option: PasswordOption) extends MaybeConfigPasswordOption
final case class ConfigOption(fullName: String) extends MaybeConfigPasswordOption {
private lazy val split = fullName.split('.')
def prefix: Seq[String] = split.dropRight(1).toSeq
def name: String = split.last
}
final case class ConfigOption(fullName: String) extends MaybeConfigPasswordOption

def parse(input: String): Either[String, MaybeConfigPasswordOption] =
if (input.startsWith("config:"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package scala.cli.commands.publish

import caseapp._

import scala.build.options.publish.MaybeConfigPasswordOption
import scala.cli.signing.shared.PasswordOption
import scala.cli.signing.util.ArgParsers._
import scala.cli.util.ArgParsers._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package scala.cli.util

import caseapp.core.argparser.ArgParser
import caseapp.core.argparser.SimpleArgParser

import scala.build.options.publish.MaybeConfigPasswordOption
import scala.cli.commands.publish.MaybeConfigPasswordOption
import scala.cli.signing.shared.PasswordOption

abstract class LowPriorityArgParsers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import scala.cli.commands.util.CommonOps.SharedDirectoriesOptionsOps
import scala.cli.commands.util.MainClassOptionsUtil._
import scala.cli.commands.util.ScalaCliSttpBackend
import scala.cli.commands.util.SharedOptionsUtil._
import scala.cli.commands.util.PublishUtils._
import scala.cli.commands.{
MainClassOptions,
Package => PackageCmd,
Expand All @@ -54,7 +55,7 @@ import scala.cli.errors.{
}
import scala.cli.packaging.Library
import scala.cli.publish.BouncycastleSignerMaker
import scala.cli.util.MaybeConfigPasswordOptionHelpers._
import scala.cli.util.ConfigPasswordOptionHelpers._

object Publish extends ScalaCommand[PublishOptions] {

Expand All @@ -79,8 +80,8 @@ object Publish extends ScalaCommand[PublishOptions] {
docJar = sharedPublish.doc,
gpgSignatureId = sharedPublish.gpgKey.map(_.trim).filter(_.nonEmpty),
gpgOptions = sharedPublish.gpgOption,
secretKey = publishParams.secretKey,
secretKeyPassword = publishParams.secretKeyPassword,
secretKey = publishParams.secretKey.map(_.configPasswordOptions()),
secretKeyPassword = publishParams.secretKeyPassword.map(_.configPasswordOptions()),
repoUser = publishRepo.user,
repoPassword = publishRepo.password,
repoRealm = publishRepo.realm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import scala.cli.commands.util.JvmUtils
import scala.cli.config.{ConfigDb, Keys}
import scala.cli.errors.MissingPublishOptionError
import scala.cli.signing.shared.PasswordOption
import scala.cli.util.MaybeConfigPasswordOptionHelpers._
import scala.cli.util.ConfigPasswordOptionHelpers._
import scala.cli.commands.util.PublishUtils._

final case class PgpSecretKeyCheck(
options: PublishSetupOptions,
Expand Down Expand Up @@ -64,7 +65,10 @@ final case class PgpSecretKeyCheck(
case Some(secretKey) =>
val pubKeyOpt = options.publicKey.map(_.get())
val passwordOpt =
value(options.publishParams.secretKeyPassword.map(_.get(configDb())).sequence)
value(options.publishParams.secretKeyPassword
.map(_.configPasswordOptions())
.map(_.get(configDb()))
.sequence)
(pubKeyOpt, Left(secretKey), passwordOpt)
case None =>
value(configDb().get(Keys.pgpSecretKey)) match {
Expand All @@ -83,6 +87,7 @@ final case class PgpSecretKeyCheck(
val res = value {
options.publishParams
.secretKeyPassword
.map(_.configPasswordOptions())
.map(_.get(configDb()))
.sequence
}
Expand Down Expand Up @@ -221,7 +226,8 @@ final case class PgpSecretKeyCheck(
Seq(SetSecret(
"PUBLISH_SECRET_KEY",
secretKey match {
case Left(p) => value(p.get(configDb())).getBytes().map(maybeEncodeBase64)
case Left(p) =>
value(p.configPasswordOptions().get(configDb())).getBytes().map(maybeEncodeBase64)
case Right(p) => p.getBytes().map(maybeEncodeBase64)
},
force = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package scala.cli.commands.util

import java.io.File
import scala.build.options.publish.ConfigPasswordOption
import scala.build.{Os, Position, Positioned}
import scala.cli.commands.SharedOptions
import scala.cli.commands.publish.MaybeConfigPasswordOption
import scala.cli.commands.publish.MaybeConfigPasswordOption.*
import scala.util.Properties

object PublishUtils {

implicit class SharedOptionsOps(v: MaybeConfigPasswordOption) {
def configPasswordOptions() =
v match {
case ActualOption(option) => ConfigPasswordOption.ActualOption(option)
case ConfigOption(fullName) => ConfigPasswordOption.ConfigOption(fullName)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package scala.cli.util

import scala.build.errors.BuildException
import scala.build.options.publish.MaybeConfigPasswordOption
import scala.cli.commands.publish.MaybeConfigPasswordOption
import scala.build.options.publish.ConfigPasswordOption
import scala.cli.config.{ConfigDb, Key}
import scala.cli.errors.MissingConfigEntryError
import scala.cli.signing.shared.PasswordOption

object MaybeConfigPasswordOptionHelpers {
object ConfigPasswordOptionHelpers {

implicit class MaybeConfigPasswordOptionOps(private val opt: MaybeConfigPasswordOption)
implicit class ConfigPasswordOptionOps(private val opt: ConfigPasswordOption)
extends AnyVal {
def get(configDb: => ConfigDb): Either[BuildException, PasswordOption] =
opt match {
case a: MaybeConfigPasswordOption.ActualOption =>
case a: ConfigPasswordOption.ActualOption =>
Right(a.option)
case c: MaybeConfigPasswordOption.ConfigOption =>
case c: ConfigPasswordOption.ConfigOption =>
val key = new Key.PasswordEntry(c.prefix, c.name)
configDb.get(key).flatMap {
case None => Left(new MissingConfigEntryError(c.fullName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package scala.build.preprocessing.directives
import scala.build.EitherCps.{either, value}
import scala.build.Logger
import scala.build.errors.{BuildException, MalformedInputError, UnexpectedDirectiveError}
import scala.build.options.publish.{ComputeVersion, MaybeConfigPasswordOption}
import scala.build.options.publish.ComputeVersion
import scala.build.options.publish.ConfigPasswordOption
import scala.build.options.{
BuildOptions,
PostBuildOptions,
Expand Down Expand Up @@ -101,13 +102,13 @@ case object UsingPublishContextualDirectiveHandler extends UsingDirectiveHandler
case "secretKey" =>
PublishContextualOptions(secretKey =
Some(
MaybeConfigPasswordOption.ActualOption(value(parsePasswordOption(singleValue.value)))
ConfigPasswordOption.ActualOption(value(parsePasswordOption(singleValue.value)))
)
)
case "secretKeyPassword" =>
PublishContextualOptions(
secretKeyPassword = Some(
MaybeConfigPasswordOption.ActualOption(value(parsePasswordOption(singleValue.value)))
ConfigPasswordOption.ActualOption(value(parsePasswordOption(singleValue.value)))
)
)
case "user" =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scala.build.options

import scala.build.options.publish.{ComputeVersion, MaybeConfigPasswordOption, Signer}
import scala.build.options.publish.{ComputeVersion, Signer, ConfigPasswordOption}
import scala.cli.signing.shared.PasswordOption

/** Publishing-related options, that can have different values locally and on CIs */
Expand All @@ -12,8 +12,8 @@ final case class PublishContextualOptions(
gpgSignatureId: Option[String] = None,
gpgOptions: List[String] = Nil,
signer: Option[Signer] = None,
secretKey: Option[MaybeConfigPasswordOption] = None,
secretKeyPassword: Option[MaybeConfigPasswordOption] = None,
secretKey: Option[ConfigPasswordOption] = None,
secretKeyPassword: Option[ConfigPasswordOption] = None,
repoUser: Option[PasswordOption] = None,
repoPassword: Option[PasswordOption] = None,
repoRealm: Option[String] = None,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package scala.build.options.publish

import scala.cli.signing.shared.PasswordOption

/** Can be either a [[PasswordOption]], or something like "config:…" pointing at a config entry */
sealed abstract class ConfigPasswordOption extends Product with Serializable

object ConfigPasswordOption {
final case class ActualOption(option: PasswordOption) extends ConfigPasswordOption
final case class ConfigOption(fullName: String) extends ConfigPasswordOption {
private lazy val split = fullName.split('.')
def prefix: Seq[String] = split.dropRight(1).toSeq
def name: String = split.last
}
}

0 comments on commit 61bf5b7

Please sign in to comment.