Skip to content

Commit 015bdb8

Browse files
committed
Use inline macro to build projectMap
1 parent 5acae67 commit 015bdb8

File tree

4 files changed

+34
-48
lines changed

4 files changed

+34
-48
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dotty.communitybuild
2+
3+
import scala.quoted.Type
4+
5+
class FieldsDsl[V](v: V):
6+
inline def of[T]: Seq[T] = FieldsImpl.fieldsOfType[V, T](v)
7+
8+
extension [V](on: V):
9+
def fields = FieldsDsl(on)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dotty.communitybuild
2+
3+
import scala.quoted._
4+
5+
object FieldsImpl:
6+
inline def fieldsOfType[V, T](inline v: V): Seq[T] =
7+
${ fieldsImpl[V, T]('v) }
8+
9+
def fieldsImpl[V: Type, T: Type](from: Expr[V])(using Quotes): Expr[Seq[T]] =
10+
import quotes.reflect._
11+
val retType = TypeTree.of[T].tpe
12+
def isProjectField(s: Symbol) =
13+
s.isValDef && s.tree.asInstanceOf[ValDef].tpt.tpe <:< retType
14+
val projectsTree = Term.of(from)
15+
val symbols = TypeTree.of[V].symbol.members.filter(isProjectField)
16+
val selects = symbols.map(Select(projectsTree, _).asExprOf[T])
17+
'{ println(${Expr(retType.show)}); ${Varargs(selects)} }

community-build/src/scala/dotty/communitybuild/Main.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import scala.sys.process._
77

88

99
object Main:
10-
def allProjects = projects.projectMap.keys.toList.sorted
1110

1211
private def generateDocs(project: CommunityProject): Seq[Path] =
1312
val name = project.project
@@ -29,7 +28,7 @@ object Main:
2928
Seq("rm", "-rf", "destStr").!
3029
Files.createDirectory(dest)
3130
val (toRun, ignored) =
32-
allProjects.map(projects.projectMap).partition(_.docCommand != null)
31+
allProjects.partition(_.docCommand != null)
3332

3433
val paths = toRun.map { project =>
3534
val name = project.project
@@ -67,13 +66,13 @@ object Main:
6766
sys.exit(1)
6867

6968
case "doc" :: names if names.nonEmpty =>
70-
val missing = names.filterNot(projects.projectMap.contains)
69+
val missing = names.filterNot(projectMap.contains)
7170
if missing.nonEmpty then
7271
println(s"Missing projects: ${missing.mkString(", ")}. All projects: ${allProjects.mkString(", ")}")
7372
sys.exit(1)
7473

7574
val failed = names.filter{ p =>
76-
val docsRoots = generateDocs(projects.projectMap(p))
75+
val docsRoots = generateDocs(projectMap(p))
7776
if docsRoots.nonEmpty then println(s"Docs for $p generated in $docsRoots")
7877
docsRoots.isEmpty
7978
}

community-build/src/scala/dotty/communitybuild/projects.scala

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -451,50 +451,11 @@ object projects:
451451
lazy val verify = SbtCommunityProject(
452452
project = "verify",
453453
sbtTestCommand = "verifyJVM/test",
454+
sbtDocCommand = "verifyJVM/doc",
454455
)
455-
456-
val projectMap = Map(
457-
"utest" -> utest,
458-
"sourcecode" -> sourcecode,
459-
"oslib" -> oslib,
460-
"oslibWatch" -> oslibWatch,
461-
"ujson" -> ujson,
462-
"upickle" -> upickle,
463-
"upickleCore" -> upickleCore,
464-
"geny" -> geny,
465-
"fansi" -> fansi,
466-
"pprint" -> pprint,
467-
"requests" -> requests,
468-
"scas" -> scas,
469-
"intent" -> intent,
470-
"algebra" -> algebra,
471-
"scalacheck" -> scalacheck,
472-
"scalatest" -> scalatest,
473-
"scalatestplusScalacheck" -> scalatestplusScalacheck,
474-
"scalaXml" -> scalaXml,
475-
"scalap" -> scalap,
476-
"betterfiles" -> betterfiles,
477-
"ScalaPB" -> ScalaPB,
478-
"minitest" -> minitest,
479-
"fastparse" -> fastparse,
480-
"stdLib213" -> stdLib213,
481-
"shapeless" -> shapeless,
482-
"xmlInterpolator" -> xmlInterpolator,
483-
"effpi" -> effpi,
484-
"sconfig" -> sconfig,
485-
"zio" -> zio,
486-
"munit" -> munit,
487-
"scodecBits" -> scodecBits,
488-
"scodec" -> scodec,
489-
"scalaParserCombinators" -> scalaParserCombinators,
490-
"dottyCpsAsync" -> dottyCpsAsync,
491-
"scalaz" -> scalaz,
492-
"endpoints4s" -> endpoints4s,
493-
"catsEffect2" -> catsEffect2,
494-
"catsEffect3" -> catsEffect3,
495-
"scalaCollectionCompat" -> scalaCollectionCompat,
496-
"scalaParallelCollections" -> scalaParallelCollections,
497-
)
498-
def apply(key: String) = projectMap(key)
499456

500457
end projects
458+
459+
def allProjects = projects.fields.of[CommunityProject].sortBy(_.project)
460+
461+
lazy val projectMap = allProjects.map(p => p.project -> p).toMap

0 commit comments

Comments
 (0)