Skip to content

Commit aa9efa3

Browse files
authored
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.
1 parent 64971c8 commit aa9efa3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tensorflow-core-ops/Setup.hs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
-- | Generates the wrappers for Ops shipped with tensorflow.
1616
module Main where
1717

18+
import Distribution.PackageDescription
19+
( PackageDescription(..)
20+
, libBuildInfo
21+
, hsSourceDirs
22+
)
1823
import Distribution.Simple.BuildPaths (autogenModulesDir)
1924
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo)
2025
import Distribution.Simple
@@ -44,6 +49,11 @@ generatingOpsWrappers = hooks
4449
, haddockHook = \p l h f -> generateSources l >> haddockHook hooks p l h f
4550
, replHook = \p l h f args -> generateSources l
4651
>> replHook hooks p l h f args
52+
, sDistHook = \p maybe_l h f -> case maybe_l of
53+
Nothing -> error "Can't run sdist; run 'cabal configure first."
54+
Just l -> do
55+
generateSources l
56+
sDistHook hooks (fudgePackageDesc l p) maybe_l h f
4757
}
4858
where
4959
flagsBuilder dir = OpGenFlags
@@ -63,6 +73,20 @@ generatingOpsWrappers = hooks
6373
Right x -> Text.writeFile (outputFile flags)
6474
(prettyLazyText 80 $ docOpList flags x)
6575

76+
-- | Add the autogen directory to the hs-source-dirs of all the targets in the
77+
-- .cabal file. Used to fool 'sdist' by pointing it to the generated source
78+
-- files.
79+
fudgePackageDesc
80+
:: LocalBuildInfo -> PackageDescription -> PackageDescription
81+
fudgePackageDesc lbi p = p
82+
{ library =
83+
(\lib -> lib { libBuildInfo = fudgeBuildInfo (libBuildInfo lib) })
84+
<$> library p
85+
}
86+
where
87+
fudgeBuildInfo bi =
88+
bi { hsSourceDirs = autogenModulesDir lbi : hsSourceDirs bi }
89+
6690
blackList =
6791
[ -- Requires the "func" type:
6892
"SymbolicGradient"

0 commit comments

Comments
 (0)