BatchBuild.icl 3 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
1
2
module BatchBuild

3
import StdEnv
4
import StdListExtensions
Diederik van Arkel's avatar
Diederik van Arkel committed
5
6
7
8
import ArgEnv
import PmDriver
import PmProject
import IdeState
9
from UtilIO import GetFullApplicationPath,GetLongPathName
Diederik van Arkel's avatar
Diederik van Arkel committed
10
import PmEnvironment, logfile, set_return_code
11
from Platform import application_path
12
import ParserCombinators
Diederik van Arkel's avatar
Diederik van Arkel committed
13

14
15
16
17

:: BBArgs =
  {  force_rebuild  :: Bool
  ,  proj_path      :: Maybe String
18
  ,  envsdir        :: Maybe String }
19
20

Start :: *World -> *World
Diederik van Arkel's avatar
Diederik van Arkel committed
21
Start world
22
23
24
    # commandline				= getCommandLine
      cl						= intersperse " " (tl [arg \\ arg <-: commandline])
      args                      = concat [fromString c \\ c <- cl]
25
26
      {force_rebuild=force_rebuild, proj_path=proj_path, envsdir=envsdir} = startPBB args
    | isNothing proj_path		= wAbort ("BatchBuild\nUse as: 'BatchBuild [--force] projectname.prj [envsdir]'\n") world
27
    # (startup,world)			= accFiles GetFullApplicationPath world
28
29
30
31
    # envsdir					= case envsdir of
                                    Nothing   -> application_path EnvsFileName
                                    (Just p)  -> application_path p
    # (envs,world)				= openEnvironments startup envsdir world // TODO: This is where we need to insert the .env file
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    # ((proj,ok,err),world)		= accFiles (ReadProjectFile (fromJust proj_path) startup) world
    | not ok || err <> ""		= wAbort ("BatchBuild failed while opening project: "+++.err+++."\n") world
    # (ok,logfile,world)		= openLogfile (fromJust proj_path) world
    | not ok					= wAbort ("BatchBuild failed while opening logfile.\n") world
    # default_compiler_options	= DefaultCompilerOptions
    # iniGeneral				= initGeneral True default_compiler_options startup (fromJust proj_path) proj envs logfile
    # ps = {ls=iniGeneral,gst_world=world,gst_continue_or_stop=False}
    # {ls,gst_world} = pinit force_rebuild ps
    = finish gst_world

concat :: [[.a]] -> [.a]
concat xss = foldr (++) [] xss

startPBB :: [.Char] -> BBArgs
startPBB args =  case filter (\(xs, _) -> xs == []) (begin pBB args) of
47
                   []         -> {force_rebuild = False, proj_path = Nothing, envsdir = Nothing }
48
49
50
                   [(_, as)]  -> as

pBB :: CParser Char BBArgs BBArgs
51
pBB = pForce <&> \f -> pFilename <&> \p -> pFilename <@ \e -> {force_rebuild = f, proj_path = p, envsdir = e}
52
53
54
55

pForce :: CParser Char Bool BBArgs
pForce = (sptoken (fromString "--force") <@ const True) <!> yield False

56
pFilename :: CParser Char (Maybe String) BBArgs
57
pFilename = (sp (<+> (satisfy (not o isWhite))) <@ Just o toString) <!> yield Nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
58

59
pinit :: .Bool *GeneralSt -> *GeneralSt
John van Groningen's avatar
John van Groningen committed
60
61
pinit force_rebuild ps
	= BringProjectUptoDate force_rebuild cleanup ps
Diederik van Arkel's avatar
Diederik van Arkel committed
62
63
64
65
where
	cleanup exepath bool1 bool2 ps
		= abortLog False "" ps

66
wAbort :: {#.Char} *World -> .World
Diederik van Arkel's avatar
Diederik van Arkel committed
67
68
69
70
71
72
73
74
75
76
77
wAbort message world
//	# (console,world) = stdio world
//	# console = console <<< message
//	# (_,world) = fclose console world
	# stderr		= fwrites message stderr
	# (ok,world)	= fclose stderr world
	# world			= set_return_code_world (-1) world
	= finish world

//finish :: !*World -> String
//finish _ = ""
78
79
finish :: .a -> .a
finish w = w