Skip to content

Commit 61b9a62

Browse files
committed
Merge branch 'master' into rc/v2.9
2 parents c008b2f + ec93376 commit 61b9a62

File tree

7 files changed

+114
-257
lines changed

7 files changed

+114
-257
lines changed

.github/workflows/integration-tests.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ jobs:
101101
env:
102102
CAN_SIGN: ${{ secrets.RELEASE_SIGNING_KEY != '' }}
103103
outputs:
104-
arm64: ${{ steps.runners.outputs.arm64 }}
104+
arm64-runner: ${{ steps.runners.outputs.arm64 }}
105105
can-sign: ${{ env.CAN_SIGN }}
106+
test-arm64: ${{ steps.runners.outputs.test-arm64 }}
106107
steps:
107108
- name: Check for hosted runners
108109
id: runners
@@ -113,27 +114,29 @@ jobs:
113114
echo "::set-output name=runners::$SELF_HOSTED_RUNNERS"
114115
if echo "$SELF_HOSTED_RUNNERS" | grep -q 'arm64'; then
115116
echo "::set-output name=arm64::['self-hosted', 'linux', 'ARM64']"
117+
echo ::set-output name=test-arm64::true
116118
else
117-
echo '::set-output name=arm64::"ubuntu-latest"'
119+
echo "::set-output name=arm64::'ubuntu-latest'"
120+
echo ::set-output name=test-arm64::false
118121
fi
119122
120123
linux-arm64:
121124
name: Linux ARM64
122-
runs-on: ${{ fromJSON(needs.configuration.outputs.arm64) }}
125+
runs-on: ${{ fromJSON(needs.configuration.outputs.arm64-runner) }}
123126
needs: configuration
124127
steps:
125128
- name: Skipping ARM64
126-
if: needs.configuration.outputs.arm64 == 'ubuntu-latest'
129+
if: needs.configuration.outputs.test-arm64 == 'false'
127130
shell: bash
128131
run: |
129132
echo '::notice title=ARM64 skipped::To build ARM64, a self-hosted runner needs to be configured and the SELF_HOSTED_RUNNERS secret must contain arm64'
130133
131134
- name: Clone project
132-
if: needs.configuration.outputs.arm64 != 'ubuntu-latest'
135+
if: needs.configuration.outputs.test-arm64 == 'true'
133136
uses: actions/checkout@v3
134137

135138
- name: Build bindist
136-
if: needs.configuration.outputs.arm64 != 'ubuntu-latest'
139+
if: needs.configuration.outputs.test-arm64 == 'true'
137140
shell: bash
138141
run: |
139142
set -ex
@@ -143,7 +146,7 @@ jobs:
143146
docker run --rm -v $(pwd):/src -w /src stack bash -c "/home/stack/release build"
144147
145148
- name: Upload bindist
146-
if: needs.configuration.outputs.arm64 != 'ubuntu-latest'
149+
if: needs.configuration.outputs.test-arm64 == 'true'
147150
uses: actions/upload-artifact@v3
148151
with:
149152
name: Linux-ARM64

cabal.project

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- This file is a configuration file for Cabal (the tool). It is provided to
2+
-- assist some users of that tool to develop Stack. For information about
3+
-- `cabal.project` files, see:
4+
-- https://cabal.readthedocs.io/en/stable/cabal-project.html.
5+
6+
-- For information about possible limitations of the `cabal.config` files
7+
-- corresponding to Stackage package sets that are made available by Stackage
8+
-- see: https://github.com/fpco/stackage-server/issues/232.
9+
10+
-- `import:` is only available to users of Cabal (the tool) >= 3.8.1.0.
11+
12+
import: https://www.stackage.org/nightly-2022-09-05/cabal.config
13+
14+
-- Extra-deps (if any) would be specified by adding:
15+
--
16+
-- constraints: <package_name> == <version_number>
17+
18+
packages: .

