Skip to content

Commit f6735d9

Browse files
Merge pull request #138 from alexarchambault/fmt-command
Add fmt command
2 parents 32efc76 + 6c7ea37 commit f6735d9

File tree

21 files changed

+471
-124
lines changed

21 files changed

+471
-124
lines changed

.scalafmt.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "3.0.0"
1+
version = "3.0.3"
22

33
align.preset = more
44
maxColumn = 100
@@ -12,6 +12,8 @@ newlines.beforeMultiline = keep
1212
newlines.afterCurlyLambdaParams = keep
1313
newlines.alwaysBeforeElseAfterCurlyIf = true
1414

15+
runner.dialect = scala213
16+
1517
fileOverride {
1618
"glob:**/scala-3-stable/**" {
1719
runner.dialect = scala3

build.sc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,23 @@ object `generate-reference-doc` extends SbtModule {
100100
}
101101

102102
object dummy extends Module {
103-
// dummy project to get scala steward updates for Ammonite, whose
104-
// version is used in the repl command, and ensure Ammonite is available
105-
// for all Scala versions we support
103+
// dummy projects to get scala steward updates for Ammonite and scalafmt, whose
104+
// versions are used in the fmt and repl commands, and ensure Ammonite is available
105+
// for all Scala versions we support.
106106
object amm extends Cross[Amm](Scala.listAll: _*)
107107
class Amm(val crossScalaVersion: String) extends CrossScalaModule with Bloop.Module {
108108
def skipBloop = true
109109
def ivyDeps = Agg(
110110
Deps.ammonite
111111
)
112112
}
113+
object scalafmt extends ScalaModule with Bloop.Module {
114+
def skipBloop = true
115+
def scalaVersion = Scala.defaultInternal
116+
def ivyDeps = Agg(
117+
Deps.scalafmtCli
118+
)
119+
}
113120
}
114121

115122
class BuildMacros(val crossScalaVersion: String) extends CrossSbtModule with ScalaCliPublishModule {
@@ -134,6 +141,9 @@ class Build(val crossScalaVersion: String)
134141
def repositories = super.repositories ++ Seq(
135142
coursier.Repositories.sonatype("snapshots")
136143
)
144+
def compileIvyDeps = super.compileIvyDeps() ++ Agg(
145+
Deps.svm
146+
)
137147
def ivyDeps = super.ivyDeps() ++ Agg(
138148
Deps.asm,
139149
Deps.bloopConfig,
@@ -218,6 +228,8 @@ class Build(val crossScalaVersion: String)
218228
|
219229
| def ammoniteVersion = "${Deps.ammonite.dep.version}"
220230
|
231+
| def defaultScalafmtVersion = "${Deps.scalafmtCli.dep.version}"
232+
|
221233
| def defaultScalaVersion = "${Scala.defaultUser}"
222234
|}
223235
|""".stripMargin
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// using scala 2.13
2+
// require scala-js
3+
4+
import scala.scalajs.js
5+
6+
object Test {
7+
def main(args: Array[String]): Unit = {
8+
val console = js.Dynamic.global.console
9+
console.log("Hello from Scala.JS")
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// using scala 2.13
2+
// require scala-native
3+
4+
import scala.scalanative.libc._
5+
import scala.scalanative.unsafe._
6+
7+
object Test {
8+
def main(args: Array[String]): Unit = {
9+
val message = "Hello from Scala Native\n"
10+
Zone { implicit z =>
11+
stdio.printf(toCString(message))
12+
}
13+
}
14+
}

examples/cross-build/Hello.scala

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package scala.build.internal;
2+
3+
import coursier.jvm.ErrnoException;
4+
5+
public final class Chdir {
6+
7+
public static boolean available() {
8+
return false;
9+
}
10+
11+
public static void chdir(String path) throws ErrnoException {
12+
// Not supported on the JVM, returning immediately
13+
}
14+
15+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package scala.build.internal;
2+
3+
import java.io.FileNotFoundException;
4+
5+
import com.oracle.svm.core.CErrorNumber;
6+
import com.oracle.svm.core.annotate.Substitute;
7+
import com.oracle.svm.core.annotate.TargetClass;
8+
import coursier.jvm.ErrnoException;
9+
import coursier.jvm.GraalvmErrnoExtras;
10+
import org.graalvm.nativeimage.c.type.CTypeConversion;
11+
import org.graalvm.nativeimage.Platform;
12+
import org.graalvm.nativeimage.Platforms;
13+
14+
@TargetClass(className = "scala.build.internal.Chdir")
15+
@Platforms({Platform.LINUX.class, Platform.DARWIN.class})
16+
final class ChdirGraalvm {
17+
18+
@Substitute
19+
public static boolean available() {
20+
return true;
21+
}
22+
23+
@Substitute
24+
public static void chdir(String path) throws ErrnoException {
25+
CTypeConversion.CCharPointerHolder path0 = CTypeConversion.toCString(path);
26+
int ret = GraalvmUnistdExtras.chdir(path0.get());
27+
28+
if (ret != 0) {
29+
int n = CErrorNumber.getCErrorNumber();
30+
Throwable cause = null;
31+
if (n == GraalvmErrnoExtras.ENOENT() || n == GraalvmErrnoExtras.ENOTDIR())
32+
cause = new FileNotFoundException(path);
33+
throw new ErrnoException(n, cause);
34+
}
35+
}
36+
37+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package scala.build.internal;
2+
3+
import com.oracle.svm.core.posix.headers.PosixDirectives;
4+
import org.graalvm.nativeimage.Platform;
5+
import org.graalvm.nativeimage.Platforms;
6+
import org.graalvm.nativeimage.c.CContext;
7+
import org.graalvm.nativeimage.c.function.CFunction;
8+
import org.graalvm.nativeimage.c.type.CCharPointer;
9+
import org.graalvm.nativeimage.c.type.CCharPointerPointer;
10+
11+
@CContext(PosixDirectives.class)
12+
@Platforms({Platform.LINUX.class, Platform.DARWIN.class})
13+
public class GraalvmUnistdExtras {
14+
15+
@CFunction
16+
public static native int chdir(CCharPointer path);
17+
18+
}

modules/build/src/main/scala/scala/build/internal/OsLibc.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import scala.util.Properties
99

1010
object OsLibc {
1111

12-
private lazy val isMusl: Option[Boolean] = {
12+
lazy val isMusl: Option[Boolean] = {
1313

1414
def tryRun(cmd: String*): Option[os.CommandResult] =
1515
try {

modules/build/src/main/scala/scala/build/internal/Runner.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ object Runner {
1818
commandName: String,
1919
command: Seq[String],
2020
logger: Logger,
21-
allowExecve: Boolean = false
21+
allowExecve: Boolean = false,
22+
cwd: Option[os.Path] = None
2223
): Int = {
2324

2425
import logger.{log, debug}
@@ -31,18 +32,24 @@ object Runner {
3132

3233
if (allowExecve && Execve.available()) {
3334
debug("execve available")
35+
36+
for (dir <- cwd)
37+
Chdir.chdir(dir.toString)
38+
3439
Execve.execve(
3540
findInPath(command.head).fold(command.head)(_.toString),
3641
commandName +: command.tail.toArray,
3742
sys.env.toArray.sorted.map { case (k, v) => s"$k=$v" }
3843
)
3944
sys.error("should not happen")
4045
}
41-
else
42-
new ProcessBuilder(command: _*)
46+
else {
47+
val b = new ProcessBuilder(command: _*)
4348
.inheritIO()
44-
.start()
45-
.waitFor()
49+
for (dir <- cwd)
50+
b.directory(dir.toIO)
51+
b.start().waitFor()
52+
}
4653
}
4754

4855
def runJvm(

0 commit comments

Comments
 (0)