feat: Add command template to source generators#2646
Draft
Mee-Tree wants to merge 1 commit intoscalacenter:mainfrom
Draft
feat: Add command template to source generators#2646Mee-Tree wants to merge 1 commit intoscalacenter:mainfrom
Mee-Tree wants to merge 1 commit intoscalacenter:mainfrom
Conversation
79c415c to
63d1351
Compare
Contributor
|
Thanks for the contribution! Do you have an example of how would a template look like? |
Author
Hi! For example, if we have a Config.SourceGenerator like this (some types are simplified for the sake of readability): ConfigurationSourceGenerator(
sourcesGlobs = SourcesGlobs(
directory = "/path/to/input",
walkDepth = None,
includes = "glob:*.in",
excludes = Nil
),
outputDirectory = "/path/to/output",
command = Nil,
commandTemplate = List(
"python3",
"-c",
"import sys; print(*sys.argv[1:], sep=\"\\n\")",
"${inputs}",
"$${inputs}",
"pref${inputs}suf",
"smth",
"${unmanaged}",
"pref${unmanaged}suf",
"${nonexistent}",
"$$${output}"
)
)The command would be expanded into: CommandSeq(
"python3",
"-c",
"import sys; print(*sys.argv[1:], sep=\"\\n\")",
"/path/to/input/test1.in",
"/path/to/input/test2.in",
"${inputs}",
"pref/path/to/input/test1.in /path/to/input/test2.insuf",
"smth",
"prefsuf",
"$/path/to/output"
)Which, when run, would output (line numbers added for reference): OutputLet's go through each line:
Please let me know if you have any further questions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is an attempt to provide a more flexible configuration for source generator commands through templating.
It should be fully backward compatible with existing source generator configurations.
Implementation Details
${inputs},${output}, and${unmanaged}${inputs}->"test1.in""test2.in")prefix${inputs}suffix->"prefixtest1.in test2.insuffix")$${inputs}->"${inputs}")This should come in handy for VirtusLab/scala-cli#3583 to eliminate the need for "wrappers" that only reorder the arguments.