Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target build { # comment at end of line

target dist {
depends_on = [ target.build ]
managed = false
rebuild = true
}

Expand Down
18 changes: 12 additions & 6 deletions src/Terrabuild.Configuration.Tests/Workspace.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ let parseWorkspace() =
let expectedWorkspace =
let targetBuild =
{ TargetBlock.DependsOn = Set [ "^build" ] |> Some
TargetBlock.Rebuild = None }
TargetBlock.Rebuild = None
TargetBlock.Managed = None }
let targetDist =
{ TargetBlock.DependsOn = Set [ "build" ] |> Some
TargetBlock.Rebuild = Expr.Bool true |> Some }
TargetBlock.Rebuild = Expr.Bool true |> Some
TargetBlock.Managed = Expr.False |> Some }
let targetDummy =
{ TargetBlock.DependsOn = None
TargetBlock.Rebuild = None }
TargetBlock.Rebuild = None
TargetBlock.Managed = None }

let extDotnet =
{ Container = Some (Expr.String "mcr.microsoft.com/dotnet/sdk:8.0.101")
Expand Down Expand Up @@ -63,13 +66,16 @@ let parseWorkspace2() =
let expectedWorkspace =
let targetBuild =
{ TargetBlock.DependsOn = Set [ "^build" ] |> Some
TargetBlock.Rebuild = None }
TargetBlock.Rebuild = None
TargetBlock.Managed = None }
let targetDist =
{ TargetBlock.DependsOn = Set [ "build" ] |> Some
TargetBlock.Rebuild = Expr.Bool true |> Some }
TargetBlock.Rebuild = Expr.Bool true |> Some
TargetBlock.Managed = None }
let targetDummy =
{ TargetBlock.DependsOn = None
TargetBlock.Rebuild = None }
TargetBlock.Rebuild = None
TargetBlock.Managed = None }

let extDotnet =
{ Container = Expr.String "mcr.microsoft.com/dotnet/sdk:8.0.101" |> Some
Expand Down
3 changes: 2 additions & 1 deletion src/Terrabuild.Configuration/AST/Workspace.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type WorkspaceBlock =
[<RequireQualifiedAccess>]
type TargetBlock =
{ DependsOn: Set<string> option
Rebuild: Expr option }
Rebuild: Expr option
Managed: Expr option }

[<RequireQualifiedAccess>]
type WorkspaceFile =
Expand Down
6 changes: 4 additions & 2 deletions src/Terrabuild.Configuration/Transpiler/Workspace.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let toWorkspace (block: Block) =

let toTarget (block: Block) =
block
|> checkAllowedAttributes ["depends_on"; "rebuild"]
|> checkAllowedAttributes ["depends_on"; "rebuild"; "managed"]
|> checkNoNestedBlocks
|> ignore

Expand All @@ -58,9 +58,11 @@ let toTarget (block: Block) =
| String.Regex "^target\.(.*)$" [targetIdentifier] -> targetIdentifier
| _ -> raiseInvalidArg $"Invalid target dependency '{dependency}'"))
let rebuild = block |> tryFindAttribute "rebuild"
let managed = block |> tryFindAttribute "managed"

{ TargetBlock.DependsOn = dependsOn
TargetBlock.Rebuild = rebuild }
TargetBlock.Rebuild = rebuild
TargetBlock.Managed = managed }


