diff options
author | Brad Richardson <everythingfunctional@protonmail.com> | 2020-12-05 00:08:12 -0600 |
---|---|---|
committer | Brad Richardson <everythingfunctional@protonmail.com> | 2020-12-05 00:08:12 -0600 |
commit | d16cbbf604171092cb4eb5549d275966196f0b8d (patch) | |
tree | be5f01c0e5bf1468bc381aea02d9bf90da8ab7c4 /bootstrap | |
parent | 7d320295c6fe56cc767b352bd26f0466aa29ac5c (diff) | |
download | fpm-d16cbbf604171092cb4eb5549d275966196f0b8d.tar.gz fpm-d16cbbf604171092cb4eb5549d275966196f0b8d.zip |
fix(hfpm): dependence on library mod files
Diffstat (limited to 'bootstrap')
-rw-r--r-- | bootstrap/src/Build.hs | 16 | ||||
-rw-r--r-- | bootstrap/src/BuildModel.hs | 30 | ||||
-rw-r--r-- | bootstrap/unit_test/ModuleToCompileInfoTest.hs | 11 | ||||
-rw-r--r-- | bootstrap/unit_test/ProgramToCompileInfoTest.hs | 11 | ||||
-rw-r--r-- | bootstrap/unit_test/SubmoduleToCompileInfoTest.hs | 11 |
5 files changed, 53 insertions, 26 deletions
diff --git a/bootstrap/src/Build.hs b/bootstrap/src/Build.hs index e4f9992..32d1979 100644 --- a/bootstrap/src/Build.hs +++ b/bootstrap/src/Build.hs @@ -7,7 +7,8 @@ module Build ) where -import BuildModel ( CompileTimeInfo(..) +import BuildModel ( AvailableModule(..) + , CompileTimeInfo(..) , RawSource(..) , Source(..) , constructCompileTimeInfo @@ -45,6 +46,7 @@ import Development.Shake.FilePath ( exe , (<.>) ) import System.Environment ( setEnv ) +import System.FilePath ( takeBaseName ) import System.Process ( system ) import System.Directory ( createDirectoryIfMissing , makeAbsolute @@ -70,6 +72,7 @@ buildProgram -> IO () buildProgram programDirectory' libraryDirectories sourceExtensions buildDirectory' (CompilerSettings { compilerSettingsCompiler = compiler, compilerSettingsFlags = flags, compilerSettingsModuleFlag = moduleFlag, compilerSettingsIncludeFlag = includeFlag }) programName programSource archives = do + libraryModules <- findAvailableModules libraryDirectories let programDirectory = foldl1 (</>) (splitDirectories programDirectory') let buildDirectory = foldl1 (</>) (splitDirectories buildDirectory') let includeFlags = map (includeFlag ++) libraryDirectories @@ -80,7 +83,7 @@ buildProgram programDirectory' libraryDirectories sourceExtensions buildDirector programSourceFileName p == programDirectory </> programSource isThisProgramOrNotProgram _ = True let sources = filter isThisProgramOrNotProgram sources' - let availableModules = getAvailableModules sources + let availableModules = (getAvailableModules sources buildDirectory) ++ libraryModules let compileTimeInfo = map (\s -> constructCompileTimeInfo s availableModules buildDirectory) sources @@ -126,11 +129,12 @@ buildLibrary -> IO (FilePath) buildLibrary libraryDirectory sourceExtensions buildDirectory (CompilerSettings { compilerSettingsCompiler = compiler, compilerSettingsFlags = flags, compilerSettingsModuleFlag = moduleFlag, compilerSettingsIncludeFlag = includeFlag }) libraryName otherLibraryDirectories = do + otherModules <- findAvailableModules otherLibraryDirectories let includeFlags = map (includeFlag ++) otherLibraryDirectories sourceFiles <- getDirectoriesFiles [libraryDirectory] sourceExtensions rawSources <- mapM sourceFileToRawSource sourceFiles let sources = map processRawSource rawSources - let availableModules = getAvailableModules sources + let availableModules = (getAvailableModules sources buildDirectory) ++ otherModules let compileTimeInfo = map (\s -> constructCompileTimeInfo s availableModules buildDirectory) sources @@ -227,3 +231,9 @@ removeDriveLetter path | ':' `elem` path = (tail . dropWhile (/= ':')) path changeSeparators :: String -> String changeSeparators = replace "\\" "/" + +findAvailableModules :: [FilePath] -> IO [AvailableModule] +findAvailableModules directories = do + moduleFiles <- getDirectoriesFiles directories ["*.mod"] + let availableModules = map (\mf -> AvailableModule { availableModuleName = takeBaseName mf, availableModuleFile = mf }) moduleFiles + return availableModules diff --git a/bootstrap/src/BuildModel.hs b/bootstrap/src/BuildModel.hs index 95d3cac..4ca5959 100644 --- a/bootstrap/src/BuildModel.hs +++ b/bootstrap/src/BuildModel.hs @@ -68,6 +68,11 @@ data CompileTimeInfo = CompileTimeInfo { , compileTimeInfoDirectDependencies :: [FilePath] } +data AvailableModule = AvailableModule { + availableModuleName :: String + , availableModuleFile :: FilePath +} + processRawSource :: RawSource -> Source processRawSource rawSource = let @@ -102,11 +107,14 @@ processRawSource rawSource = } else undefined -getAvailableModules :: [Source] -> [String] -getAvailableModules = mapMaybe maybeModuleName +getAvailableModules :: [Source] -> FilePath -> [AvailableModule] +getAvailableModules sources buildDirectory = mapMaybe maybeModule sources where - maybeModuleName m@(Module{}) = Just $ moduleName m - maybeModuleName _ = Nothing + maybeModule m@(Module{}) = + let mName = moduleName m + modFile = buildDirectory </> mName <.> "mod" + in Just $ AvailableModule { availableModuleName = mName, availableModuleFile = modFile } + maybeModule _ = Nothing getAllObjectFiles :: FilePath -> [Source] -> [FilePath] getAllObjectFiles buildDirectory sources = map getObjectFile sources @@ -120,7 +128,7 @@ getSourceFileName p@(Program{} ) = programSourceFileName p getSourceFileName m@(Module{} ) = moduleSourceFileName m getSourceFileName s@(Submodule{}) = submoduleSourceFileName s -constructCompileTimeInfo :: Source -> [String] -> FilePath -> CompileTimeInfo +constructCompileTimeInfo :: Source -> [AvailableModule] -> FilePath -> CompileTimeInfo constructCompileTimeInfo p@(Program{}) availableModules buildDirectory = CompileTimeInfo { compileTimeInfoSourceFileName = programSourceFileName p @@ -128,8 +136,8 @@ constructCompileTimeInfo p@(Program{}) availableModules buildDirectory = buildDirectory , compileTimeInfoOtherFilesProduced = [] , compileTimeInfoDirectDependencies = map - (\mName -> buildDirectory </> mName <.> "mod") - (filter (`elem` availableModules) (programModulesUsed p)) + (\am -> availableModuleFile am) + (filter (\am -> (availableModuleName am) `elem` (programModulesUsed p)) availableModules) } constructCompileTimeInfo m@(Module{}) availableModules buildDirectory = CompileTimeInfo @@ -141,8 +149,8 @@ constructCompileTimeInfo m@(Module{}) availableModules buildDirectory = then [buildDirectory </> moduleName m <.> "smod"] else [] , compileTimeInfoDirectDependencies = map - (\mName -> buildDirectory </> mName <.> "mod") - (filter (`elem` availableModules) (moduleModulesUsed m)) + (\am -> availableModuleFile am) + (filter (\am -> (availableModuleName am) `elem` (moduleModulesUsed m)) availableModules) } constructCompileTimeInfo s@(Submodule{}) availableModules buildDirectory = CompileTimeInfo @@ -157,8 +165,8 @@ constructCompileTimeInfo s@(Submodule{}) availableModules buildDirectory = ] , compileTimeInfoDirectDependencies = (buildDirectory </> submoduleParentName s <.> "smod") - : (map (\mName -> buildDirectory </> mName <.> "mod") - (filter (`elem` availableModules) (submoduleModulesUsed s)) + : (map (\am -> availableModuleFile am) + (filter (\am -> (availableModuleName am) `elem` (submoduleModulesUsed s)) availableModules) ) } diff --git a/bootstrap/unit_test/ModuleToCompileInfoTest.hs b/bootstrap/unit_test/ModuleToCompileInfoTest.hs index 5a1f0a8..08cd67c 100644 --- a/bootstrap/unit_test/ModuleToCompileInfoTest.hs +++ b/bootstrap/unit_test/ModuleToCompileInfoTest.hs @@ -3,7 +3,8 @@ module ModuleToCompileInfoTest ) where -import BuildModel ( CompileTimeInfo(..) +import BuildModel ( AvailableModule(..) + , CompileTimeInfo(..) , Source(..) , constructCompileTimeInfo ) @@ -43,10 +44,12 @@ exampleModule = Module moduleSourceFileName' :: FilePath moduleSourceFileName' = "some" </> "file" </> "somewhere.f90" -availableModules :: [String] -availableModules = ["module1", "module3"] +availableModules :: [AvailableModule] +availableModules = [ AvailableModule {availableModuleName = "module1", availableModuleFile = "build_dir" </> "module1.mod"} + , AvailableModule {availableModuleName = "module3", availableModuleFile = "build_dir" </> "module3.mod"} + ] -doCompileTimeTransformation :: (Source, [String]) -> CompileTimeInfo +doCompileTimeTransformation :: (Source, [AvailableModule]) -> CompileTimeInfo doCompileTimeTransformation (programSource, otherSources) = constructCompileTimeInfo programSource otherSources "build_dir" diff --git a/bootstrap/unit_test/ProgramToCompileInfoTest.hs b/bootstrap/unit_test/ProgramToCompileInfoTest.hs index f17a3df..a9ad39b 100644 --- a/bootstrap/unit_test/ProgramToCompileInfoTest.hs +++ b/bootstrap/unit_test/ProgramToCompileInfoTest.hs @@ -3,7 +3,8 @@ module ProgramToCompileInfoTest ) where -import BuildModel ( CompileTimeInfo(..) +import BuildModel ( AvailableModule(..) + , CompileTimeInfo(..) , Source(..) , constructCompileTimeInfo ) @@ -42,10 +43,12 @@ exampleProgram = Program programSourceFileName' :: FilePath programSourceFileName' = "some" </> "file" </> "somewhere.f90" -availableModules :: [String] -availableModules = ["module1", "module3"] +availableModules :: [AvailableModule] +availableModules = [ AvailableModule {availableModuleName = "module1", availableModuleFile = "build_dir" </> "module1.mod"} + , AvailableModule {availableModuleName = "module3", availableModuleFile = "build_dir" </> "module3.mod"} + ] -doCompileTimeTransformation :: (Source, [String]) -> CompileTimeInfo +doCompileTimeTransformation :: (Source, [AvailableModule]) -> CompileTimeInfo doCompileTimeTransformation (programSource, otherSources) = constructCompileTimeInfo programSource otherSources "build_dir" diff --git a/bootstrap/unit_test/SubmoduleToCompileInfoTest.hs b/bootstrap/unit_test/SubmoduleToCompileInfoTest.hs index d5d3ad8..621b0d5 100644 --- a/bootstrap/unit_test/SubmoduleToCompileInfoTest.hs +++ b/bootstrap/unit_test/SubmoduleToCompileInfoTest.hs @@ -3,7 +3,8 @@ module SubmoduleToCompileInfoTest ) where -import BuildModel ( CompileTimeInfo(..) +import BuildModel ( AvailableModule(..) + , CompileTimeInfo(..) , Source(..) , constructCompileTimeInfo ) @@ -45,10 +46,12 @@ exampleSubmodule = Submodule submoduleSourceFileName' :: FilePath submoduleSourceFileName' = "some" </> "file" </> "somewhere.f90" -availableModules :: [String] -availableModules = ["module1", "module3"] +availableModules :: [AvailableModule] +availableModules = [ AvailableModule {availableModuleName = "module1", availableModuleFile = "build_dir" </> "module1.mod"} + , AvailableModule {availableModuleName = "module3", availableModuleFile = "build_dir" </> "module3.mod"} + ] -doCompileTimeTransformation :: (Source, [String]) -> CompileTimeInfo +doCompileTimeTransformation :: (Source, [AvailableModule]) -> CompileTimeInfo doCompileTimeTransformation (programSource, otherSources) = constructCompileTimeInfo programSource otherSources "build_dir" |