Skip to content

Commit

Permalink
RelevantProjectContent wip
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindberg committed Jul 1, 2022
1 parent 1852d4f commit fbdda1b
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions bleep-cli/src/main/scala/bleep/internal/Templates.scala
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ object Templates {
logger,
initialProjects = build0.projects.map { case (crossName, p) => (crossName, ProjectKeepExploded(p, p)) },
ignoreWhenInferringTemplates = cn => ignoreWhenInferringTemplates(cn.name),
keepRelevantForTemplating = RelevantProjectContent.Parents,
mkTemplates = TemplateDef.templateGroupsForProjects
)

Expand All @@ -261,6 +262,7 @@ object Templates {
logger,
initialProjects = groupedCrossProjects,
ignoreWhenInferringTemplates,
keepRelevantForTemplating = RelevantProjectContent.Noop,
mkTemplates = TemplateDef.crossTemplates
)

Expand All @@ -280,10 +282,32 @@ object Templates {
inferredTemplates: Map[TemplateDef, Option[Templates.TemplateKeepExploded]]
)

@FunctionalInterface
trait RelevantProjectContent {
def apply(p: model.Project, templateDef: TemplateDef): model.Project
}

object RelevantProjectContent {
object Noop extends RelevantProjectContent {
override def apply(p: model.Project, templateDef: TemplateDef): model.Project = p
}

object Parents extends RelevantProjectContent {
override def apply(p: model.Project, templateDef: TemplateDef): 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)))
relevantExtends(p)
}
}
}

def step[ProjectName: Formatter: Nameish](
logger: Logger,
initialProjects: Map[ProjectName, ProjectKeepExploded],
ignoreWhenInferringTemplates: ProjectName => Boolean,
keepRelevantForTemplating: RelevantProjectContent,
mkTemplates: (Map[ProjectName, ProjectKeepExploded], ProjectName => Boolean) => List[TemplateDef]
): StepResult[ProjectName] = {
// we'll apply these groups of templates in turn
Expand Down Expand Up @@ -311,20 +335,13 @@ object Templates {
if (projectNames.sizeIs <= 1) Left(s"Too few qualifying project names: $projectNames")
else Right(projects)
}

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)))

val fullTemplateContents: Either[String, model.Project] =
initial.flatMap { projects =>
projects
.map(x => relevantExtends(x._2.current))
.map(x => keepRelevantForTemplating(x._2.current, templateDef))
.optReduce(_.intersectDropEmpty(_))
.toRight("No common settings")
}
}

val templateContentsAfterParents: Either[String, TemplateKeepExploded] =
fullTemplateContents.map { current =>
Expand Down

0 comments on commit fbdda1b

Please sign in to comment.