summaryrefslogtreecommitdiff
path: root/libraries/ghc-boot
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2019-06-20 18:04:30 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-07-09 22:56:18 -0400
commit24782b89907ab36fb5aef3a17584f4c10f1e2690 (patch)
treeb0d55f9b146f33fc901aa10b166a647aeded0c0e /libraries/ghc-boot
parent0472f0f6a92395d478e9644c0dbd12948518099f (diff)
downloadhaskell-24782b89907ab36fb5aef3a17584f4c10f1e2690.tar.gz
Deduplicate "unique subdir" code between GHC and Cabal
The code, including the generated module with the version, is now in ghc-boot. Config.hs reexports stuff as needed, ghc-pkg doesn't need any tricks at all.
Diffstat (limited to 'libraries/ghc-boot')
-rw-r--r--libraries/ghc-boot/GHC/UniqueSubdir.hs32
-rw-r--r--libraries/ghc-boot/ghc-boot.cabal.in6
-rw-r--r--libraries/ghc-boot/ghc.mk36
3 files changed, 74 insertions, 0 deletions
diff --git a/libraries/ghc-boot/GHC/UniqueSubdir.hs b/libraries/ghc-boot/GHC/UniqueSubdir.hs
new file mode 100644
index 0000000000..49ae05e526
--- /dev/null
+++ b/libraries/ghc-boot/GHC/UniqueSubdir.hs
@@ -0,0 +1,32 @@
+module GHC.UniqueSubdir
+ ( uniqueSubdir
+ , uniqueSubdir0
+ ) where
+
+import Prelude -- See Note [Why do we import Prelude here?]
+
+import Data.List (intercalate)
+
+import GHC.Platform
+import GHC.Version (cProjectVersion)
+
+-- | A filepath like @x86_64-linux-7.6.3@ with the platform string to use when
+-- constructing platform-version-dependent files that need to co-exist.
+--
+uniqueSubdir :: Platform -> FilePath
+uniqueSubdir platform = uniqueSubdir0
+ (stringEncodeArch $ platformArch platform)
+ (stringEncodeOS $ platformOS platform)
+
+-- | 'ghc-pkg' falls back on the host platform if the settings file is missing,
+-- and so needs this since we don't have information about the host platform in
+-- as much detail as 'Platform'.
+uniqueSubdir0 :: String -> String -> FilePath
+uniqueSubdir0 arch os = intercalate "-"
+ [ arch
+ , os
+ , cProjectVersion
+ ]
+ -- NB: This functionality is reimplemented in Cabal, so if you
+ -- change it, be sure to update Cabal.
+ -- TODO make Cabal use this now that it is in ghc-boot.
diff --git a/libraries/ghc-boot/ghc-boot.cabal.in b/libraries/ghc-boot/ghc-boot.cabal.in
index 650f7518dc..aed75b0c8a 100644
--- a/libraries/ghc-boot/ghc-boot.cabal.in
+++ b/libraries/ghc-boot/ghc-boot.cabal.in
@@ -45,6 +45,12 @@ Library
GHC.HandleEncoding
GHC.Platform
GHC.Settings
+ GHC.UniqueSubdir
+ GHC.Version
+
+ -- but done by Hadrian
+ -- autogen-modules:
+ -- GHC.Version
build-depends: base >= 4.7 && < 4.14,
binary == 0.8.*,
diff --git a/libraries/ghc-boot/ghc.mk b/libraries/ghc-boot/ghc.mk
new file mode 100644
index 0000000000..29c5376560
--- /dev/null
+++ b/libraries/ghc-boot/ghc.mk
@@ -0,0 +1,36 @@
+libraries/ghc-boot_PACKAGE = ghc-boot
+libraries/ghc-boot_dist-install_GROUP = libraries
+$(if $(filter ghc-boot,$(PACKAGES_STAGE0)),$(eval $(call build-package,libraries/ghc-boot,dist-boot,0)))
+$(if $(filter ghc-boot,$(PACKAGES_STAGE1)),$(eval $(call build-package,libraries/ghc-boot,dist-install,1)))
+$(if $(filter ghc-boot,$(PACKAGES_STAGE2)),$(eval $(call build-package,libraries/ghc-boot,dist-install,2)))
+
+libraries/ghc-boot/dist-boot/build/GHC/Version.hs \
+libraries/ghc-boot/dist-install/build/GHC/Version.hs: mk/project.mk | $$(dir $$@)/.
+ $(call removeFiles,$@)
+ @echo "module GHC.Version where" >> $@
+ @echo >> $@
+ @echo 'import Prelude -- See Note [Why do we import Prelude here?]' >> $@
+ @echo >> $@
+ @echo 'cProjectGitCommitId :: String' >> $@
+ @echo 'cProjectGitCommitId = "$(ProjectGitCommitId)"' >> $@
+ @echo >> $@
+ @echo 'cProjectVersion :: String' >> $@
+ @echo 'cProjectVersion = "$(ProjectVersion)"' >> $@
+ @echo >> $@
+ @echo 'cProjectVersionInt :: String' >> $@
+ @echo 'cProjectVersionInt = "$(ProjectVersionInt)"' >> $@
+ @echo >> $@
+ @echo 'cProjectPatchLevel :: String' >> $@
+ @echo 'cProjectPatchLevel = "$(ProjectPatchLevel)"' >> $@
+ @echo >> $@
+ @echo 'cProjectPatchLevel1 :: String' >> $@
+ @echo 'cProjectPatchLevel1 = "$(ProjectPatchLevel1)"' >> $@
+ @echo >> $@
+ @echo 'cProjectPatchLevel2 :: String' >> $@
+ @echo 'cProjectPatchLevel2 = "$(ProjectPatchLevel2)"' >> $@
+ @echo done.
+
+libraries/ghc-boot/dist-boot/package-data.mk: \
+ libraries/ghc-boot/dist-boot/build/GHC/Version.hs
+libraries/ghc-boot/dist-install/package-data.mk: \
+ libraries/ghc-boot/dist-install/build/GHC/Version.hs