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
6 changes: 6 additions & 0 deletions src/Terrabuild/CLI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type LogsArgs =
| [<Unique; AltCommandLine("-c")>] Configuration of name:string
| [<Unique; AltCommandLine("-e")>] Environment of name:string
| [<EqualsAssignment; AltCommandLine("-v")>] Variable of variable:string * value:string
| [<Unique; AltCommandLine("-t")>] Type of types:string list
| [<Unique; AltCommandLine("-l")>] Label of labels:string list
| [<Unique; AltCommandLine("-p")>] Project of projects:string list
| [<Unique>] Local_Only
Expand All @@ -37,6 +38,7 @@ with
| Configuration _ -> "Configuration to use."
| Environment _ -> "Environment to use."
| Variable _ -> "Set variable."
| Type _-> "Select projects based on extension types."
| Label _-> "Select projects based on labels."
| Project _ -> "Select projets base on id."
| Local_Only -> "Use local cache only."
Expand All @@ -48,6 +50,7 @@ type RunArgs =
| [<Unique; AltCommandLine("-c")>] Configuration of name:string
| [<Unique; AltCommandLine("-e")>] Environment of name:string
| [<EqualsAssignment; AltCommandLine("-v")>] Variable of variable:string * value:string
| [<Unique; AltCommandLine("-t")>] Type of types:string list
| [<Unique; AltCommandLine("-l")>] Label of labels:string list
| [<Unique; AltCommandLine("-p")>] Project of projects:string list
| [<Unique; AltCommandLine("-f")>] Force
Expand All @@ -67,6 +70,7 @@ with
| Configuration _ -> "Configuration to use."
| Environment _ -> "Environment to use."
| Variable _ -> "Set variable."
| Type _-> "Select projects based on extension types."
| Label _ -> "Select projects based on labels."
| Project _ -> "Select projets base on id."
| Force -> "Ignore cache when building target."
Expand All @@ -84,6 +88,7 @@ type ServeArgs =
| [<Unique; AltCommandLine("-c")>] Configuration of name:string
| [<Unique; AltCommandLine("-e")>] Environment of name:string
| [<EqualsAssignment; AltCommandLine("-v")>] Variable of variable:string * value:string
| [<Unique; AltCommandLine("-t")>] Type of types:string list
| [<Unique; AltCommandLine("-l")>] Label of labels:string list
| [<Unique; AltCommandLine("-p")>] Project of projects:string list
with
Expand All @@ -94,6 +99,7 @@ with
| Configuration _ -> "Configuration to use."
| Environment _ -> "Environment to use."
| Variable _ -> "Set variable."
| Type _-> "Select projects based on extension types."
| Label _ -> "Select projects based on labels."
| Project _ -> "Select projets base on id."

