public
Description: Io programming language
Homepage: http://iolanguage.com
Clone URL: git://github.com/stevedekorte/io.git
Steve Dekorte (author)
Tue May 13 17:03:06 -0700 2008
commit  c7f2d7a7564662fa77c4b288dda0442b797e0e90
tree    e077101dc0613b3aa4b02fc710b268a468f448e2
parent  c7b4b4f67ec7938749c08c496d93ad96a11269ce
io / build / Project.io
100755 189 lines (163 sloc) 5.194 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
Project := Object clone do(
  cc := method(System getEnvironmentVariable("CC") ifNilEval(return "cc"))
  cxx := method(System getEnvironmentVariable("CXX") ifNilEval(return "g++"))
  platform := System platform split at(0) asLowercase
 
  systemCall := method(s,
    r := trySystemCall(s)
    if(r == 256, System exit(1))
    r
  )
 
  trySystemCall := method(s,
    result := System system("sh -c '" .. s .. "'")
    result
  )
 
  modulesInFolder := method(name,
    folder := Directory clone setPath(name)
    if(folder exists not, return List clone)
    subfolders := folder directories
    subfolders selectInPlace(fileNamedOrNil("build.io"))
    subfolders map(f,
      module := Lobby doString(f fileNamedOrNil("build.io") contents)
      module folder setPath(f path)
      module
    )
  )
 
  addons := method(
    self addons := modulesInFolder("addons") sortInPlaceBy(block(x, y, x name < y name))
  )
  
   buildAddon := method(name,
    currentAddon := addons detect(addon, addon name == name)
    if(currentAddon == nil,  Exception raise("No addon named " .. name .. " found!"))
    currentAddon build(options)
  )
 
  /*
  buildAddon := method(name,
    addons detect(addon, /*writeln(addon name);*/ addon name == name) build(options)
  )
  */
 
  availableAddon := method(addon,
    if(addon hasSlot("isAvailable"),
      //writeln(addon name, " isAvailable")
      return addon isAvailable
    )
    if(addon isDisabled,
      //writeln(addon name, " isDisabled")
      addon isAvailable := false
      return false
    )
    if(addon supportedOnPlatform(platform) not,
      error := (addon name .. " is not supported on " .. platform .. "\n") print
      File clone openForAppending("errors") write(error) close
      addon isAvailable := false
      return false
    )
    if(addon hasDepends not, return false)
    addon depends addons foreach(addonName,
      dependancy := addons detect(name == addonName)
      if(dependancy == nil,
        error := (addon name .. " is missing " .. addonName .. " addon\n") print
        File clone openForAppending("errors") write(error) close
        addon isAvailable := false
        return false
      )
      if(availableAddon(dependancy) not,
        error := (addon name .. " is missing " .. addonName .. " addon\n") print
        File clone openForAppending("errors") write(error) close
        addon isAvailable := false
        return false
      )
    )
    addon isAvailable := true
    true
  )
 
  availableAddons := method(
    addons selectInPlace(addon, availableAddon(addon))
  )
 
  options := method(
    if (platform == "windows",
      //"-MDd -Zi -DWIN32 -D_DEBUG -DIOBINDINGS -D_CRT_SECURE_NO_DEPRECATE"
      "-MD -Zi -DWIN32 -DNDEBUG -DIOBINDINGS -D_CRT_SECURE_NO_DEPRECATE"
    ,
      "-Os -g -Wall -pipe -fno-strict-aliasing -DSANE_POPEN -DIOBINDINGS"
    )
  )
 
  build := method(
    File clone with("errors") remove close
    buildAddons
    writeln("\n--- build complete ---\n")
  )
 
  orderedAddons := method(
    ordered := List clone
    dependencies := availableAddons clone
    while(0 < dependencies size,
      ordered = dependencies clone appendSeq(ordered) unique
      dependencies = dependencies map(depends addons map(a, addons detect(name == a))) flatten unique
    )
    ordered
  )
 
  buildAddons := method(
    writeln("\n--- building addons ---\n")
 
    orderedAddons foreach(build(options))
    self
  )
 
  libPaths := Directory with("libs") directories map(path)
 
  otherLibPaths := method(libtype,
    if(libtype == nil, libtype = "_build/dll")
    addons := availableAddons
    l := List clone
    l appendSeq(addons map(a, "-Laddons/" .. a name .. "/" .. libtype))
    l unique
  )
 
  includes := method(
    libPaths map(s, "-I" .. s .. "/_build/headers")
  )
 
  cleanAddons := method(
    writeln("--- Project cleanAddons ---")
    addons foreach(clean)
  )
 
  clean := method(
    writeln("--- Project clean ---")
    cleanAddons
    trySystemCall("rm -rf projects/*/build")
    trySystemCall("rm -f IoAddonsInit.*")
  )
 
  docs := method(
    writeln("--- Project generate docs from source file comments ---")
    systemCall("cd libs/iovm; ../../_build/binaries/io ../../tools/io/DocsExtractor.io .")
    //addons foreach(generateDocs)
    //build
    systemCall("_build/binaries/io tools/io/docs2html.io > docs/IoReference.html")
  )
 
  cleanDocs := method(
    writeln("--- Project clean embedded docs ---")
    systemCall("cd vm; make cleanDocs")
    addons foreach(cleanDocs)
  )
 
  runUnitTests := method(
    failures := 0
 
    maxNameSize := availableAddons max(name size) name size
    availableAddons foreach(addon,
      path := Path with(addon folder path, "tests/correctness/run.io")
      
      if(File clone setPath(path) exists,
        write(addon name alignLeft(maxNameSize), " - ")
        File standardOutput flush
        r := System system("./_build/binaries/io " .. path)
        if(r == 0, writeln("PASSED"), writeln("FAILED ", r, " TESTS"))
        failures = failures + r
      )
    )
    writeln("")
    if(failures == 0, writeln("ALL TESTS PASSED"), writeln("FAILED ", failures, " tests"))
    failures
  )
 
  installDependenciesFor := method(name,
    addons map(installCommands) map(at(name)) select(!=nil) foreach(c,
      c println
      System system(c)
    )
  )
 
  aptget := method(installDependenciesFor("aptget"))
  emerge := method(installDependenciesFor("emerge"))
  port := method(installDependenciesFor("port"))
  urpmi := method(installDependenciesFor("urpmi"))
)