Updating built in Io code to use += instead of x = x + y
[io/quag.git] / build / Project.io
blobda5c66e44cbd92e91032e868d610debf9f4aa4bc
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(options)
37 availableAddon := method(addon,
38 if(addon hasSlot("isAvailable"), return addon isAvailable)
39 if(addon isDisabled,
40 addon isAvailable := false
41 return false
43 if(addon supportedOnPlatform(platform) not,
44 error := (addon name .. " is not supported on " .. platform .. "\n") print
45 File clone openForAppending("errors") write(error) close
46 addon isAvailable := false
47 return false
49 if(addon hasDepends not, return false)
50 addon depends addons foreach(addonName,
51 dependancy := addons detect(name == addonName)
52 if(dependancy == nil,
53 error := (addon name .. " is missing " .. addonName .. " addon\n") print
54 File clone openForAppending("errors") write(error) close
55 addon isAvailable := false
56 return false
58 if(availableAddon(dependancy) not,
59 error := (addon name .. " is missing " .. addonName .. " addon\n") print
60 File clone openForAppending("errors") write(error) close
61 addon isAvailable := false
62 return false
65 addon isAvailable := true
66 true
69 availableAddons := method(
70 addons selectInPlace(addon, availableAddon(addon))
73 options := method(
74 if (platform == "windows",
75 "-MD -DWIN32 -DNDEBUG -DIOBINDINGS"
77 "-Os -g -Wall -DSANE_POPEN -DIOBINDINGS"
81 build := method(
82 File clone with("errors") remove close
83 buildAddons
84 writeln("\n--- build complete ---\n")
87 orderedAddons := method(
88 ordered := List clone
89 dependencies := availableAddons clone
90 while(0 < dependencies size,
91 ordered = dependencies clone appendSeq(ordered) unique
92 dependencies = dependencies map(depends addons map(a, addons detect(name == a))) flatten unique
94 ordered
97 buildAddons := method(
98 writeln("\n--- building addons ---\n")
100 orderedAddons foreach(build(options))
101 self
104 libPaths := Directory with("libs") folders map(path)
106 otherLibPaths := method(libtype,
107 if(libtype == nil, libtype = "_build/dll")
108 addons := availableAddons
109 l := List clone
110 l appendSeq(addons map(a, "-Laddons/" .. a name .. "/" .. libtype))
111 l unique
114 includes := method(
115 libPaths map(s, "-I" .. s .. "/_build/headers")
118 cleanAddons := method(
119 writeln("--- Project cleanAddons ---")
120 addons foreach(clean)
123 clean := method(
124 writeln("--- Project clean ---")
125 cleanAddons
126 trySystemCall("rm -rf projects/*/build")
127 trySystemCall("rm -f IoAddonsInit.*")
130 docs := method(
131 writeln("--- Project generate embedded docs ---")
132 systemCall("cd libs/iovm; ../../_build/binaries/io ../../tools/io/DocsExtractor.io .")
133 addons foreach(generateDocs)
136 cleanDocs := method(
137 writeln("--- Project clean embedded docs ---")
138 systemCall("cd vm; make cleanDocs")
139 addons foreach(cleanDocs)
142 runUnitTests := method(
143 failures := 0
145 availableAddons foreach(addon,
146 path := Path with(addon folder path, "tests/run.io")
147 if(File clone setPath(path) exists,
148 write(addon name alignLeft(10), " - ")
149 File standardOutput flush
150 r := System system("./_build/binaries/io " .. path)
151 if(r == 0, writeln("PASSED"), writeln("FAILED ", r, " TESTS"))
152 failures = failures + r
155 writeln("")
156 if(failures == 0, writeln("ALL TESTS PASSED"), writeln("FAILED ", failures, " tests"))
157 failures
160 installDependenciesFor := method(name,
161 addons map(installCommands) map(at(name)) select(!=nil) foreach(c,
162 c println
163 System system(c)
167 aptget := method(installDependenciesFor("aptget"))
168 emerge := method(installDependenciesFor("emerge"))
169 port := method(installDependenciesFor("port"))
170 urpmi := method(installDependenciesFor("urpmi"))