let toVariable (block: Block) =
Expand Down
69 changes: 33 additions & 36 deletions src/Terrabuild/Core/Configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ let private loadProjectDef (options: ConfigOptions.Options) (workspaceConfig: AS
let extensions = extensions |> Map.addMap projectConfig.Extensions

let projectScripts =
projectConfig.Extensions
|> Map.map (fun _ ext ->
projectConfig.Extensions |> Map.map (fun _ ext ->
ext.Script
|> Option.bind (Eval.asStringOption << Eval.eval evaluationContext)
|> Option.map (FS.workspaceRelative options.Workspace projectDir))
Expand All @@ -264,8 +263,7 @@ let private loadProjectDef (options: ConfigOptions.Options) (workspaceConfig: AS
ProjectInfo.Includes = projectConfig.Project.Includes |> evalAsStringSet }

let initProjectInfo =
projectConfig.Project.Initializers
|> Set.fold (fun projectInfo init ->
projectConfig.Project.Initializers |> Set.fold (fun projectInfo init ->
let parseContext =
let context = { Terrabuild.Extensibility.ExtensionContext.Debug = options.Debug
Terrabuild.Extensibility.ExtensionContext.Directory = projectDir
Expand Down Expand Up @@ -308,8 +306,8 @@ let private loadProjectDef (options: ConfigOptions.Options) (workspaceConfig: AS
|> Set.map (fun dep -> FS.workspaceRelative options.Workspace projectDir dep)

let projectTargets =
projectConfig.Targets
|> Map.map (fun targetName targetBlock ->
// apply target override
projectConfig.Targets |> Map.map (fun targetName targetBlock ->
let workspaceTarget = workspaceConfig.Targets |> Map.tryFind targetName
let rebuild =
match targetBlock.Rebuild with
Expand All @@ -319,10 +317,15 @@ let private loadProjectDef (options: ConfigOptions.Options) (workspaceConfig: AS
match targetBlock.DependsOn with
| Some dependsOn -> Some dependsOn
| _ -> workspaceTarget |> Option.bind _.DependsOn
let managed =
match targetBlock.Managed with
| Some managed -> Some managed
| _ -> workspaceTarget |> Option.bind _.Managed

{ targetBlock with
Rebuild = rebuild
DependsOn = dependsOn })
DependsOn = dependsOn
Managed = managed })

let includes =
projectScripts
Expand All @@ -333,8 +336,7 @@ let private loadProjectDef (options: ConfigOptions.Options) (workspaceConfig: AS
// enrich workspace locals with project locals
// NOTE we are checking for duplicated fields as this is an error
let locals =
workspaceConfig.Locals
|> Map.iter (fun name _ ->
workspaceConfig.Locals |> Map.iter (fun name _ ->
if projectConfig.Locals |> Map.containsKey name then raiseParseError $"duplicated local '{name}'")
workspaceConfig.Locals |> Map.addMap projectConfig.Locals

Expand Down Expand Up @@ -389,8 +391,7 @@ let private finalizeProject projectDir evaluationContext (projectDef: LoadedProj
"terrabuild.version", Value.String projectHash ]

let projectVars =
projectDependencies
|> Seq.choose (fun (KeyValue(_, project)) ->
projectDependencies |> Seq.choose (fun (KeyValue(_, project)) ->
project.Id |> Option.map (fun id ->
$"project.{id}", Value.Map (Map ["version", Value.String project.Hash])))
|> Map.ofSeq
Expand All @@ -402,9 +403,7 @@ let private finalizeProject projectDir evaluationContext (projectDef: LoadedProj
|> Map.addMap projectVars }

let projectSteps =
projectDef.Targets
|> Map.map (fun targetName target ->

projectDef.Targets |> Map.map (fun targetName target ->
let evaluationContext =
let mutable evaluationContext =
let terrabuildTargetVars =
Expand Down Expand Up @@ -449,14 +448,13 @@ let private finalizeProject projectDir evaluationContext (projectDef: LoadedProj
// use value from project target
// otherwise use workspace target
// defaults to allow caching
let rebuild =
let targetRebuild =
target.Rebuild
|> Option.bind (Eval.asBoolOption << Eval.eval evaluationContext)
|> Option.defaultValue false

let targetOperations =
target.Steps
|> List.fold (fun actions step ->
target.Steps |> List.fold (fun actions step ->
let extension =
match projectDef.Extensions |> Map.tryFind step.Extension with
| Some extension -> extension
Expand Down Expand Up @@ -523,21 +521,20 @@ let private finalizeProject projectDir evaluationContext (projectDef: LoadedProj
actions
) []

let dependsOn = target.DependsOn |> Option.defaultValue Set.empty
let targetDependsOn = target.DependsOn |> Option.defaultValue Set.empty

let outputs =
let targetManaged =
target.Managed
|> Option.bind (Eval.asBoolOption << Eval.eval evaluationContext)

let targetOutputs =
let targetOutputs =
target.Outputs
|> Option.bind (Eval.asStringSetOption << Eval.eval evaluationContext)
match targetOutputs with
| Some outputs -> outputs
| _ -> projectDef.Outputs

let hash =
targetOperations
|> List.map (fun ope -> ope.Hash)
|> Hash.sha256strings

let targetCache =
let targetCache =
target.Cache
Expand All @@ -550,19 +547,19 @@ let private finalizeProject projectDir evaluationContext (projectDef: LoadedProj
| None -> None
| _ -> raiseParseError "invalid cache value"

let targetManaged =
target.Managed
|> Option.bind (Eval.asBoolOption << Eval.eval evaluationContext)
let targetHash =
targetOperations
|> List.map (fun ope -> ope.Hash)
|> Hash.sha256strings

let target = {
Target.Hash = hash
Target.Rebuild = rebuild
Target.DependsOn = dependsOn
Target.Cache = targetCache
Target.Managed = targetManaged
Target.Outputs = outputs
Target.Operations = targetOperations
}
let target =
{ Target.Hash = targetHash
Target.Rebuild = targetRebuild
Target.DependsOn = targetDependsOn
Target.Cache = targetCache
Target.Managed = targetManaged
Target.Outputs = targetOutputs
Target.Operations = targetOperations }

target
)
Expand Down