Skip to content

Commit af5bbb7

Browse files
committed
Fix path of build.sbt
1 parent 2bf65d2 commit af5bbb7

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package ch.epfl.scala
22

3+
import java.nio.file.Path
4+
import java.nio.file.Paths
5+
36
import scala.collection.mutable
47
import scala.util.Properties
58

@@ -26,6 +29,7 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
2629

2730
object autoImport {
2831
val githubSubmitInputKey: AttributeKey[SubmitInput] = AttributeKey("githubSubmitInput")
32+
val githubWorkspace: AttributeKey[Path] = AttributeKey("githubWorkspace")
2933
val githubManifestsKey: AttributeKey[Map[String, githubapi.Manifest]] = AttributeKey("githubDependencyManifests")
3034
val githubProjectsKey: AttributeKey[Seq[ProjectRef]] = AttributeKey("githubProjectRefs")
3135
val githubDependencyManifest: TaskKey[Option[githubapi.Manifest]] = taskKey(
@@ -106,16 +110,20 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
106110
// updateFull is needed to have information about callers and reconstruct dependency tree
107111
val reportResult = Keys.updateFull.result.value
108112
val projectID = Keys.projectID.value
113+
val root = Paths.get(Keys.loadedBuild.value.root).toAbsolutePath
109114
val scalaVersion = (Keys.artifactName / Keys.scalaVersion).value
110115
val scalaBinaryVersion = (Keys.artifactName / Keys.scalaBinaryVersion).value
111116
val crossVersion = CrossVersion.apply(scalaVersion, scalaBinaryVersion)
112117
val allDirectDependencies = Keys.allDependencies.value
113118
val baseDirectory = Keys.baseDirectory.value
114119
val logger = Keys.streams.value.log
115-
val input = Keys.state.value.get(githubSubmitInputKey)
120+
val state = Keys.state.value
116121

117-
val onResolveFailure = input.flatMap(_.onResolveFailure)
118-
val ignoredConfigs = input.toSeq.flatMap(_.ignoredConfigs).toSet
122+
val inputOpt = state.get(githubSubmitInputKey)
123+
val workspaceOpt = state.get(githubWorkspace)
124+
125+
val onResolveFailure = inputOpt.flatMap(_.onResolveFailure)
126+
val ignoredConfigs = inputOpt.toSeq.flatMap(_.ignoredConfigs).toSet
119127
val moduleName = crossVersion(projectID).name
120128

121129
def getReference(module: ModuleID): String =
@@ -183,10 +191,16 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
183191
}
184192

185193
val projectModuleRef = getReference(projectID)
186-
// TODO: find exact build file for this project
187-
val file = githubapi.FileInfo("build.sbt")
194+
val buildFile = workspaceOpt match {
195+
case None => "build.sbt"
196+
case Some(workspace) =>
197+
if (root.startsWith(workspace)) workspace.relativize(root).resolve("build.sbt").toString
198+
else root.resolve("build.sbt").toString
199+
}
200+
val file = githubapi.FileInfo(buildFile)
188201
val metadata = Map("baseDirectory" -> JString(baseDirectory.toString))
189202
val manifest = githubapi.Manifest(projectModuleRef, file, metadata, resolved.toMap)
203+
logger.info(s"Created manifest of $buildFile")
190204
Some(manifest)
191205
}
192206
}

sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package ch.epfl.scala
22

33
import java.nio.charset.StandardCharsets
4+
import java.nio.file.Path
5+
import java.nio.file.Paths
46
import java.time.Instant
57

68
import scala.concurrent.Await
79
import scala.concurrent.duration.Duration
810
import scala.util.Properties
911
import scala.util.Try
1012

13+
import ch.epfl.scala.GithubDependencyGraphPlugin.autoImport
1114
import ch.epfl.scala.GithubDependencyGraphPlugin.autoImport._
1215
import ch.epfl.scala.JsonProtocol._
1316
import ch.epfl.scala.githubapi.JsonProtocol._
@@ -58,6 +61,7 @@ object SubmitDependencyGraph {
5861

5962
val initState = state
6063
.put(githubSubmitInputKey, input)
64+
.put(autoImport.githubWorkspace, githubWorkspace())
6165
.put(githubManifestsKey, Map.empty[String, Manifest])
6266
.put(githubProjectsKey, projectRefs)
6367

@@ -137,6 +141,7 @@ object SubmitDependencyGraph {
137141
}
138142

139143
private def checkGithubEnv(): Unit = {
144+
githubWorkspace()
140145
githubWorkflow()
141146
githubJobName()
142147
githubRunId()
@@ -147,6 +152,7 @@ object SubmitDependencyGraph {
147152
githubToken()
148153
}
149154

155+
private def githubWorkspace(): Path = Paths.get(githubCIEnv("GITHUB_WORKSPACE")).toAbsolutePath
150156
private def githubWorkflow(): String = githubCIEnv("GITHUB_WORKFLOW")
151157
private def githubJobName(): String = githubCIEnv("GITHUB_JOB")
152158
private def githubRunId(): String = githubCIEnv("GITHUB_RUN_ID")

0 commit comments

Comments
 (0)