Skip to content

Commit 11716a6

Browse files
Replace full platform name and cabal version in build artifact path on Windows with first 8 symbols of its SHA1 hash. This is done to decrease chances of hitting 260 symbol path limit.
1 parent 4b06874 commit 11716a6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Stack/Constants.hs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE TemplateHaskell #-}
23
{-# LANGUAGE OverloadedStrings #-}
34

@@ -47,6 +48,13 @@ import Prelude
4748
import Stack.Types.Config
4849
import Stack.Types.PackageIdentifier
4950
import Stack.Types.PackageName
51+
#ifdef mingw32_HOST_OS
52+
import qualified Crypto.Hash.SHA1 as SHA1
53+
import qualified Data.ByteString as B
54+
import qualified Data.ByteString.Base16 as Base16
55+
import qualified Data.ByteString.Char8 as B8
56+
import qualified Data.Text.Encoding as T
57+
#endif
5058

5159
-- | Extensions for anything that can be a Haskell module.
5260
haskellModuleExts :: [Text]
@@ -205,11 +213,22 @@ distRelativeDir = do
205213
parseRelDir $
206214
packageIdentifierString
207215
(PackageIdentifier cabalPackageName cabalPkgVer)
216+
217+
#ifdef mingw32_HOST_OS
218+
-- This is an attempt to shorten path to stack build artifacts dir on Windows to
219+
-- decrease our chances of hitting 260 symbol path limit.
220+
-- The idea is to calculate SHA1 hash from concatenated platform and cabal strings,
221+
-- encode with base 16 and take first 8 symbols of it.
222+
let concatenatedText = T.pack . toFilePath $ platform </> cabal
223+
sha1 = SHA1.hash $ T.encodeUtf8 concatenatedText
224+
platformAndCabal <- parseRelDir . B8.unpack . B.take 8 $ Base16.encode sha1
225+
#else
226+
let platformAndCabal = platform </> cabal
227+
#endif
208228
return $
209229
workDirRel </>
210230
$(mkRelDir "dist") </>
211-
platform </>
212-
cabal
231+
platformAndCabal
213232

214233
-- | Get a URL for a raw file on Github
215234
rawGithubUrl :: Text -- ^ user/org name

0 commit comments

Comments
 (0)