Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindberg committed Jul 1, 2022
1 parent 81d6bb3 commit 1852d4f
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions bleep-cli/src/main/scala/bleep/internal/Templates.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ object Templates {
combined,
// combined.map(Main.apply),
// test
List(Test(Common)),
List(Test(Common))
// scalas.map(Test.apply),
// platforms.map(Test.apply),
// combined.map(Test.apply)
Expand Down Expand Up @@ -166,7 +166,7 @@ object Templates {
else one.templateId.value.compareTo(two.templateId.value) < 0
}

sorted// ++ sorted.map(Main.apply) ++ sorted.map(Test.apply)
sorted // ++ sorted.map(Main.apply) ++ sorted.map(Test.apply)
}

case object Common extends TemplateDef {
Expand Down Expand Up @@ -250,8 +250,8 @@ object Templates {
val s1 = step[model.CrossProjectName](
logger,
initialProjects = build0.projects.map { case (crossName, p) => (crossName, ProjectKeepExploded(p, p)) },
cn => ignoreWhenInferringTemplates(cn.name),
TemplateDef.templateGroupsForProjects
ignoreWhenInferringTemplates = cn => ignoreWhenInferringTemplates(cn.name),
mkTemplates = TemplateDef.templateGroupsForProjects
)

val groupedCrossProjects: Map[model.ProjectName, ProjectKeepExploded] =
Expand All @@ -261,17 +261,16 @@ object Templates {
logger,
initialProjects = groupedCrossProjects,
ignoreWhenInferringTemplates,
TemplateDef.crossTemplates
mkTemplates = TemplateDef.crossTemplates
)

val build = build0.build.copy(
templates = JsonMap(
(s1.inferredTemplates ++ s2.inferredTemplates)
.collect { case (templateDef, Some(p)) => (templateDef.templateId, p.current) }
.filterNot(_._2.isEmpty)
),
projects = JsonMap(s2.templatedProjects.map { case (n, cp) => (n, cp.current) })
)
val build = {
val templates = (s1.inferredTemplates ++ s2.inferredTemplates).collect {
case (templateDef, Some(p)) if !p.current.isEmpty => (templateDef.templateId, p.current)
}
val projects = s2.templatedProjects.map { case (n, cp) => (n, cp.current) }
build0.build.copy(templates = JsonMap(templates), projects = JsonMap(projects))
}

garbageCollectTemplates(inlineTrivialTemplates(build))
}
Expand Down Expand Up @@ -313,19 +312,22 @@ object Templates {
else Right(projects)
}

val current: Either[String, model.Project] = {
val fullTemplateContents: Either[String, model.Project] = {
// todo: investigate if correct/necessary
val keepParent = templateDef.allParents.map(_.templateId).toSet
def relevantExtends(p: model.Project) =
p.copy(`extends` = JsonList(p.`extends`.values.filter(keepParent)))

initial.flatMap { projects =>
projects.map(x => relevantExtends(x._2.current)).optReduce(_.intersectDropEmpty(_)).toRight("No common settings")
projects
.map(x => relevantExtends(x._2.current))
.optReduce(_.intersectDropEmpty(_))
.toRight("No common settings")
}
}

val maybeTemplateAfterParents: Either[String, TemplateKeepExploded] =
current.map { current =>
val templateContentsAfterParents: Either[String, TemplateKeepExploded] =
fullTemplateContents.map { current =>
val exploded = current.`extends`.values.foldLeft(current) { case (acc, templateId) =>
inferredTemplates(templateById(templateId)) match {
case Some(parent) => acc.union(parent.current)
Expand All @@ -336,9 +338,9 @@ object Templates {
applyInheritance(templateDef, inferredTemplates.apply, template)
}

inferredTemplates(templateDef) = maybeTemplateAfterParents.toOption
inferredTemplates(templateDef) = templateContentsAfterParents.toOption

maybeTemplateAfterParents match {
templateContentsAfterParents match {
case Right(template) =>
val appliedTo = List.newBuilder[ProjectName]

Expand Down

0 comments on commit 1852d4f

Please sign in to comment.