diff --git a/bleep-cli/src/main/scala/bleep/internal/Templates.scala b/bleep-cli/src/main/scala/bleep/internal/Templates.scala index c59717560..0aadb55fb 100644 --- a/bleep-cli/src/main/scala/bleep/internal/Templates.scala +++ b/bleep-cli/src/main/scala/bleep/internal/Templates.scala @@ -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) @@ -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 { @@ -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] = @@ -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)) } @@ -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) @@ -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]