Enable suppression of plugins (#16)

This commit is contained in:
Patrick Stevens
2024-10-08 08:27:53 +01:00
committed by GitHub
parent 2789152331
commit 105e6a9ca3
2 changed files with 20 additions and 2 deletions

View File

@@ -70,6 +70,10 @@ through the `Parameters` field on the plugin's args.
(MSBuild only allows strings here, so the `"true"` in the above example is a string, not a boolean. (MSBuild only allows strings here, so the `"true"` in the above example is a string, not a boolean.
If you want more advanced inputs to your plugin, you will have to create a parser yourself.) If you want more advanced inputs to your plugin, you will have to create a parser yourself.)
You can supply `<WhippetSuppressPlugin>JsonSerializeGenerator,JsonParseGenerator</WhippetSuppressPlugin>` (for example) next to `<WhippetFile>`
to suppress on that file the action of all of the specified comma-separated list of generators.
(That is, we will ignore any generator defined in a class with one of these names.)
## Standalone tool ## Standalone tool
The standalone tool takes the following arguments: The standalone tool takes the following arguments:

View File

@@ -19,6 +19,8 @@ type WhippetTarget =
InputSource : FileInfo InputSource : FileInfo
GeneratedDest : FileInfo GeneratedDest : FileInfo
Params : Map<string, string> Params : Map<string, string>
/// Suppress plugins with any of these names.
Suppress : string Set
} }
module Program = module Program =
@@ -131,6 +133,11 @@ module Program =
) )
|> Map.ofSeq |> Map.ofSeq
let suppress =
Map.tryFind "WhippetSuppressPlugin" metadata
|> Option.map (fun s -> s.Split ',' |> Set.ofArray)
|> Option.defaultValue Set.empty
let inputSource = let inputSource =
FileInfo (Path.Combine (Path.GetDirectoryName desiredProject.ProjectFileName, myriadFile)) FileInfo (Path.Combine (Path.GetDirectoryName desiredProject.ProjectFileName, myriadFile))
@@ -143,6 +150,7 @@ module Program =
GeneratedDest = generatedDest GeneratedDest = generatedDest
InputSource = inputSource InputSource = inputSource
Params = pars Params = pars
Suppress = suppress
} }
|> Some |> Some
) )
@@ -179,14 +187,20 @@ module Program =
) )
|> Seq.toList |> Seq.toList
pluginDll, applicablePlugins pluginAssembly, applicablePlugins
) )
for item in toGenerate do for item in toGenerate do
use output = item.GeneratedDest.Open (FileMode.Create, FileAccess.Write) use output = item.GeneratedDest.Open (FileMode.Create, FileAccess.Write)
use outputWriter = new StreamWriter (output, leaveOpen = true) use outputWriter = new StreamWriter (output, leaveOpen = true)
for _, applicablePlugins in plugins do let plugins =
plugins
|> Seq.map (fun (_, plugins) ->
plugins |> List.filter (fun (ty, _) -> not (Set.contains ty.Name item.Suppress))
)
for applicablePlugins in plugins do
for plugin, hostClass in applicablePlugins do for plugin, hostClass in applicablePlugins do
match getGenerateRawFromRaw hostClass with match getGenerateRawFromRaw hostClass with
| None -> () | None -> ()