Expand Down
1 change: 1 addition & 0 deletions src/Terrabuild/Contracts/ConfigOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Options = {
LogTypes: Contracts.LogType list
Note: string option
Tag: string option
Types: string set option
Labels: string set option
Projects: string set option
Variables: Map<string, string>
Expand Down
18 changes: 14 additions & 4 deletions src/Terrabuild/Core/Configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Project = {
Files: string set
Targets: Map<string, Target>
Labels: string set
Types: string set
}

[<RequireQualifiedAccess>]
Expand Down Expand Up @@ -74,6 +75,7 @@ type private LoadedProject = {
Outputs: string set
Targets: Map<string, AST.Project.TargetBlock>
Labels: string set
Types: string set
Extensions: Map<string, AST.ExtensionBlock>
Scripts: Map<string, LazyScript>
Locals: Map<string, Expr>
Expand Down Expand Up @@ -298,9 +300,8 @@ let private loadProjectDef (options: ConfigOptions.Options) (workspaceConfig: AS

let projectOutputs = projectInfo.Outputs
let projectIgnores = projectInfo.Ignores
let labels =
projectConfig.Project.Initializers |> Set.map (fun x -> x.Replace("@", ""))
|> Set.union projectConfig.Project.Labels
let labels = projectConfig.Project.Labels
let types = projectConfig.Project.Initializers

// convert relative dependencies to absolute dependencies respective to workspaceDirectory
let projectDependencies =
Expand Down Expand Up @@ -343,6 +344,7 @@ let private loadProjectDef (options: ConfigOptions.Options) (workspaceConfig: AS
LoadedProject.Outputs = projectOutputs
LoadedProject.Targets = projectTargets
LoadedProject.Labels = labels
LoadedProject.Types = types
LoadedProject.Extensions = extensions
LoadedProject.Scripts = scripts
LoadedProject.Locals = locals }
Expand Down Expand Up @@ -569,7 +571,8 @@ let private finalizeProject projectDir evaluationContext (projectDef: LoadedProj
Project.Dependencies = projectDependencies
Project.Files = files
Project.Targets = projectSteps
Project.Labels = projectDef.Labels }
Project.Labels = projectDef.Labels
Project.Types = projectDef.Types }



Expand Down Expand Up @@ -719,6 +722,13 @@ let read (options: ConfigOptions.Options) =
| Some labels -> projects |> Map.filter (fun _ config -> Set.intersect config.Labels labels <> Set.empty)
| _ -> projects

// select dependencies with project types if any
let projectSelection =
match options.Types with
| Some types -> projects |> Map.filter (fun _ config -> Set.intersect config.Types types <> Set.empty)
| _ -> projects


// select dependencies with id if any
let projectSelection =
match options.Projects with
Expand Down
8 changes: 8 additions & 0 deletions src/Terrabuild/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type RunTargetOptions = {
Environment: string option
Note: string option
Tag: string option
Types: string set option
Labels: string set option
Projects: string set option
Variables: Map<string, string>
Expand Down Expand Up @@ -86,6 +87,7 @@ let processCommandLine (parser: ArgumentParser<TerrabuildArgs>) (result: ParseRe
ConfigOptions.Options.Environment = options.Environment
ConfigOptions.Options.Note = options.Note
ConfigOptions.Options.Tag = options.Tag
ConfigOptions.Options.Types = options.Types
ConfigOptions.Options.Labels = options.Labels
ConfigOptions.Options.Projects = options.Projects
ConfigOptions.Options.Variables = options.Variables
Expand Down Expand Up @@ -198,6 +200,7 @@ let processCommandLine (parser: ArgumentParser<TerrabuildArgs>) (result: ParseRe
let configuration = runArgs.TryGetResult(RunArgs.Configuration)
let environment = runArgs.TryGetResult(RunArgs.Environment)
let note = runArgs.TryGetResult(RunArgs.Note)
let types = runArgs.TryGetResult(RunArgs.Type) |> Option.map (fun types -> types |> Seq.map String.toLower |> Set)
let labels = runArgs.TryGetResult(RunArgs.Label) |> Option.map (fun labels -> labels |> Seq.map String.toLower |> Set)
let projects = runArgs.TryGetResult(RunArgs.Project) |> Option.map (fun projects -> projects |> Seq.map String.toLower |> Set)
let variables = runArgs.GetResults(RunArgs.Variable) |> Map
Expand Down Expand Up @@ -226,6 +229,7 @@ let processCommandLine (parser: ArgumentParser<TerrabuildArgs>) (result: ParseRe
RunTargetOptions.Environment = environment
RunTargetOptions.Note = note
RunTargetOptions.Tag = tag
RunTargetOptions.Types = types
RunTargetOptions.Labels = labels
RunTargetOptions.Projects = projects
RunTargetOptions.Variables = variables
Expand All @@ -242,6 +246,7 @@ let processCommandLine (parser: ArgumentParser<TerrabuildArgs>) (result: ParseRe
| _ -> raiseInvalidArg "Can't find workspace root directory. Check you are in a workspace."
let configuration = serveArgs.TryGetResult(ServeArgs.Configuration)
let environment = serveArgs.TryGetResult(ServeArgs.Environment)
let types = serveArgs.TryGetResult(ServeArgs.Type) |> Option.map (fun types -> types |> Seq.map String.toLower |> Set)
let labels = serveArgs.TryGetResult(ServeArgs.Label) |> Option.map (fun labels -> labels |> Seq.map String.toLower |> Set)
let projects = serveArgs.TryGetResult(ServeArgs.Project) |> Option.map (fun projects -> projects |> Seq.map String.toLower |> Set)
let variables = serveArgs.GetResults(ServeArgs.Variable) |> Map
Expand All @@ -259,6 +264,7 @@ let processCommandLine (parser: ArgumentParser<TerrabuildArgs>) (result: ParseRe
RunTargetOptions.Environment = environment
RunTargetOptions.Note = None
RunTargetOptions.Tag = None
RunTargetOptions.Types = types
RunTargetOptions.Labels = labels
RunTargetOptions.Projects = projects
RunTargetOptions.Variables = variables
Expand All @@ -276,6 +282,7 @@ let processCommandLine (parser: ArgumentParser<TerrabuildArgs>) (result: ParseRe
| _ -> raiseInvalidArg "Can't find workspace root directory. Check you are in a workspace."
let configuration = logsArgs.TryGetResult(LogsArgs.Configuration)
let environment = logsArgs.TryGetResult(LogsArgs.Environment)
let types = logsArgs.TryGetResult(LogsArgs.Type) |> Option.map (fun types -> types |> Seq.map String.toLower |> Set)
let labels = logsArgs.TryGetResult(LogsArgs.Label) |> Option.map (fun labels -> labels |> Seq.map String.toLower |> Set)
let projects = logsArgs.TryGetResult(LogsArgs.Project) |> Option.map (fun projects -> projects |> Seq.map String.toLower |> Set)
let variables = logsArgs.GetResults(LogsArgs.Variable) |> Map
Expand All @@ -294,6 +301,7 @@ let processCommandLine (parser: ArgumentParser<TerrabuildArgs>) (result: ParseRe
RunTargetOptions.Environment = environment
RunTargetOptions.Note = None
RunTargetOptions.Tag = None
RunTargetOptions.Types = types
RunTargetOptions.Labels = labels
RunTargetOptions.Projects = projects
RunTargetOptions.Variables = variables
Expand Down
35 changes: 21 additions & 14 deletions tests/cluster-layers/results/terrabuild-debug.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@
]
}
},
"labels": [
"dotnet"
"labels": [],
"types": [
"@dotnet"
]
},
"b": {
Expand Down Expand Up @@ -152,8 +153,9 @@
]
}
},
"labels": [
"dotnet"
"labels": [],
"types": [
"@dotnet"
]
},
"c": {
Expand Down Expand Up @@ -221,8 +223,9 @@
]
}
},
"labels": [
"npm"
"labels": [],
"types": [
"@npm"
]
},
"d": {
Expand Down Expand Up @@ -278,8 +281,9 @@
]
}
},
"labels": [
"dotnet"
"labels": [],
"types": [
"@dotnet"
]
},
"e": {
Expand Down Expand Up @@ -335,8 +339,9 @@
]
}
},
"labels": [
"dotnet"
"labels": [],
"types": [
"@dotnet"
]
},
"f": {
Expand Down Expand Up @@ -388,8 +393,9 @@
]
}
},
"labels": [
"npm"
"labels": [],
"types": [
"@npm"
]
},
"g": {
Expand Down Expand Up @@ -440,8 +446,9 @@
]
}
},
"labels": [
"npm"
"labels": [],
"types": [
"@npm"
]
}
}
Expand Down
9 changes: 6 additions & 3 deletions tests/indirect-target/results/terrabuild-debug.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
]
}
},
"labels": []
"labels": [],
"types": []
},
"b": {
"id": "b",
Expand Down Expand Up @@ -153,7 +154,8 @@
]
}
},
"labels": []
"labels": [],
"types": []
},
"c": {
"id": "c",
Expand Down Expand Up @@ -216,7 +218,8 @@
]
}
},
"labels": []
"labels": [],
"types": []
}
}
}
9 changes: 6 additions & 3 deletions tests/multirefs/results/terrabuild-debug.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
]
}
},
"labels": []
"labels": [],
"types": []
},
"b": {
"directory": "B",
Expand Down Expand Up @@ -95,7 +96,8 @@
]
}
},
"labels": []
"labels": [],
"types": []
},
"c": {
"directory": "C",
Expand Down Expand Up @@ -131,7 +133,8 @@
]
}
},
"labels": []
"labels": [],
"types": []
}
}
}
Loading