Fixing bug in relativeDoFile (and making it a clone of doRelativeFile, until we decid...
[io/quag.git] / build / Project.io
blob4e240b0af6791991e6ac8642018c41c9413a2df9
1 Project := Object clone do(
2 cc := method(System getenv("CC") ifNilEval(return "cc"))
3 cxx := method(System getenv("CXX") ifNilEval(return "g++"))
4 platform := System platform split at(0) asLowercase
6 systemCall := method(s,
7 r := trySystemCall(s)
8 if(r == 256, System exit(1))
12 trySystemCall := method(s,
13 result := System system("sh -c '" .. s .. "'")
14 result
17 modulesInFolder := method(name,
18 folder := Directory clone setPath(name)
19 if(folder exists not, return List clone)
20 subfolders := folder folders
21 subfolders selectInPlace(fileNamedOrNil("build.io"))
22 subfolders map(f,
23 module := Lobby doString(f fileNamedOrNil("build.io") contents)
24 module folder setPath(f path)
25 module
29 addons := method(
30 self addons := modulesInFolder("addons") sortInPlaceBy(block(x, y, x name < y name))
33 buildAddon := method(name,
34 addons detect(addon, addon name == name) build
37 availableAddon := method(addon,
38 if(addon hasSlot("isAvailable"), return addon isAvailable)
39 if(addon supportedOnPlatform(platform) not,
40 error := (addon name .. " is not supported on " .. platform .. "\n") print
41 File clone openForAppending("errors") write(error) close
42 addon isAvailable := false
43 return false
45 if(addon hasDepends not, return false)
46 addon depends addons foreach(addonName,
47 dependancy := addons detect(name == addonName)
48 if(dependancy == nil,
49 error := (addon name .. " is missing " .. addonName .. " addon\n") print
50 File clone openForAppending("errors") write(error) close
51 addon isAvailable := false
52 return false
54 if(availableAddon(dependancy) not,
55 error := (addon name .. " is missing " .. addonName .. " addon\n") print
56 File clone openForAppending("errors") write(error) close
57 addon isAvailable := false
58 return false
61 addon isAvailable := true
62 true
65 availableAddons := method(
66 addons selectInPlace(addon, availableAddon(addon))
69 options := method(
70 if (platform == "windows",
71 "-MDd -DWIN32 -D_DEBUG -DIOBINDINGS"
73 "-Os -g -Wall -DSANE_POPEN -DIOBINDINGS"
77 build := method(
78 File clone with("errors") remove close
79 buildAddons
80 writeln("\n--- build complete ---\n")
83 orderedAddons := method(
84 ordered := List clone
85 dependencies := availableAddons clone
86 while(0 < dependencies size,
87 ordered = dependencies clone appendSeq(ordered) unique
88 dependencies = dependencies map(depends addons map(a, addons detect(name == a))) flatten unique
90 ordered
93 buildAddons := method(
94 writeln("\n--- building addons ---\n")
96 orderedAddons foreach(build(options))
97 self
100 libPaths := Directory with("libs") folders map(path)
102 otherLibPaths := method(libtype,
103 if(libtype == nil, libtype = "_build/dll")
104 addons := availableAddons
105 l := List clone
106 l appendSeq(addons map(a, "-Laddons/" .. a name .. "/" .. libtype))
107 l unique
110 includes := method(
111 libPaths map(s, "-I" .. s .. "/_build/headers")
114 cleanAddons := method(
115 writeln("--- Project cleanAddons ---")
116 addons foreach(clean)
119 clean := method(
120 writeln("--- Project clean ---")
121 cleanAddons
122 trySystemCall("rm -rf projects/*/build")
123 trySystemCall("rm -f IoAddonsInit.*")
126 docs := method(
127 writeln("--- Project generate embedded docs ---")
128 systemCall("cd libs/iovm; ../../_build/binaries/io ../../tools/io/DocsExtractor.io .")
129 addons foreach(generateDocs)
132 cleanDocs := method(
133 writeln("--- Project clean embedded docs ---")
134 systemCall("cd vm; make cleanDocs")
135 addons foreach(cleanDocs)
138 runUnitTests := method(
139 failures := 0
141 availableAddons foreach(addon,
142 path := Path with(addon folder path, "tests/run.io")
143 if(File clone setPath(path) exists,
144 write(addon name alignLeft(10), " - ")
145 File standardOutput flush
146 r := System system("./_build/binaries/io " .. path)
147 if(r == 0, writeln("PASSED"), writeln("FAILED ", r, " TESTS"))
148 failures = failures + r
151 writeln("")
152 if(failures == 0, writeln("ALL TESTS PASSED"), writeln("FAILED ", failures, " tests"))
153 failures
156 installDependenciesFor := method(name,
157 addons map(installCommands) map(at(name)) select(!=nil) foreach(c,
158 c println
159 System system(c)
163 aptget := method(installDependenciesFor("aptget"))
164 emerge := method(installDependenciesFor("emerge"))
165 port := method(installDependenciesFor("port"))
166 urpmi := method(installDependenciesFor("urpmi"))