package.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ library:
262262
- Stack.Unpack
263263
- Stack.Upgrade
264264
- Stack.Upload
265-
- Stack.YamlUpdate
266265
- System.Info.ShortPathName
267266
- System.Permissions
268267
- System.Process.Pager

src/Stack/ConfigCmd.hs

Lines changed: 85 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ module Stack.ConfigCmd
1717
,cfgCmdName) where
1818

1919
import Stack.Prelude
20-
import Data.Coerce (coerce)
2120
import qualified Data.Aeson.Key as Key
2221
import qualified Data.Aeson.KeyMap as KeyMap
23-
import Data.ByteString.Builder (byteString)
22+
import Data.Attoparsec.Text as P (Parser, parseOnly, skip, skipWhile,
23+
string, takeText, takeWhile)
2424
import qualified Data.Map.Merge.Strict as Map
2525
import qualified Data.Text as T
2626
import qualified Data.Yaml as Yaml
@@ -37,7 +37,6 @@ import Stack.Constants
3737
import Stack.Types.Config
3838
import Stack.Types.Resolver
3939
import System.Environment (getEnvironment)
40-
import Stack.YamlUpdate
4140

4241
data ConfigCmdSet
4342
= ConfigCmdSetResolver (Unresolved AbstractResolver)
@@ -73,29 +72,90 @@ cfgCmdSet cmd = do
7372
PCGlobalProject -> liftM (</> stackDotYaml) (getImplicitGlobalProjectDir conf)
7473
PCNoProject _extraDeps -> throwString "config command used when no project configuration available" -- maybe modify the ~/.stack/config.yaml file instead?
7574
CommandScopeGlobal -> return (configUserConfigPath conf)
76-
-- We don't need to worry about checking for a valid yaml here
77-
rawConfig <- mkRaw <$> liftIO (readFileUtf8 (toFilePath configFilePath))
78-
(config :: Yaml.Object) <- either throwM return (Yaml.decodeEither' . encodeUtf8 $ coerce rawConfig)
75+
rawConfig <- liftIO (readFileUtf8 (toFilePath configFilePath))
76+
config <- either throwM return (Yaml.decodeEither' $ encodeUtf8 rawConfig)
7977
newValue <- cfgCmdSetValue (parent configFilePath) cmd
80-
let cmdKey = cfgCmdSetOptionName cmd
81-
config' = KeyMap.insert (Key.fromText cmdKey) newValue config
82-
yamlKeys = Key.toText <$> KeyMap.keys config
83-
if config' == config
84-
then logInfo
85-
(fromString (toFilePath configFilePath) <>
86-
" already contained the intended configuration and remains \
87-
\unchanged.")
88-
else do
89-
let configLines = yamlLines rawConfig
90-
either
91-
throwM
92-
(\updated -> do
93-
let redressed = unmkRaw $ redress configLines updated
94-
writeBinaryFileAtomic configFilePath . byteString $ encodeUtf8 redressed
95-
96-
let file = fromString $ toFilePath configFilePath
97-
logInfo (file <> " has been updated."))
98-
(encodeInOrder configLines (coerce yamlKeys) (coerce cmdKey) config')
78+
let yamlLines = T.lines rawConfig
79+
cmdKey = cfgCmdSetOptionName cmd -- Text
80+
cmdKey' = Key.fromText cmdKey -- Data.Aeson.Key.Key
81+
newValue' = T.stripEnd $
82+
decodeUtf8With lenientDecode $ Yaml.encode newValue -- Text
83+
file = toFilePath configFilePath -- String
84+
file' = display $ T.pack file -- Utf8Builder
85+
newYamlLines <- case KeyMap.lookup cmdKey' config of
86+
Nothing -> do
87+
logInfo $ file' <> " has been extended."
88+
pure $ yamlLines <> [cmdKey <> ": " <> newValue']
89+
Just oldValue -> if oldValue == newValue
90+
then do
91+
logInfo $ file' <> " already contained the intended \
92+
\configuration and remains unchanged."
93+
pure yamlLines
94+
else switchLine file' cmdKey newValue' [] yamlLines
95+
liftIO $ writeFileUtf8 file (T.unlines newYamlLines)
96+
where
97+
switchLine file cmdKey _ searched [] = do
98+
logWarn $ display cmdKey <> " not found in YAML file " <> file <>
99+
" as a single line. Multi-line key:value formats are not supported."
100+
pure $ reverse searched
101+
switchLine file cmdKey newValue searched (oldLine:rest) =
102+
case parseOnly (parseLine cmdKey) oldLine of
103+
Left _ ->
104+
switchLine file cmdKey newValue (oldLine:searched) rest
105+
Right (kt, spaces1, spaces2, comment) -> do
106+
let newLine = renderKey cmdKey kt <> spaces1 <> ":" <>
107+
spaces2 <> newValue <> comment
108+
logInfo $ file <> " has been updated."
109+
pure $ reverse searched <> (newLine:rest)
110+
111+
-- This assumes that a top-level key will not be indented in the YAML file.
112+
parseLine :: Text -> Parser (KeyType, Text, Text, Text)
113+
parseLine key = do
114+
kt <- parseKey key
115+
spaces1 <- P.takeWhile (== ' ')
116+
skip (== ':')
117+
spaces2 <- P.takeWhile (== ' ')
118+
skipWhile (/= ' ')
119+
comment <- takeText
120+
pure (kt, spaces1, spaces2, comment)
121+
122+
-- If the key is, for example, install-ghc, this recognises install-ghc,
123+
-- 'install-ghc' or "install-ghc".
124+
parseKey :: Text -> Parser KeyType
125+
parseKey k = parsePlainKey k
126+
<|> parseSingleQuotedKey k
127+
<|> parseDoubleQuotedKey k
128+
129+
parsePlainKey :: Text -> Parser KeyType
130+
parsePlainKey key = do
131+
_ <- string key
132+
pure PlainKey
133+
134+
parseSingleQuotedKey :: Text -> Parser KeyType
135+
parseSingleQuotedKey = parseQuotedKey SingleQuotedKey '\''
136+
137+
parseDoubleQuotedKey :: Text -> Parser KeyType
138+
parseDoubleQuotedKey = parseQuotedKey DoubleQuotedKey '"'
139+
140+
parseQuotedKey :: KeyType -> Char -> Text -> Parser KeyType
141+
parseQuotedKey kt c key = do
142+
skip (==c)
143+
_ <- string key
144+
skip (==c)
145+
pure kt
146+
147+
renderKey :: Text -> KeyType -> Text
148+
renderKey key kt = case kt of
149+
PlainKey -> key
150+
SingleQuotedKey -> '\'' `T.cons` key `T.snoc` '\''
151+
DoubleQuotedKey -> '"' `T.cons` key `T.snoc` '"'
152+
153+
-- |Type representing types of representations of keys in YAML files.
154+
data KeyType
155+
= PlainKey -- ^ For example: install-ghc
156+
| SingleQuotedKey -- ^ For example: 'install-ghc'
157+
| DoubleQuotedKey -- ^ For example: "install-ghc"
158+
deriving (Eq, Show)
99159

100160
cfgCmdSetValue
101161
:: (HasConfig env, HasGHCVariant env)

src/Stack/Types/Config.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ data ConfigMonoid =
860860
-- ^ See 'configMonoidAllowNewer'
861861
,configMonoidDefaultTemplate :: !(First TemplateName)
862862
-- ^ The default template to use when none is specified.
863-
-- (If Nothing, the default is used.)
863+
-- (If Nothing, the 'default' default template is used.)
864864
, configMonoidAllowDifferentUser :: !(First Bool)
865865
-- ^ Allow users other than the stack root owner to use the stack
866866
-- installation.

0 commit comments

Comments
 (0)