aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap')
-rw-r--r--bootstrap/src/BuildModel.hs21
-rw-r--r--bootstrap/unit_test/ModuleToCompileInfoTest.hs70
-rw-r--r--bootstrap/unit_test/ProgramToCompileInfoTest.hs8
3 files changed, 91 insertions, 8 deletions
diff --git a/bootstrap/src/BuildModel.hs b/bootstrap/src/BuildModel.hs
index f4c809f..c6e422b 100644
--- a/bootstrap/src/BuildModel.hs
+++ b/bootstrap/src/BuildModel.hs
@@ -94,15 +94,28 @@ processRawSource rawSource =
else undefined
constructCompileTimeInfo :: Source -> [String] -> FilePath -> CompileTimeInfo
-constructCompileTimeInfo program@(Program{}) availableModules buildDirectory =
+constructCompileTimeInfo p@(Program{}) availableModules buildDirectory =
CompileTimeInfo
- { compileTimeInfoSourceFileName = programSourceFileName program
- , compileTimeInfoObjectFileProduced = (programObjectFileName program)
+ { compileTimeInfoSourceFileName = programSourceFileName p
+ , compileTimeInfoObjectFileProduced = (programObjectFileName p)
buildDirectory
, compileTimeInfoOtherFilesProduced = []
, compileTimeInfoDirectDependencies = map
(\mName -> buildDirectory </> mName <.> "mod")
- (filter (`elem` availableModules) (programModulesUsed program))
+ (filter (`elem` availableModules) (programModulesUsed p))
+ }
+constructCompileTimeInfo m@(Module{}) availableModules buildDirectory =
+ CompileTimeInfo
+ { compileTimeInfoSourceFileName = moduleSourceFileName m
+ , compileTimeInfoObjectFileProduced = (moduleObjectFileName m)
+ buildDirectory
+ , compileTimeInfoOtherFilesProduced =
+ (buildDirectory </> moduleName m <.> "mod") : if moduleProducesSmod m
+ then [buildDirectory </> moduleName m <.> "smod"]
+ else []
+ , compileTimeInfoDirectDependencies = map
+ (\mName -> buildDirectory </> mName <.> "mod")
+ (filter (`elem` availableModules) (moduleModulesUsed m))
}
constructCompileTimeInfo _ otherSources buildDirectory = undefined
diff --git a/bootstrap/unit_test/ModuleToCompileInfoTest.hs b/bootstrap/unit_test/ModuleToCompileInfoTest.hs
new file mode 100644
index 0000000..5a1f0a8
--- /dev/null
+++ b/bootstrap/unit_test/ModuleToCompileInfoTest.hs
@@ -0,0 +1,70 @@
+module ModuleToCompileInfoTest
+ ( 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 module and available modules"
+ (exampleModule, availableModules)
+ [ whenTransformed
+ "its compileTimeInfo is determined"
+ doCompileTimeTransformation
+ [ then' "it stil knows the original source file" checkSourceFileName
+ , then' "it knows what object file will be produced" checkObjectFileName
+ , then' "the mod and smod files are also produced" checkOtherFilesProduced
+ , then' "the direct dependencies are only the available modules used"
+ checkDirectDependencies
+ ]
+ ]
+
+exampleModule :: Source
+exampleModule = Module
+ { moduleSourceFileName = moduleSourceFileName'
+ , moduleObjectFileName = \bd -> bd </> "some_file_somewhere.f90.o"
+ , moduleModulesUsed = ["module1", "module2", "module3"]
+ , moduleName = "some_module"
+ , moduleProducesSmod = True
+ }
+
+moduleSourceFileName' :: FilePath
+moduleSourceFileName' = "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 moduleSourceFileName' (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" </> "some_module.mod", "build_dir" </> "some_module.smod"]
+ (compileTimeInfoOtherFilesProduced cti)
+
+checkDirectDependencies :: CompileTimeInfo -> Result
+checkDirectDependencies cti = assertEquals
+ ["build_dir" </> "module1.mod", "build_dir" </> "module3.mod"]
+ (compileTimeInfoDirectDependencies cti)
diff --git a/bootstrap/unit_test/ProgramToCompileInfoTest.hs b/bootstrap/unit_test/ProgramToCompileInfoTest.hs
index 20d7131..f17a3df 100644
--- a/bootstrap/unit_test/ProgramToCompileInfoTest.hs
+++ b/bootstrap/unit_test/ProgramToCompileInfoTest.hs
@@ -3,8 +3,8 @@ module ProgramToCompileInfoTest
)
where
-import BuildModel ( Source(..)
- , CompileTimeInfo(..)
+import BuildModel ( CompileTimeInfo(..)
+ , Source(..)
, constructCompileTimeInfo
)
import Hedge ( Result
@@ -19,7 +19,7 @@ import System.FilePath ( (</>) )
test :: IO (Test ())
test = return $ givenInput
- "a program and other sources"
+ "a program and available modules"
(exampleProgram, availableModules)
[ whenTransformed
"its compileTimeInfo is determined"
@@ -39,7 +39,7 @@ exampleProgram = Program
, programModulesUsed = ["module1", "module2", "module3"]
}
-programSourceFileName' :: String
+programSourceFileName' :: FilePath
programSourceFileName' = "some" </> "file" </> "somewhere.f90"
availableModules :: [String]