-
Notifications
You must be signed in to change notification settings - Fork 850
Allows stack.yaml files to use !include directives #6880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| <div class="hidden-warning"><a href="https://docs.haskellstack.org/"><img src="https://cdn.jsdelivr.net/gh/commercialhaskell/stack/doc/img/hidden-warning.svg"></a></div> | ||
|
|
||
| # The `!include` directive | ||
|
|
||
| Stack's configuration files are in the [YAML](https://yaml.org/) format. Stack | ||
| supports a non-standard `!include` YAML directive that allows the content of | ||
| one YAML file to be included in another. The directive can be used in both | ||
| [project-level and global](index.md#project-level-and-global-configuration-files) | ||
| configuration files. | ||
|
|
||
| The included file path is relative to the directory containing the file with the | ||
| `!include` directive. | ||
|
|
||
| !!! warning | ||
|
|
||
| The [`stack config set`](../../commands/config_command.md#the-stack-config-set-commands) | ||
| commands cannot modify a configuration file that uses `!include` directives. | ||
|
|
||
| ## Including a value | ||
|
|
||
| A value for a key can be provided by an included file. For example, given a file | ||
| `snapshot.yaml` with the content: | ||
|
|
||
| ~~~yaml | ||
| lts-23.24 | ||
| ~~~ | ||
|
|
||
| the following project-level configuration file would use `lts-23.24` as the | ||
| snapshot: | ||
|
|
||
| ~~~yaml | ||
| snapshot: !include snapshot.yaml | ||
| packages: | ||
| - . | ||
| ~~~ | ||
|
|
||
| The included file replaces the `!include` directive with its content, so this is | ||
| equivalent to: | ||
|
|
||
| ~~~yaml | ||
| snapshot: lts-23.24 | ||
| packages: | ||
| - . | ||
| ~~~ | ||
|
|
||
| ## Merging mappings | ||
|
|
||
| YAML's merge key (`<<`) can be combined with `!include` to merge the content of | ||
| an included file into the current mapping. For example, given a file | ||
| `shared-config.yaml` with the content: | ||
|
|
||
| ~~~yaml | ||
| ghc-options: | ||
| "$everything": -Wall | ||
| flags: | ||
| my-package: | ||
| dev: true | ||
| ~~~ | ||
|
|
||
| the following project-level configuration file would merge those options: | ||
|
|
||
| ~~~yaml | ||
| snapshot: lts-23.24 | ||
| <<: !include shared-config.yaml | ||
| packages: | ||
| - . | ||
| ~~~ | ||
|
|
||
| This is equivalent to: | ||
|
|
||
| ~~~yaml | ||
| snapshot: lts-23.24 | ||
| ghc-options: | ||
| "$everything": -Wall | ||
| flags: | ||
| my-package: | ||
| dev: true | ||
| packages: | ||
| - . | ||
| ~~~ | ||
|
|
||
| The `!include` directive can also be placed on the line after the merge key: | ||
|
|
||
| ~~~yaml | ||
| snapshot: lts-23.24 | ||
| <<: | ||
| !include shared-config.yaml | ||
| packages: | ||
| - . | ||
| ~~~ | ||
|
|
||
| ## Including list items | ||
|
|
||
| The `!include` directive can also be used to include the contents of a file as a | ||
| list item. For example, given a file `extra-deps.yaml` with the content: | ||
|
|
||
| ~~~yaml | ||
| - acme-missiles-0.3 | ||
| - text-short-0.1.6 | ||
| ~~~ | ||
|
|
||
| the following would use those as extra dependencies: | ||
|
|
||
| ~~~yaml | ||
| snapshot: lts-23.24 | ||
| extra-deps: !include extra-deps.yaml | ||
| ~~~ | ||
|
|
||
| ## Nested includes | ||
|
|
||
| Included files can themselves contain `!include` directives, allowing for nested | ||
| composition of configuration. Stack detects and raises an error for cyclic | ||
| includes. | ||
|
|
||
| ## Use with global configuration | ||
|
|
||
| The `!include` directive can also be used in the global configuration file | ||
| (`config.yaml`). For example, given a file `ghc-options.yaml` with the content: | ||
|
|
||
| ~~~yaml | ||
| ghc-options: | ||
| "$everything": -j4 | ||
| ~~~ | ||
|
|
||
| the global configuration file could include it: | ||
|
|
||
| ~~~yaml | ||
| <<: !include ghc-options.yaml | ||
| install-ghc: true | ||
| system-ghc: false | ||
| ~~~ |
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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import StackTest | ||
|
|
||
| import Control.Monad (unless) | ||
| import Data.List (isInfixOf) | ||
| import System.Directory (getCurrentDirectory) | ||
| import System.Environment (setEnv) | ||
| import System.FilePath ( (</>) ) | ||
|
|
||
| main :: IO () | ||
| main = do | ||
| let | ||
| checkFor expected actual = | ||
| unless (expected == actual) $ | ||
| error ("expected " <> show expected <> "but got: " <> show actual) | ||
|
|
||
| -- Check that includes in stack.yaml files are included | ||
| stackCheckStdout | ||
| ["--stack-yaml","stack-including-flags.yaml","run"] | ||
| (checkFor "TEST_FLAG was set\n") | ||
|
|
||
| stackCheckStdout | ||
| ["--stack-yaml","stack-including-flags-with-newline.yaml","run"] | ||
| (checkFor "TEST_FLAG was set\n") | ||
|
|
||
| stackCheckStdout | ||
| ["--stack-yaml","stack-not-including-flags.yaml","run"] | ||
| (checkFor "TEST_FLAG was not set\n") | ||
|
|
||
| -- Check that includes in config.yaml files are included | ||
| currentDir <- getCurrentDirectory | ||
| setEnv "STACK_CONFIG" (currentDir </> "config-including-flags.yaml") | ||
| stackCheckStdout | ||
| ["--stack-yaml","stack-not-including-flags.yaml","run"] | ||
| (checkFor "TEST_FLAG was set\n") | ||
|
|
||
| -- Check that 'config set' succeeds when the key already exists in a | ||
| -- stack.yaml file that uses !include directives | ||
| stackCheckStderr | ||
| ["--stack-yaml","stack-including-flags.yaml","config","set","snapshot","lts-24.37"] | ||
| (expectMessage "already contained the intended configuration") | ||
|
|
||
| -- Check that 'config set' succeeds when the key already exists in a | ||
| -- stack.yaml file that uses !include directives (with newline variant) | ||
| stackCheckStderr | ||
| ["--stack-yaml","stack-including-flags-with-newline.yaml","config","set","snapshot","lts-24.37"] | ||
| (expectMessage "already contained the intended configuration") | ||
|
mpilgrem marked this conversation as resolved.
|
||
|
|
||
| -- Check that 'config set' raises an error when the key does not exist in a | ||
| -- stack.yaml file that uses !include directives | ||
| stackErrStderr | ||
| ["--stack-yaml","stack-including-file-with-install-ghc.yaml","config","set","install-ghc","true"] | ||
| (expectMessage "!include") | ||
|
|
||
| expectMessage :: String -> String -> IO () | ||
| expectMessage msg stderr' = do | ||
| unless (msg `isInfixOf` stderr') | ||
| (error $ "Expected stderr to contain " ++ show msg ++ " but got:\n" ++ stderr') | ||
14 changes: 14 additions & 0 deletions
14
tests/integration/tests/6879-stack-yaml-includes/files/app/Main.hs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| {-# LANGUAGE CPP #-} | ||
|
|
||
| module Main | ||
| ( main | ||
| ) where | ||
|
|
||
| main :: IO () | ||
| main = | ||
| #if TEST_FLAG | ||
| putStrLn "TEST_FLAG was set" | ||
| #else | ||
| putStrLn "TEST_FLAG was not set" | ||
| #endif | ||
|
|
2 changes: 2 additions & 0 deletions
2
tests/integration/tests/6879-stack-yaml-includes/files/config-flags.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ghc-options: | ||
| "$everything": -DTEST_FLAG |
1 change: 1 addition & 0 deletions
1
tests/integration/tests/6879-stack-yaml-includes/files/config-including-flags.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <<: !include config-flags.yaml |
17 changes: 17 additions & 0 deletions
17
tests/integration/tests/6879-stack-yaml-includes/files/files.cabal
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| name: files | ||
| version: 0.1.0.0 | ||
| build-type: Simple | ||
| cabal-version: >=1.10 | ||
|
|
||
| flag test-flag | ||
| description: Generate a compiler error for test purposes | ||
| default: False | ||
| manual: True | ||
|
|
||
| executable test-exe | ||
| hs-source-dirs: app | ||
| main-is: Main.hs | ||
| build-depends: base >= 4.7 && < 5 | ||
| default-language: Haskell2010 | ||
| if flag(test-flag) | ||
| cpp-options: -DTEST_FLAG |
1 change: 1 addition & 0 deletions
1
tests/integration/tests/6879-stack-yaml-includes/files/install-ghc.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| install-ghc: true |
3 changes: 3 additions & 0 deletions
3
tests/integration/tests/6879-stack-yaml-includes/files/stack-flags.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| flags: | ||
| files: | ||
| test-flag: true |
2 changes: 2 additions & 0 deletions
2
...tegration/tests/6879-stack-yaml-includes/files/stack-including-file-with-install-ghc.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| snapshot: lts-24.37 | ||
| <<: !include install-ghc.yaml |
3 changes: 3 additions & 0 deletions
3
.../integration/tests/6879-stack-yaml-includes/files/stack-including-flags-with-newline.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| snapshot: lts-24.37 | ||
| <<: | ||
| !include stack-flags.yaml |
2 changes: 2 additions & 0 deletions
2
tests/integration/tests/6879-stack-yaml-includes/files/stack-including-flags.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| snapshot: lts-24.37 | ||
| <<: !include stack-flags.yaml |
1 change: 1 addition & 0 deletions
1
tests/integration/tests/6879-stack-yaml-includes/files/stack-not-including-flags.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| snapshot: lts-24.37 |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.