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

Pull dependencies rather than scanning the build classpath #201

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import org.scalajs.jsenv.nodejs.NodeJSEnv
import java.io.File
import Smithy4sPlugin.jvmDimSettings
import sys.process._

ThisBuild / commands ++= createBuildCommands(allModules)
Expand Down Expand Up @@ -49,6 +48,7 @@ lazy val allModules = Seq(
codegenPlugin.projectRefs,
benchmark.projectRefs,
protocol.projectRefs,
protocolTests.projectRefs,
openapi.projectRefs,
`aws-kernel`.projectRefs,
aws.projectRefs,
Expand Down Expand Up @@ -323,7 +323,16 @@ lazy val codegen = projectMatrix
.dependsOn(openapi)
.jvmPlatform(buildtimejvmScala2Versions, jvmDimSettings)
.settings(
buildInfoKeys := Seq[BuildInfoKey](version, scalaBinaryVersion),
buildInfoKeys := Seq[BuildInfoKey](
organization,
version,
scalaBinaryVersion,
"protocolArtifact" -> (protocol
.jvm(autoScalaLibrary = false) / moduleName).value,
"smithyOrg" -> Dependencies.Smithy.model.organization,
"smithyVersion" -> Dependencies.Smithy.model.revision,
"smithyArtifact" -> Dependencies.Smithy.model.name
),
buildInfoPackage := "smithy4s.codegen",
isCE3 := true,
libraryDependencies ++= Seq(
Expand Down Expand Up @@ -389,7 +398,7 @@ lazy val codegenPlugin = (projectMatrix in file("modules/codegen-plugin"))
(core.jvm(Scala213) / publishLocal).value,
(codegen.jvm(Scala212) / publishLocal).value,
(openapi.jvm(Scala212) / publishLocal).value,
(protocol.jvm(Scala212) / publishLocal).value
(protocol.jvm(autoScalaLibrary = false) / publishLocal).value
)
publishLocal.value
},
Expand All @@ -407,23 +416,27 @@ lazy val codegenPlugin = (projectMatrix in file("modules/codegen-plugin"))
*/
lazy val protocol = projectMatrix
.in(file("modules/protocol"))
.jvmPlatform(buildtimejvmScala2Versions, jvmDimSettings)
.jvmPlatform(
autoScalaLibrary = false,
scalaVersions = Seq.empty,
settings = jvmDimSettings
)
.settings(
libraryDependencies += Dependencies.Smithy.model,
javacOptions ++= Seq("--release", "8")
Copy link
Contributor

@Baccata Baccata Apr 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍, but we might want Xlint still

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least, in the JVM 11, javac -Xlint did not seem to be a thing

)

lazy val protocolTests = projectMatrix
.in(file("modules/protocol-tests"))
.jvmPlatform(Seq(Scala213), jvmDimSettings)
.dependsOn(protocol)
.settings(
isCE3 := true,
libraryDependencies ++= Seq(
Dependencies.Smithy.model,
"org.scala-lang.modules" %% "scala-collection-compat" % "2.7.0",
Dependencies.Weaver.cats.value % Test,
Dependencies.Weaver.scalacheck.value % Test
),
Test / fork := true,
javacOptions ++= Seq(
"-source",
"1.8",
"-target",
"1.8",
"-Xlint"
)
Test / fork := true
)

/**
Expand Down Expand Up @@ -760,6 +773,8 @@ def genSmithyResources(config: Configuration) = genSmithyImpl(config).map(_._2)
* library code, aws-specific code.
*/
def genSmithyImpl(config: Configuration) = Def.task {
// codegen needs the `protocol` jar to be published
(protocol.jvm(autoScalaLibrary = false) / publishLocal).value

val inputFiles = (config / smithySpecs).value
val outputDir = (config / genSmithyOutput).?.value
Expand Down
16 changes: 8 additions & 8 deletions modules/codegen/src/smithy4s/codegen/ModelLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ import software.amazon.smithy.build.ProjectionTransformer
import software.amazon.smithy.build.TransformContext

object ModelLoader {
private val requiredDeps =
s"${smithy4s.codegen.BuildInfo.organization}:${smithy4s.codegen.BuildInfo.protocolArtifact}:${smithy4s.codegen.BuildInfo.version}" ::
s"${smithy4s.codegen.BuildInfo.smithyOrg}:${smithy4s.codegen.BuildInfo.smithyArtifact}:${smithy4s.codegen.BuildInfo.smithyVersion}" ::
Nil

def load(
specs: Set[File],
dependencies: List[String],
repositories: List[String],
transformers: List[String]
): (ClassLoader, Model) = {
val maybeDeps = resolveDependencies(dependencies, repositories)
val allDeps = dependencies ++ requiredDeps
val maybeDeps = resolveDependencies(allDeps, repositories)
val currentClassLoader = this.getClass().getClassLoader()

// Loads a model using whatever's on the current classpath (in particular, anything that
// might be provided by smithy4s itself out of the box)
val modelBuilder =
Model
.assembler()
.discoverModels(currentClassLoader)
.assemble()
.unwrap()
.toBuilder()
val modelBuilder = Model.builder()

maybeDeps.foreach { deps =>
// Loading the model just from upstream dependencies, in isolation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static Builder builder() {
}

/**
* Builder used to create {@link Example}s.
* Builder used to create {@link UncheckedExample}s.
*/
public static final class Builder implements SmithyBuilder<UncheckedExample> {
private String title;
Expand Down
35 changes: 35 additions & 0 deletions modules/protocol/src/smithy4s/api/UuidFormatTrait.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021 Disney Streaming
*
* Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://disneystreaming.github.io/TOST-1.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package smithy4s.api;

import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.AnnotationTrait;

public final class UuidFormatTrait extends AnnotationTrait {
public static ShapeId ID = ShapeId.from("smithy4s.api#uuidFormat");

public UuidFormatTrait() {
super(ID, Node.objectNode());
}

public static final class Provider extends AnnotationTrait.Provider<UuidFormatTrait> {
public Provider() {
super(ID, (node) -> new UuidFormatTrait());
}
}
}
40 changes: 0 additions & 40 deletions modules/protocol/src/smithy4s/api/UuidFormatTrait.scala

This file was deleted.