From aa9efa3aa1aea2362353e8f9ad508567796bf142 Mon Sep 17 00:00:00 2001 From: Judah Jacobson Date: Wed, 10 May 2017 16:29:31 -0700 Subject: [PATCH] Fix 'sdist' for tensorflow-core-ops. (#113) Use the same trick as for `proto-lens-protoc`: hack the package description during the `sdist` step to include the autogen directory in hs-source-dirs. --- tensorflow-core-ops/Setup.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tensorflow-core-ops/Setup.hs b/tensorflow-core-ops/Setup.hs index 449e6d0..6ab910b 100644 --- a/tensorflow-core-ops/Setup.hs +++ b/tensorflow-core-ops/Setup.hs @@ -15,6 +15,11 @@ -- | Generates the wrappers for Ops shipped with tensorflow. module Main where +import Distribution.PackageDescription + ( PackageDescription(..) + , libBuildInfo + , hsSourceDirs + ) import Distribution.Simple.BuildPaths (autogenModulesDir) import Distribution.Simple.LocalBuildInfo (LocalBuildInfo) import Distribution.Simple @@ -44,6 +49,11 @@ generatingOpsWrappers = hooks , haddockHook = \p l h f -> generateSources l >> haddockHook hooks p l h f , replHook = \p l h f args -> generateSources l >> replHook hooks p l h f args + , sDistHook = \p maybe_l h f -> case maybe_l of + Nothing -> error "Can't run sdist; run 'cabal configure first." + Just l -> do + generateSources l + sDistHook hooks (fudgePackageDesc l p) maybe_l h f } where flagsBuilder dir = OpGenFlags @@ -63,6 +73,20 @@ generatingOpsWrappers = hooks Right x -> Text.writeFile (outputFile flags) (prettyLazyText 80 $ docOpList flags x) +-- | Add the autogen directory to the hs-source-dirs of all the targets in the +-- .cabal file. Used to fool 'sdist' by pointing it to the generated source +-- files. +fudgePackageDesc + :: LocalBuildInfo -> PackageDescription -> PackageDescription +fudgePackageDesc lbi p = p + { library = + (\lib -> lib { libBuildInfo = fudgeBuildInfo (libBuildInfo lib) }) + <$> library p + } + where + fudgeBuildInfo bi = + bi { hsSourceDirs = autogenModulesDir lbi : hsSourceDirs bi } + blackList = [ -- Requires the "func" type: "SymbolicGradient"