Skip to content

Commit 9c53e62

Browse files
committed
Reorder arguments of ComputeVersion classes
1 parent 49cc749 commit 9c53e62

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

modules/build/src/test/scala/scala/build/options/publish/ComputeVersionTests.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ComputeVersionTests extends munit.FunSuite {
1515
os.rel / "version" -> ver
1616
)
1717
inputs.fromRoot { root =>
18-
val cv = ComputeVersion.Command(Nil, Seq("cat", "version"))
18+
val cv = ComputeVersion.Command(Seq("cat", "version"), Nil)
1919
val readVersion = cv.get(root)
2020
.fold(ex => throw new Exception(ex), identity)
2121
expect(readVersion == ver)
@@ -31,7 +31,7 @@ class ComputeVersionTests extends munit.FunSuite {
3131
os.proc("git", "clone", repo)
3232
.call(cwd = root, stdin = os.Inherit, stdout = os.Inherit)
3333
val dir = root / "compute-version-test"
34-
val cv = ComputeVersion.GitTag(Nil, os.rel, true, "0.0.1-SNAPSHOT")
34+
val cv = ComputeVersion.GitTag(os.rel, true, Nil, "0.0.1-SNAPSHOT")
3535

3636
val commitExpectedVersions = Seq(
3737
"8ea4e87f202fbcc369bec9615e7ddf2c14b39e9d" -> "0.2.0-1-g8ea4e87-SNAPSHOT",
@@ -56,7 +56,7 @@ class ComputeVersionTests extends munit.FunSuite {
5656
expect(!hasHead)
5757

5858
val defaultVersion = "0.0.2-SNAPSHOT"
59-
val cv = ComputeVersion.GitTag(Nil, os.rel, true, defaultVersion)
59+
val cv = ComputeVersion.GitTag(os.rel, true, Nil, defaultVersion)
6060

6161
val version = cv.get(root)
6262
.fold(ex => throw new Exception(ex), identity)

modules/cli/src/main/scala/scala/cli/commands/publish/Publish.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
370370
name
371371
}
372372
def defaultComputeVersion(mayDefaultToGitTag: Boolean): Option[ComputeVersion] =
373-
if (mayDefaultToGitTag) Some(ComputeVersion.GitTag(Nil, os.rel, dynVer = false))
373+
if (mayDefaultToGitTag) Some(ComputeVersion.GitTag(os.rel, dynVer = false, positions = Nil))
374374
else None
375375
def defaultVersionError =
376376
new MissingPublishOptionError("version", "--version", "publish.version")

modules/options/src/main/scala/scala/build/info/BuildInfo.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ object BuildInfo {
106106
mainClass = options.mainClass,
107107
projectVersion = options.sourceGeneratorOptions.computeVersion
108108
.map(cv => value(cv.get(workspace)))
109-
.orElse(ComputeVersion.GitTag(Nil, os.rel, dynVer = false).get(workspace).toOption)
109+
.orElse(
110+
ComputeVersion.GitTag(os.rel, dynVer = false, positions = Nil).get(workspace).toOption
111+
)
110112
),
111113
scalaVersionSettings(options),
112114
platformSettings(options)

modules/options/src/main/scala/scala/build/options/ComputeVersion.scala

+15-15
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import com.github.plokhotnyuk.jsoniter_scala.macros.*
55
import org.eclipse.jgit.api.Git
66
import org.eclipse.jgit.lib.{Constants, Ref}
77

8-
import scala.build.{Position, Positioned}
98
import scala.build.errors.{BuildException, MalformedInputError}
9+
import scala.build.{Position, Positioned}
1010
import scala.io.Codec
1111
import scala.jdk.CollectionConverters.*
1212
import scala.util.{Success, Try, Using}
@@ -19,37 +19,37 @@ sealed abstract class ComputeVersion extends Product with Serializable {
1919

2020
object ComputeVersion {
2121

22-
final case class Command(positions: Seq[Position], command: Seq[String]) extends ComputeVersion {
22+
final case class Command(command: Seq[String], positions: Seq[Position]) extends ComputeVersion {
2323
def get(workspace: os.Path): Either[BuildException, String] = {
2424
val maybeRes = Try(os.proc(command).call(stdin = os.Inherit, cwd = workspace, check = false))
2525
maybeRes match {
2626
case Success(res) if res.exitCode == 0 =>
2727
Right(res.out.trim(Codec.default))
2828
case _ =>
2929
Left(new Command.ComputeVersionCommandError(
30-
positions,
3130
command,
32-
maybeRes.map(_.exitCode).getOrElse(1)
31+
maybeRes.map(_.exitCode).getOrElse(1),
32+
positions
3333
))
3434
}
3535
}
3636
}
3737

3838
object Command {
3939
final class ComputeVersionCommandError(
40-
positions: Seq[Position],
4140
command: Seq[String],
42-
exitCode: Int
41+
exitCode: Int,
42+
positions: Seq[Position]
4343
) extends BuildException(
4444
s"Error running command ${command.mkString(" ")} (exit code: $exitCode)",
4545
positions = positions
4646
)
4747
}
4848

4949
final case class GitTag(
50-
positions: Seq[Position],
5150
repo: os.FilePath,
5251
dynVer: Boolean,
52+
positions: Seq[Position],
5353
defaultFirstVersion: String = "0.1.0-SNAPSHOT"
5454
) extends ComputeVersion {
5555
import GitTag.GitTagError
@@ -166,25 +166,25 @@ object ComputeVersion {
166166

167167
def parse(input: Positioned[String]): Either[BuildException, ComputeVersion] =
168168
if (input.value == "git" || input.value == "git:tag")
169-
Right(ComputeVersion.GitTag(input.positions, os.rel, dynVer = false))
169+
Right(ComputeVersion.GitTag(os.rel, dynVer = false, positions = input.positions))
170170
else if (input.value.startsWith("git:tag:"))
171171
Right(ComputeVersion.GitTag(
172-
input.positions,
173172
os.FilePath(input.value.stripPrefix("git:tag:")),
174-
dynVer = false
173+
dynVer = false,
174+
positions = input.positions
175175
))
176176
else if (input.value == "git:dynver")
177-
Right(ComputeVersion.GitTag(input.positions, os.rel, dynVer = true))
177+
Right(ComputeVersion.GitTag(os.rel, dynVer = true, positions = input.positions))
178178
else if (input.value.startsWith("git:dynver:"))
179179
Right(ComputeVersion.GitTag(
180-
input.positions,
181180
os.FilePath(input.value.stripPrefix("git:dynver:")),
182-
dynVer = true
181+
dynVer = true,
182+
positions = input.positions
183183
))
184184
else if (input.value.startsWith("command:["))
185185
try {
186186
val command = readFromString(input.value.stripPrefix("command:"))(commandCodec)
187-
Right(ComputeVersion.Command(input.positions, command))
187+
Right(ComputeVersion.Command(command, input.positions))
188188
}
189189
catch {
190190
case e: JsonReaderException =>
@@ -200,7 +200,7 @@ object ComputeVersion {
200200
}
201201
else if (input.value.startsWith("command:")) {
202202
val command = input.value.stripPrefix("command:").split("\\s+").toSeq
203-
Right(ComputeVersion.Command(input.positions, command))
203+
Right(ComputeVersion.Command(command, input.positions))
204204
}
205205
else
206206
Left(

0 commit comments

Comments
 (0)