diff --git a/Distribution/PackageDescription.hs b/Distribution/PackageDescription.hs index 438dad8e0fd6af95e79cbb09d9e331df9abbfa67..c2b335c6bbb5b93dbb317921c80cc4ad9307db2d 100644 --- a/Distribution/PackageDescription.hs +++ b/Distribution/PackageDescription.hs @@ -134,7 +134,8 @@ data PackageDescription -- components library :: Maybe Library, executables :: [Executable], - otherFiles :: [FilePath] + extraSrcFiles :: [FilePath], + extraTmpFiles :: [FilePath] } deriving (Show, Read, Eq) @@ -165,7 +166,8 @@ emptyPackageDescription category = "", library = Nothing, executables = [], - otherFiles = [] + extraSrcFiles = [], + extraTmpFiles = [] } -- |Get all the module names from the libraries in this package @@ -371,8 +373,10 @@ basicStanzaFields = , listField "tested-with" showTestedWith parseTestedWithQ testedWith (\val pkg -> pkg{testedWith=val}) - , listField "other-files" showFilePath parseFilePathQ - otherFiles (\val pkg -> pkg{otherFiles=val}) + , listField "extra-source-files" showFilePath parseFilePathQ + extraSrcFiles (\val pkg -> pkg{extraSrcFiles=val}) + , listField "extra-tmp-files" showFilePath parseFilePathQ + extraTmpFiles (\val pkg -> pkg{extraTmpFiles=val}) ] executableStanzaFields :: [StanzaField Executable] @@ -682,7 +686,7 @@ testPkgDesc = unlines [ "Build-Depends: haskell-src, HUnit>=1.0.0-rain", "Other-Modules: Distribution.Package, Distribution.Version,", " Distribution.Simple.GHCPackageConfig", - "Other-Files: file1, file2", + "Extra-Source-Files: file1, file2", "C-Sources: not/even/rain.c, such/small/hands", "HS-Source-Dirs: src, src2", "Exposed-Modules: Distribution.Void, Foo.Bar", @@ -720,7 +724,7 @@ testPkgDescAnswer = synopsis = "a nice package!", description = "a really nice package!", category = "tools", - otherFiles=["file1", "file2"], + extraSrcFiles=["file1", "file2"], buildDepends = [Dependency "haskell-src" AnyVersion, Dependency "HUnit" (UnionVersionRanges (ThisVersion (Version [1,0,0] ["rain"])) diff --git a/Distribution/Simple.hs b/Distribution/Simple.hs index 7a5a67a408ace6347f2726a4ca270bdd4b2dccef..098eaee9278900279bb39a72a9205bf6f4a6243d 100644 --- a/Distribution/Simple.hs +++ b/Distribution/Simple.hs @@ -89,7 +89,7 @@ import Language.Haskell.Extension -- Base import System.Environment(getArgs) import System.Exit(ExitCode(..), exitWith) -import System.Directory(removeFile, doesFileExist) +import System.Directory(removeFile, doesFileExist, doesDirectoryExist) import Distribution.License import Control.Monad(when, unless) @@ -411,6 +411,7 @@ clean pkg_descr lbi verbose pps = do case compilerFlavor (compiler lbi) of GHC -> cleanGHCExtras _ -> return () + mapM_ removeFileOrDirectory (extraTmpFiles pkg_descr) where cleanGHCExtras = do -- remove source stubs for library @@ -428,6 +429,13 @@ clean pkg_descr lbi verbose pps = do s <- sequence [moduleToFilePath dirs (x ++"_stub") ["h", "c"] | x <- mods ] mapM_ removeFile (concat s) + removeFileOrDirectory :: FilePath -> IO () + removeFileOrDirectory fname = do + isDir <- doesDirectoryExist fname + isFile <- doesFileExist fname + if isDir then removeDirectoryRecursive fname + else if isFile then removeFile fname + else return () no_extra_flags :: [String] -> IO () no_extra_flags [] = return () diff --git a/Distribution/Simple/SrcDist.hs b/Distribution/Simple/SrcDist.hs index 6a5764a2af3a4a1dd1af587e279cf42c29260927..d82b022e6996f2049bdbbd812511bf18613b4ba0 100644 --- a/Distribution/Simple/SrcDist.hs +++ b/Distribution/Simple/SrcDist.hs @@ -103,7 +103,7 @@ sdist tmpDir targetPref verbose snapshot pps pkg_descr_orig = do copyFileTo verbose targetDir srcMainFile when (not (null (licenseFile pkg_descr))) $ copyFileTo verbose targetDir (licenseFile pkg_descr) - flip mapM_ (otherFiles pkg_descr) $ \ fpath -> do + flip mapM_ (extraSrcFiles pkg_descr) $ \ fpath -> do copyFileTo verbose targetDir fpath -- setup isn't listed in the description file. hsExists <- doesFileExist "Setup.hs" diff --git a/doc/Cabal.xml b/doc/Cabal.xml index cbd14538390e178a9825146204b1dc79a2fd025d..cdd970d52620b61a11a242bf99f26aaf8b25fd6f 100644 --- a/doc/Cabal.xml +++ b/doc/Cabal.xml @@ -502,7 +502,7 @@ Other-Modules: A, C, Utils</programlisting> <varlistentry> <term> - <literal>other-files:</literal> + <literal>extra-source-files:</literal> <replaceable>filename list</replaceable> </term> <listitem> @@ -511,6 +511,21 @@ Other-Modules: A, C, Utils</programlisting> (see <xref linkend="setup-sdist"/>).</para> </listitem> </varlistentry> + + <varlistentry> + <term> + <literal>extra-tmp-files:</literal> + <replaceable>filename list</replaceable> + </term> + <listitem> + <para>A list of additional files or directories to be + removed by <command>setup clean</command> + (see <xref linkend="setup-clean"/>). + These would typically be additional files created by + additional hooks, such as the scheme described in + <xref linkend="system-dependent"/>.</para> + </listitem> + </varlistentry> </variablelist> </sect3> @@ -933,8 +948,12 @@ ld-options: -L/usr/X11R6/lib</programlisting> additional files such as <filename>configure</filename>, templates for <literal>.buildinfo</literal> files, files named only in <literal>.buildinfo</literal> files, header files and - so on in the <literal>other-files</literal> field, to ensure - that they are included in source distributions.</para> + so on in the <literal>extra-source-files</literal> field, + to ensure that they are included in source distributions. + They should also list files and directories generated by + <command>configure</command> in the + <literal>extra-tmp-files</literal> field to ensure that they + are removed by <command>setup clean</command>.</para> </note> </sect2> @@ -1416,12 +1435,14 @@ runhaskell Setup.hs unregister --gen-script</screen> </variablelist> </sect2> - <sect2> + <sect2 id="setup-clean"> <title>setup clean</title> <para>Remove any local files created during the <literal>configure</literal>, <literal>build</literal>, <literal>haddock</literal>, <literal>register</literal> or - <literal>unregister</literal> steps.</para> + <literal>unregister</literal> steps, and also any files and + directories listed in the <literal>extra-tmp-files</literal> + field.</para> </sect2> <sect2 id="setup-test"> @@ -1448,7 +1469,7 @@ runhaskell Setup.hs unregister --gen-script</screen> description file, the setup script, the sources of the modules named in the package description file, and files named in the <literal>license-file</literal>, <literal>main-is</literal>, - <literal>c-sources</literal> and <literal>other-files</literal> + <literal>c-sources</literal> and <literal>extra-source-files</literal> fields.</para> <para>This command takes the following option:</para>