aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bootstrap/src/BuildModel.hs18
-rw-r--r--bootstrap/unit_test/SubmoduleToCompileInfoTest.hs74
2 files changed, 91 insertions, 1 deletions
diff --git a/bootstrap/src/BuildModel.hs b/bootstrap/src/BuildModel.hs
index b8fc537..dfbab72 100644
--- a/bootstrap/src/BuildModel.hs
+++ b/bootstrap/src/BuildModel.hs
@@ -120,7 +120,23 @@ constructCompileTimeInfo m@(Module{}) availableModules buildDirectory =
(\mName -> buildDirectory </> mName <.> "mod")
(filter (`elem` availableModules) (moduleModulesUsed m))
}
-constructCompileTimeInfo _ otherSources buildDirectory = undefined
+constructCompileTimeInfo s@(Submodule{}) availableModules buildDirectory =
+ CompileTimeInfo
+ { compileTimeInfoSourceFileName = submoduleSourceFileName s
+ , compileTimeInfoObjectFileProduced = (submoduleObjectFileName s)
+ buildDirectory
+ , compileTimeInfoOtherFilesProduced = [ buildDirectory
+ </> submoduleParentName s
+ ++ "@"
+ ++ submoduleName s
+ <.> "smod"
+ ]
+ , compileTimeInfoDirectDependencies =
+ (buildDirectory </> submoduleParentName s <.> "smod")
+ : (map (\mName -> buildDirectory </> mName <.> "mod")
+ (filter (`elem` availableModules) (submoduleModulesUsed s))
+ )
+ }
pathSeparatorsToUnderscores :: FilePath -> FilePath
pathSeparatorsToUnderscores fileName =
diff --git a/bootstrap/unit_test/SubmoduleToCompileInfoTest.hs b/bootstrap/unit_test/SubmoduleToCompileInfoTest.hs
new file mode 100644
index 0000000..4b3f474
--- /dev/null
+++ b/bootstrap/unit_test/SubmoduleToCompileInfoTest.hs
@@ -0,0 +1,74 @@
+module SubmoduleToCompileInfoTest
+ ( test
+ )
+where
+
+import BuildModel ( CompileTimeInfo(..)
+ , Source(..)
+ , constructCompileTimeInfo
+ )
+import Hedge ( Result
+ , Test
+ , assertEquals
+ , givenInput
+ , then'
+ , whenTransformed
+ )
+import System.FilePath ( (</>) )
+
+test :: IO (Test ())
+test = return $ givenInput
+ "a submodule and available modules"
+ (exampleSubmodule, availableModules)
+ [ whenTransformed
+ "its compileTimeInfo is determined"
+ doCompileTimeTransformation
+ [ then' "it still knows the original source file" checkSourceFileName
+ , then' "it knows what object file will be produced" checkObjectFileName
+ , then' "the smod file is also produced" checkOtherFilesProduced
+ , then'
+ "the direct dependencies are the parent smod and the available modules used"
+ checkDirectDependencies
+ ]
+ ]
+
+exampleSubmodule :: Source
+exampleSubmodule = Submodule
+ { submoduleSourceFileName = submoduleSourceFileName'
+ , submoduleObjectFileName = \bd -> bd </> "some_file_somewhere.f90.o"
+ , submoduleModulesUsed = ["module1", "module2", "module3"]
+ , submoduleParentName = "base_module@parent"
+ , submoduleName = "some_submodule"
+ }
+
+submoduleSourceFileName' :: FilePath
+submoduleSourceFileName' = "some" </> "file" </> "somewhere.f90"
+
+availableModules :: [String]
+availableModules = ["module1", "module3"]
+
+doCompileTimeTransformation :: (Source, [String]) -> CompileTimeInfo
+doCompileTimeTransformation (programSource, otherSources) =
+ constructCompileTimeInfo programSource otherSources "build_dir"
+
+checkSourceFileName :: CompileTimeInfo -> Result
+checkSourceFileName cti =
+ assertEquals submoduleSourceFileName' (compileTimeInfoSourceFileName cti)
+
+checkObjectFileName :: CompileTimeInfo -> Result
+checkObjectFileName cti = assertEquals
+ ("build_dir" </> "some_file_somewhere.f90.o")
+ (compileTimeInfoObjectFileProduced cti)
+
+checkOtherFilesProduced :: CompileTimeInfo -> Result
+checkOtherFilesProduced cti = assertEquals
+ ["build_dir" </> "base_module@parent@some_submodule.smod"]
+ (compileTimeInfoOtherFilesProduced cti)
+
+checkDirectDependencies :: CompileTimeInfo -> Result
+checkDirectDependencies cti = assertEquals
+ [ "build_dir" </> "base_module@parent.smod"
+ , "build_dir" </> "module1.mod"
+ , "build_dir" </> "module3.mod"
+ ]
+ (compileTimeInfoDirectDependencies cti)