diff --git a/.drone.yml b/.drone.yml index b4e820baa37f..1e21a57d5b88 100644 --- a/.drone.yml +++ b/.drone.yml @@ -72,9 +72,7 @@ pipeline: - NIGHTLYBUILD=yes commands: - ./project/scripts/sbtPublish ";dotty-bootstrapped/publishSigned ;sonatypeRelease" - volumes: - - /home/drone/keys:/keys - secrets: [ sonatype_user, sonatype_pw, pgp_pw ] + secrets: [ sonatype_user, sonatype_pw, pgp_pw, pgp_secret ] when: event: deployment environment: nightly @@ -87,9 +85,7 @@ pipeline: # Produces dotty-version.{tar.gz, zip} - ./project/scripts/sbt dist-bootstrapped/packArchive - ./project/scripts/sbtPublish ";dotty-bootstrapped/publishSigned ;sonatypeRelease" - volumes: - - /home/drone/keys:/keys - secrets: [ sonatype_user, sonatype_pw, pgp_pw ] + secrets: [ sonatype_user, sonatype_pw, pgp_pw, pgp_secret ] when: event: tag @@ -111,9 +107,7 @@ pipeline: - RELEASEBUILD=yes commands: - ./project/scripts/sbtPublish ";sbt-dotty/publishSigned ;sonatypeRelease" - volumes: - - /home/drone/keys:/keys - secrets: [ sonatype_user, sonatype_pw, pgp_pw ] + secrets: [ sonatype_user, sonatype_pw, pgp_pw, pgp_secret ] when: event: deployment environment: sbt_release diff --git a/build.sbt b/build.sbt index 93e194a97d37..2939ebf2ec79 100644 --- a/build.sbt +++ b/build.sbt @@ -31,3 +31,4 @@ val `sbt-dotty` = Build.`sbt-dotty` val `vscode-dotty` = Build.`vscode-dotty` inThisBuild(Build.thisBuildSettings) +inScope(Global)(Build.globalSettings) diff --git a/project/Build.scala b/project/Build.scala index 0cebad53caab..7e22c3321b46 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1,9 +1,9 @@ import sbt.Keys._ import sbt._ import complete.DefaultParsers._ -import java.io.{File, RandomAccessFile} +import java.io.File import java.nio.channels.FileLock -import java.nio.file.{ Files, FileSystemException } +import java.nio.file._ import java.util.Calendar import scala.reflect.io.Path @@ -20,6 +20,8 @@ import dotty.tools.sbtplugin.DottyIDEPlugin.autoImport._ import org.scalajs.sbtplugin.ScalaJSPlugin import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ +import com.typesafe.sbt.pgp.PgpKeys + import pl.project13.scala.sbt.JmhPlugin import JmhPlugin.JmhKeys.Jmh @@ -96,27 +98,14 @@ object Build { lazy val bootstrapFromPublishedJars = settingKey[Boolean]("If true, bootstrap dotty from published non-bootstrapped dotty") - // Used in build.sbt - lazy val thisBuildSettings = Def.settings( - // Change this to true if you want to bootstrap using a published non-bootstrapped compiler - bootstrapFromPublishedJars := false, - - // Override `runCode` from sbt-dotty to use the language-server and - // vscode extension from the source repository of dotty instead of a - // published version. - runCode := (run in `dotty-language-server`).toTask("").value - ) - // Only available in vscode-dotty lazy val unpublish = taskKey[Unit]("Unpublish a package") - - - lazy val commonSettings = publishSettings ++ Seq( + // Settings shared by the build (scoped in ThisBuild). Used in build.sbt + lazy val thisBuildSettings = Def.settings( organization := dottyOrganization, organizationName := "LAMP/EPFL", organizationHomepage := Some(url("http://lamp.epfl.ch")), - homepage := Some(url(dottyGithubUrl)), scalacOptions ++= Seq( "-feature", @@ -129,6 +118,60 @@ object Build { javacOptions ++= Seq("-Xlint:unchecked", "-Xlint:deprecation"), + // Change this to true if you want to bootstrap using a published non-bootstrapped compiler + bootstrapFromPublishedJars := false, + + // Override `runCode` from sbt-dotty to use the language-server and + // vscode extension from the source repository of dotty instead of a + // published version. + runCode := (run in `dotty-language-server`).toTask("").value + ) + + // Settings shared globally (scoped in Global). Used in build.sbt + lazy val globalSettings = Def.settings( + // Override `runCode` from sbt-dotty to use the language-server and + // vscode extension from the source repository of dotty instead of a + // published version. + runCode := (run in `dotty-language-server`).toTask("").value, + + onLoad := (onLoad in Global).value andThen { state => + def exists(submodule: String) = { + val path = Paths.get(submodule) + Files.exists(path) && { + val fileStream = Files.list(path) + val nonEmpty = fileStream.iterator().hasNext() + fileStream.close() + nonEmpty + } + } + + // Make sure all submodules are properly cloned + val submodules = List("scala-backend", "scala2-library", "collection-strawman") + if (!submodules.forall(exists)) { + sLog.value.log(Level.Error, + s"""Missing some of the submodules + |You can initialize the modules with: + | > git submodule update --init + """.stripMargin) + } + + // Copy default configuration from .vscode-template/ unless configuration files already exist in .vscode/ + sbt.IO.copyDirectory(new File(".vscode-template/"), new File(".vscode/"), overwrite = false) + + state + }, + + // Credentials to release to Sonatype + credentials ++= ( + for { + username <- sys.env.get("SONATYPE_USER") + password <- sys.env.get("SONATYPE_PW") + } yield Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", username, password) + ).toList, + PgpKeys.pgpPassphrase := sys.env.get("PGP_PW").map(_.toCharArray()) + ) + + lazy val commonSettings = publishSettings ++ Seq( scalaSource in Compile := baseDirectory.value / "src", scalaSource in Test := baseDirectory.value / "test", javaSource in Compile := baseDirectory.value / "src", @@ -881,7 +924,6 @@ object Build { settings(commonSettings). settings( EclipseKeys.skipProject := true, - version := "0.1.2", // Keep in sync with package.json autoScalaLibrary := false, @@ -1097,22 +1139,6 @@ object Build { )) } - lazy val dottyProjectFolderChecks = onLoad in Global := (onLoad in Global).value andThen { state => - val submodules = List(new File("scala-backend"), new File("scala2-library"), new File("collection-strawman")) - if (!submodules.forall(f => f.exists && f.listFiles().nonEmpty)) { - sLog.value.log(Level.Error, - s"""Missing some of the submodules - |You can initialize the modules with: - | > git submodule update --init - """.stripMargin) - } - - // Copy default configuration from .vscode-template/ unless configuration files already exist in .vscode/ - sbt.IO.copyDirectory(new File(".vscode-template/"), new File(".vscode/"), overwrite = false) - - state - } - lazy val commonDistSettings = packSettings ++ Seq( packMain := Map(), publishArtifact := false, @@ -1134,9 +1160,6 @@ object Build { dependsOn(dottyCompiler). dependsOn(dottyLibrary). nonBootstrappedSettings( - triggeredMessage in ThisBuild := Watched.clearWhenTriggered, - dottyProjectFolderChecks, - addCommandAlias("run", "dotty-compiler/run") ++ addCommandAlias("legacyTests", "dotty-compiler/testOnly dotc.tests") ) diff --git a/project/scripts/sbt b/project/scripts/sbt index 60f843fcb6cf..3c35e1b1e2e4 100755 --- a/project/scripts/sbt +++ b/project/scripts/sbt @@ -1,14 +1,10 @@ #!/usr/bin/env bash +set -e # Usage: # ./sbt -CMD="$1" - -if [ -z "$CMD" ]; then - echo "Error: missing sbt command" - exit 1 -fi +CMD="${1:?Missing sbt command}" # run sbt with the supplied arg sbt -J-Xmx4096m \ diff --git a/project/scripts/sbtPublish b/project/scripts/sbtPublish index e089fbb07d2f..8ed985c1662f 100755 --- a/project/scripts/sbtPublish +++ b/project/scripts/sbtPublish @@ -1,34 +1,27 @@ #!/usr/bin/env bash +set -e # Usage: -# SONATYPE_USER= SONATYPE_PW= PGP_PW= ./sbtPublish - -set -e +# SONATYPE_USER= SONATYPE_PW= PGP_PW= PGP_SECRET= ./sbtPublish # Release command: -RELEASE_CMD="$1" +RELEASE_CMD="${1:?Missing publish command}" -if [ -z "$SONATYPE_USER" ] || [ -z "$SONATYPE_PW" ] || [ -z "$PGP_PW" ]; then - echo "Error: SONATYPE_USER, SONATYPE_PW or PGP_PW env unset" - exit 1 -fi +# Make sure required environment variable are set +: "${SONATYPE_USER:?not set}" +: "${SONATYPE_PW:?not set}" +: "${PGP_PW:?not set}" +: "${PGP_SECRET:?is not set}" if [ ! "$NIGHTLYBUILD" = "yes" ] && [ ! "$RELEASEBUILD" = "yes" ]; then echo "Neither NIGHTLYBUILD nor RELEASEBUILD env var set to \"yes\"" exit 1 fi -if [ -z "$RELEASE_CMD" ]; then - echo "Error: missing publish command" - exit 1 -fi - -CMD=" ;set credentials in ThisBuild := Seq(Credentials(\"Sonatype Nexus Repository Manager\", \"oss.sonatype.org\", \"$SONATYPE_USER\", \"$SONATYPE_PW\"))" -CMD="$CMD ;set pgpPassphrase := Some(\"\"\"$PGP_PW\"\"\".toCharArray)" -CMD="$CMD ;set pgpSecretRing := file(\"/keys/secring.asc\")" -CMD="$CMD ;set pgpPublicRing := file(\"/keys/pubring.asc\")" -CMD="$CMD $RELEASE_CMD" +# Write down PGP secret key to the location expected by sbt-pgp +mkdir -p "$HOME/.sbt/gpg" +echo "$PGP_SECRET" > "$HOME/.sbt/gpg/secring.asc" # run sbt with the supplied arg SBT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/sbt" -"$SBT" "$CMD" +"$SBT" "$RELEASE_CMD"