--------------------------------------------------------------------------
-- Handling of Generic Package Descriptions

toGenericPackageDescription :: PackageDescription -> GenericPackageDescription
toGenericPackageDescription pd =
    GenericPackageDescription {
        packageDescription = pd{
            library = Nothing,
            executables = [],
            testSuites = [],
            benchmarks = [],
            buildDepends = []},
        genPackageFlags = [],
        condLibrary = case library pd of
                            Nothing -> Nothing
                            Just lib -> Just (buildCondTreeLibrary lib),
        condExecutables = map buildCondTreeExe (executables pd),
        condTestSuites =  map buildCondTreeTest (testSuites pd),
        condBenchmarks =  map buildCondTreeBenchmark (benchmarks pd)}
  where
    buildCondTreeLibrary lib =
        CondNode {
            condTreeData = lib { libBuildInfo = (libBuildInfo lib) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []}
    buildCondTreeExe exe =
        (exeName exe, CondNode {
            condTreeData = exe { buildInfo = (buildInfo exe) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []})
    buildCondTreeTest test =
        (testName test, CondNode {
            condTreeData = test { testBuildInfo = (testBuildInfo test) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []})
    buildCondTreeBenchmark bm =
        (benchmarkName bm, CondNode {
            condTreeData = bm { benchmarkBuildInfo = (benchmarkBuildInfo bm) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []})

-- ---------------------------------------------------------------------
-- The exported stuff goes here
--
toGenericPackageDescription :: PackageDescription -> GenericPackageDescription
toGenericPackageDescription pd =
    GenericPackageDescription {
        packageDescription = pd{
            library = Nothing,
            executables = [],
            testSuites = [],
            benchmarks = [],
            buildDepends = []},
        genPackageFlags = [],
        condLibrary = case library pd of
                            Nothing -> Nothing
                            Just lib -> Just (buildCondTreeLibrary lib),
        condExecutables = map buildCondTreeExe (executables pd),
        condTestSuites =  map buildCondTreeTest (testSuites pd),
        condBenchmarks =  map buildCondTreeBenchmark (benchmarks pd)}
  where
    buildCondTreeLibrary lib =
        CondNode {
            condTreeData = lib { libBuildInfo = (libBuildInfo lib) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []}
    buildCondTreeExe exe =
        (exeName exe, CondNode {
            condTreeData = exe { buildInfo = (buildInfo exe) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []})
    buildCondTreeTest test =
        (testName test, CondNode {
            condTreeData = test { testBuildInfo = (testBuildInfo test) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []})
    buildCondTreeBenchmark bm =
        (benchmarkName bm, CondNode {
            condTreeData = bm { benchmarkBuildInfo = (benchmarkBuildInfo bm) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []})

-- ---------------------------------------------------------------------
-- The exported stuff goes here
--
toGenericPackageDescription pd =
    GenericPackageDescription {
        packageDescription = pd{
            library = Nothing,
            executables = [],
            testSuites = [],
            benchmarks = [],
            buildDepends = []},
        genPackageFlags = [],
        condLibrary = case library pd of
                            Nothing -> Nothing
                            Just lib -> Just (buildCondTreeLibrary lib),
        condExecutables = map buildCondTreeExe (executables pd),
        condTestSuites =  map buildCondTreeTest (testSuites pd),
        condBenchmarks =  map buildCondTreeBenchmark (benchmarks pd)}
  where
    buildCondTreeLibrary lib =
        CondNode {
            condTreeData = lib { libBuildInfo = (libBuildInfo lib) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []}
    buildCondTreeExe exe =
        (exeName exe, CondNode {
            condTreeData = exe { buildInfo = (buildInfo exe) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []})
    buildCondTreeTest test =
        (testName test, CondNode {
            condTreeData = test { testBuildInfo = (testBuildInfo test) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []})
    buildCondTreeBenchmark bm =
        (benchmarkName bm, CondNode {
            condTreeData = bm { benchmarkBuildInfo = (benchmarkBuildInfo bm) { targetBuildDepends = buildDepends pd } },
            condTreeConstraints = buildDepends pd,
            condTreeComponents = []})

-- ---------------------------------------------------------------------
-- The exported stuff goes here
--