Avoid the need to rerun configure when we install
authorIan Lynagh <igloo@earth.li>
Fri, 18 May 2007 15:20:17 +0000 (15:20 +0000)
committerIan Lynagh <igloo@earth.li>
Fri, 18 May 2007 15:20:17 +0000 (15:20 +0000)
This also means we don't need to carry around 10s of megs of Setup
executables in bindists.

libraries/Makefile
libraries/installPackage.hs [new file with mode: 0644]

index 919bb69..c133e1a 100644 (file)
@@ -100,7 +100,8 @@ subdirs:
 .PHONY: boot
 
 boot: $(BOOTSTRAPPING_STAMPS) ifBuildable/ifBuildable \
-         $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup)
+         $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
+         installPackage/installPackage
 
 # We build the Setup program in a setup subdirectory to stop it trying
 # to use bits of base and Cabal when we build those packages.
@@ -117,6 +118,14 @@ $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
                              -i../../bootstrapping.filepath \
                              -Wall -cpp --make Setup.*hs -o Setup
 
+installPackage/installPackage: installPackage.hs $(BOOTSTRAPPING_STAMPS)
+       -$(RM) -rf installPackage
+       mkdir installPackage
+       $(CP) installPackage.hs installPackage/
+       cd installPackage && $(GHC) -Wall --make installPackage -o installPackage \
+                             -i../bootstrapping.Cabal \
+                             -i../bootstrapping.filepath
+
 ifBuildable/ifBuildable: ifBuildable.hs
        -$(RM) -rf ifBuildable
        mkdir ifBuildable
@@ -139,6 +148,7 @@ all: doc
 endif
 
 build: $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR))
+build: installPackage/installPackage
 
 configure: $(foreach SUBDIR,$(SUBDIRS), \
              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
@@ -210,37 +220,26 @@ install-docs:
 # Ideally this would depend on a stamp/build.library.%, but if it does
 # then we can't change the libraries and then just rerun make.
 # Thus if you install without building then it will just break.
-$(foreach SUBDIR,$(SUBDIRS),stamp/configure.library.install.$(SUBDIR)): \
-stamp/configure.library.install.%: %/setup/Setup ifBuildable/ifBuildable
-       -$(RM) -f stamp/configure.library.*.$*
-       ifBuildable/ifBuildable $* setup/Setup configure \
-                                           $(CONFIGURE_OPTS) \
-                                           --prefix=$(prefix) \
-                                           --with-compiler=$(bindir)/ghc \
-                                           --datasubdir=ghc
-       touch $@
-
-# We need to reconfigure as we now need to register with the normal ghc-pkg
 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
-install.library.%: stamp/configure.library.install.% \
-                   %/setup/Setup ifBuildable/ifBuildable
-       ifBuildable/ifBuildable $* setup/Setup install
+install.library.%: installPackage/installPackage ifBuildable/ifBuildable
+       ifBuildable/ifBuildable $* ../installPackage/installPackage
 
 .PHONY: binary-dist binary-dist.library.%
 
 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
 
 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
-       cp    Makefile           $(BIN_DIST_LIBDIR)
-       cp    gen_contents_index $(BIN_DIST_LIBDIR)
-       cp    index.html         $(BIN_DIST_LIBDIR)
-       cp    doc-index.html     $(BIN_DIST_LIBDIR)
-       cp -a stamp              $(BIN_DIST_LIBDIR)
+       mkdir                               $(BIN_DIST_LIBDIR)/installPackage
+       cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
+       cp    Makefile                      $(BIN_DIST_LIBDIR)
+       cp    gen_contents_index            $(BIN_DIST_LIBDIR)
+       cp    index.html                    $(BIN_DIST_LIBDIR)
+       cp    doc-index.html                $(BIN_DIST_LIBDIR)
+       cp -a stamp                         $(BIN_DIST_LIBDIR)
 
 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
 binary-dist.library.%:
-       $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*/setup
-       ifBuildable/ifBuildable $* cp    setup/Setup   $(BIN_DIST_LIBDIR)/$*/setup
+       $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*
        ifBuildable/ifBuildable $* cp    $*.cabal      $(BIN_DIST_LIBDIR)/$*
        ifBuildable/ifBuildable $* cp -a dist          $(BIN_DIST_LIBDIR)/$*
        ifBuildable/ifBuildable $* $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
diff --git a/libraries/installPackage.hs b/libraries/installPackage.hs
new file mode 100644 (file)
index 0000000..dcba287
--- /dev/null
@@ -0,0 +1,60 @@
+
+import Distribution.PackageDescription
+import Distribution.Setup
+import Distribution.Simple
+import Distribution.Simple.Configure
+import Distribution.Simple.LocalBuildInfo
+import Distribution.Simple.Utils
+import Distribution.Verbosity
+import System.Environment
+
+main :: IO ()
+main = do args <- getArgs
+          let verbosity = case args of
+                              [] -> normal
+                              ['-':'v':v] ->
+                                  let m = case v of
+                                              "" -> Nothing
+                                              _ -> Just v
+                                  in flagToVerbosity m
+                              _ -> error ("Bad arguments: " ++ show args)
+              userHooks = simpleUserHooks
+              installFlags = InstallFlags {
+                                 installUserFlags = MaybeUserGlobal,
+                                 installVerbose = verbosity
+                             }
+          pdFile <- defaultPackageDesc verbosity
+          pd <- readPackageDescription verbosity pdFile
+          lbi <- getPersistBuildConfig
+          let -- XXX This is an almighty hack, shadowing the base Setup.hs hack
+              lib' = case library pd of
+                         Just lib ->
+                             lib {
+                                 exposedModules = filter (("GHC.Prim" /=))
+                                                $ exposedModules lib
+                                 }
+                         Nothing ->
+                             error "Expected a library, but none found"
+              pd' = pd { library = Just lib' }
+              -- When installing we need to use the non-inplace ghc-pkg.
+              -- We also set the compiler to be non-inplace, but that
+              -- probably doesn't matter.
+              c = compiler lbi
+              c' = c { compilerPath = dropInPlace (compilerPath c),
+                       compilerPkgTool = dropInPlace (compilerPkgTool c)
+                     }
+              lbi' = lbi { compiler = c' }
+          (instHook simpleUserHooks) pd' lbi' userHooks installFlags
+
+dropInPlace :: FilePath -> FilePath
+dropInPlace "" = ""
+dropInPlace xs@(x:xs') = case dropPrefix "-inplace" xs of
+                             Nothing -> x : dropInPlace xs'
+                             Just xs'' -> dropInPlace xs''
+
+dropPrefix :: Eq a => [a] -> [a] -> Maybe [a]
+dropPrefix [] ys = Just ys
+dropPrefix (x:xs) (y:ys)
+ | x == y = dropPrefix xs ys
+dropPrefix _ _ = Nothing
+