Skip to content

Commit

Permalink
Replace full platform name and cabal version in build artifact path o…
Browse files Browse the repository at this point in the history
…n Windows with first 8 symbols of its SHA1 hash. This is done to decrease chances of hitting 260 symbol path limit.
  • Loading branch information
anton-dessiatov committed Sep 22, 2015
1 parent 4b06874 commit 11716a6
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Stack/Constants.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}

Expand Down Expand Up @@ -47,6 +48,13 @@ import Prelude
import Stack.Types.Config
import Stack.Types.PackageIdentifier
import Stack.Types.PackageName
#ifdef mingw32_HOST_OS
import qualified Crypto.Hash.SHA1 as SHA1
import qualified Data.ByteString as B
import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Char8 as B8
import qualified Data.Text.Encoding as T
#endif

-- | Extensions for anything that can be a Haskell module.
haskellModuleExts :: [Text]
Expand Down Expand Up @@ -205,11 +213,22 @@ distRelativeDir = do
parseRelDir $
packageIdentifierString
(PackageIdentifier cabalPackageName cabalPkgVer)

#ifdef mingw32_HOST_OS
-- This is an attempt to shorten path to stack build artifacts dir on Windows to
-- decrease our chances of hitting 260 symbol path limit.
-- The idea is to calculate SHA1 hash from concatenated platform and cabal strings,
-- encode with base 16 and take first 8 symbols of it.
let concatenatedText = T.pack . toFilePath $ platform </> cabal
sha1 = SHA1.hash $ T.encodeUtf8 concatenatedText
platformAndCabal <- parseRelDir . B8.unpack . B.take 8 $ Base16.encode sha1
#else
let platformAndCabal = platform </> cabal
#endif
return $
workDirRel </>
$(mkRelDir "dist") </>
platform </>
cabal
platformAndCabal

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

0 comments on commit 11716a6

Please sign in to comment.