Skip to content

Commit 8af77d1

Browse files
committed
Add commands to automatically re-fetch and patch the protobuf
1 parent 6e911dc commit 8af77d1

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

build.sbt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,50 @@
11
ThisBuild / scalafixScalaBinaryVersion :=
22
CrossVersion.binaryScalaVersion(scalaVersion.value)
33

4+
val scalametaVersion = "4.13.9"
5+
val semanticdbProtoURL =
6+
"https://raw.githubusercontent.com/scalameta/scalameta/refs/tags/v%s/semanticdb/semanticdb/shared/src/main/proto/semanticdb.proto"
7+
.format(scalametaVersion)
8+
49
ThisBuild / scalaVersion := "2.13.16"
510

611
commands += Command.command("ci") { s =>
7-
s"clean" ::
12+
s"check-protobuf" ::
13+
s"clean" ::
814
s"clean-generated" ::
915
s"generate" ::
1016
s
1117
}
1218

1319
commands += Command.command("generate") { s =>
14-
s"generator/protocGenerate" ::
20+
s"fetch-protobuf" ::
21+
s"generator/protocGenerate" ::
1522
s"output/scalafix AdjustForScala3" ::
1623
s"remove-scalameta-proto" ::
1724
s"output/compile" ::
1825
s
1926
}
27+
28+
commands += Command.command("check-protobuf") { s =>
29+
import scala.sys.process._
30+
val generatorDir = (generator / Compile / baseDirectory).value
31+
assert(
32+
(("%s/src/main/fetch-proto.sh %s %s %s")
33+
.format(generatorDir, semanticdbProtoURL, generatorDir, "true") !) == 0
34+
);
35+
s
36+
}
37+
38+
commands += Command.command("fetch-protobuf") { s =>
39+
import scala.sys.process._
40+
val generatorDir = (generator / Compile / baseDirectory).value
41+
assert(
42+
(("%s/src/main/fetch-proto.sh %s %s %s")
43+
.format(generatorDir, semanticdbProtoURL, generatorDir, "false") !) == 0
44+
);
45+
s
46+
}
47+
2048
commands += Command.command("clean-generated") { s =>
2149
IO.delete(
2250
(output / Compile / baseDirectory).value / "src" / "main" / "scala" / "generated"

generator/src/main/fetch-proto.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env sh
2+
set -e
3+
4+
# Usage: ./fetch-proto.sh {url} {generator-base-directory} {check-only:true/false}
5+
6+
URL="$1"
7+
GENERATOR_DIR="$2"
8+
CHECK_ONLY="$3"
9+
10+
PATCH_FILE="$GENERATOR_DIR/src/main/scalameta-to-compiler.patch"
11+
TARGET="$GENERATOR_DIR/src/main/protobuf/scalameta.proto"
12+
13+
# Fetch the proto file
14+
tmpfile=$(mktemp)
15+
curl -L "$URL" > $tmpfile
16+
17+
# Patch it
18+
patch -u $tmpfile "$PATCH_FILE"
19+
20+
# Check if the content is identical
21+
if diff -wq $tmpfile "$TARGET"; then
22+
echo "Fetched file and current .proto are identical"
23+
exit 0
24+
fi
25+
26+
if test "$CHECK_ONLY" = "true"; then
27+
echo "Fetched file and current .proto differ"
28+
exit 1
29+
fi
30+
31+
echo "Updating $TARGET."
32+
mv $tmpfile "$TARGET"
33+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--- ../scalameta/semanticdb/semanticdb/shared/src/main/proto/semanticdb.proto 2025-09-01 13:27:15.488562021 +0200
2+
+++ generator/src/main/protobuf/scalameta.proto 2025-09-01 13:45:57.842972500 +0200
3+
@@ -1,11 +1,13 @@
4+
syntax = "proto3";
5+
6+
-package scala.meta.internal.semanticdb;
7+
+package dotty.tools.dotc.semanticdb;
8+
9+
import "scalapb/scalapb.proto";
10+
11+
option (scalapb.options) = {
12+
preserve_unknown_fields: false
13+
+ import: "dotty.tools.dotc.semanticdb.internal._"
14+
+ import: "scala.annotation.internal.sharable"
15+
};
16+
17+
enum Schema {
18+

0 commit comments

Comments
 (0)