Skip to content

Commit

Permalink
Basic UseVersion parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nddrylliog committed Feb 20, 2013
1 parent ea99866 commit a0982e5
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 51 deletions.
5 changes: 4 additions & 1 deletion source/rock/frontend/BuildParams.ooc
Expand Up @@ -5,7 +5,7 @@ import structs/[ArrayList, HashMap]
import text/StringTokenizer

// out stuff
import PathList, CommandLine
import PathList, CommandLine, Target
import drivers/CCompiler
import rock/middle/[Module, UseDef]
import rock/middle/tinker/Errors
Expand Down Expand Up @@ -214,6 +214,9 @@ BuildParams: class {
// backend
backend: String = "c"

// target
target := Target guessHost()

checkBinaryNameCollision: func (name: String) {
if (File new(name) dir?()) {
stderr write("Naming conflict (output binary) : There is already a directory called %s.\nTry a different name, e.g. '-o=%s2'\n" format(name, name))
Expand Down
4 changes: 3 additions & 1 deletion source/rock/frontend/drivers/AndroidDriver.ooc
Expand Up @@ -109,7 +109,9 @@ AndroidDriver: class extends Driver {

uze := UseDef parse(sourceFolder identifier, params)
if (uze) {
for (additional in uze additionals) {
props := uze getRelevantProperties(params)

for (additional in props additionals) {
cPath := File new(uze identifier, additional relative path) path

if (params verbose) {
Expand Down
3 changes: 2 additions & 1 deletion source/rock/frontend/drivers/Driver.ooc
Expand Up @@ -63,7 +63,8 @@ Driver: abstract class {
}
usesDone add(useDef)

for (additional in useDef additionals) {
props := useDef getRelevantProperties(params)
for (additional in props additionals) {
src := additional absolute

base := params libcachePath
Expand Down
10 changes: 8 additions & 2 deletions source/rock/frontend/drivers/MakeDriver.ooc
Expand Up @@ -174,7 +174,10 @@ MakeDriver: class extends SequenceDriver {
}

for (uze in uses) {
for (additional in uze additionals) {
// FIXME: that's no good for MakeDriver - we should write conditions instead
props := uze getRelevantProperties(params)

for (additional in props additionals) {
cPath := File new(File new(originalOutPath, uze identifier), additional relative) path
oPath := "%s.o" format(cPath[0..-3])

Expand Down Expand Up @@ -214,7 +217,10 @@ MakeDriver: class extends SequenceDriver {
}

for (uze in uses) {
for (additional in uze additionals) {
// FIXME: that's no good for MakeDriver - we should write conditions instead
props := uze getRelevantProperties(params)

for (additional in props additionals) {
cPath := File new(File new(originalOutPath, uze identifier), additional relative) path
oPath := "%s.o" format(cPath[0..-3])

Expand Down
3 changes: 2 additions & 1 deletion source/rock/frontend/drivers/SequenceDriver.ooc
Expand Up @@ -161,7 +161,8 @@ SequenceDriver: class extends Driver {

for (uze in flags uses) {
if (uze sourcePath && uze sourcePath == sourceFolder absolutePath) {
for (additional in uze additionals) {
props := uze getRelevantProperties(params)
for (additional in props additionals) {
buildAdditional(sourceFolder, uze, additional)
}
}
Expand Down
148 changes: 103 additions & 45 deletions source/rock/middle/UseDef.ooc
@@ -1,7 +1,7 @@

// sdk stuff
import io/[File, FileReader, StringReader]
import structs/[List, ArrayList, HashMap]
import structs/[List, ArrayList, HashMap, Stack]
import text/StringTokenizer

// our stuff
Expand Down Expand Up @@ -74,10 +74,12 @@ UseDef: class {
libPaths : ArrayList<String> { get set }
includePaths : ArrayList<String> { get set }
preMains : ArrayList<String> { get set }
additionals : ArrayList<Additional> { get set }
androidLibs : ArrayList<String> { get set }
androidIncludePaths : ArrayList<String> { get set }

versionBlocks := ArrayList<UseVersion> new()
stack := Stack<UseVersion> new()

init: func (=identifier) {
requirements = ArrayList<Requirement> new()
pkgs = ArrayList<String> new()
Expand All @@ -89,7 +91,6 @@ UseDef: class {
libPaths = ArrayList<String> new()
includePaths = ArrayList<String> new()
preMains = ArrayList<String> new()
additionals = ArrayList<Additional> new()
androidLibs = ArrayList<String> new()
androidIncludePaths = ArrayList<String> new()
}
Expand Down Expand Up @@ -207,75 +208,90 @@ UseDef: class {
read: func (=file, params: BuildParams) {
reader := FileReader new(file)
if(params veryVerbose) ("Reading use file " + file path) println()

stack push(UseVersion new())

while(reader hasNext?()) {
line := reader readLine() trim(8 as Char /* backspace */) trim(0 as Char /* null byte */)
line := reader readLine() \
trim() /* general whitespace */ \
trim(8 as Char /* backspace */) \
trim(0 as Char /* null byte */)

if(line empty?() || line startsWith?('#')) {
if (line empty?() || line startsWith?('#')) {
// skip comments
continue
}

lineReader := StringReader new(line)
if (line startsWith?("version")) {
lineReader readUntil('(')
versionExpr := lineReader readUntil(')')
"Got version expression: %s" printfln(versionExpr)
continue
}

if (line startsWith?("}")) {
"Version expression closed" println()
continue
}

id := lineReader readUntil(':')
value := lineReader readAll() trim()

"%s: %s" printfln(id, value)

if(id startsWith?("_")) {
if (id startsWith?("_")) {
// reserved ids for external tools (packaging, etc.)
continue
}

if(id == "Name") {
if (id == "Name") {
name = value
} else if(id == "Description") {
} else if (id == "Description") {
description = value
} else if(id == "Pkgs") {
for(pkg in value split(','))
} else if (id == "Pkgs") {
for (pkg in value split(','))
pkgs add(pkg trim())
} else if(id == "CustomPkg") {
} else if (id == "CustomPkg") {
customPkgs add(parseCustomPkg(value))
} else if(id == "Libs") {
for(lib in value split(','))
} else if (id == "Libs") {
for (lib in value split(','))
libs add(lib trim())
} else if(id == "Frameworks") {
for(framework in value split(','))
} else if (id == "Frameworks") {
for (framework in value split(','))
frameworks add(framework trim())
} else if(id == "Includes") {
for(inc in value split(','))
} else if (id == "Includes") {
for (inc in value split(','))
includes add(inc trim())
} else if(id == "PreMains") {
for(pm in value split(','))
} else if (id == "PreMains") {
for (pm in value split(','))
preMains add(pm trim())
} else if(id == "Linker") {
} else if (id == "Linker") {
linker = value trim()
} else if(id == "LibPaths") {
for(path in value split(',')) {
} else if (id == "LibPaths") {
for (path in value split(',')) {
libFile := File new(path trim())
if(libFile relative?()) {
if (libFile relative?()) {
libFile = file parent getChild(path) getAbsoluteFile()
}
libPaths add(libFile path)
}
} else if(id == "IncludePaths") {
for(path in value split(',')) {
} else if (id == "IncludePaths") {
for (path in value split(',')) {
incFile := File new(path trim())
if(incFile relative?()) {
if (incFile relative?()) {
incFile = file parent getChild(path) getAbsoluteFile()
}
includePaths add(incFile path)
}
} else if(id == "AndroidLibs") {
for(path in value split(',')) {
} else if (id == "AndroidLibs") {
for (path in value split(',')) {
androidLibs add(path trim())
}
} else if(id == "AndroidIncludePaths") {
for(path in value split(',')) {
} else if (id == "AndroidIncludePaths") {
for (path in value split(',')) {
androidIncludePaths add(path trim())
}
} else if(id == "Additionals") {
for(path in value split(',')) {
} else if (id == "Additionals") {
for (path in value split(',')) {
relative := File new(path trim()) getReducedFile()
absolute := file parent getChild(relative path) getAbsoluteFile()

Expand All @@ -288,29 +304,71 @@ UseDef: class {
"relative path: %s / %d" printfln(relative path, relative exists?())
"absolute path: %s / %d" printfln(absolute path, absolute exists?())
}
additionals add(Additional new(relative, absolute))
stack peek() properties additionals add(Additional new(relative, absolute))
}
} else if(id == "Requires") {
for(req in value split(',')) {
} else if (id == "Requires") {
for (req in value split(',')) {
// TODO: Version support!
requirements add(Requirement new(req trim(), "0"))
}
} else if(id == "SourcePath") {
} else if (id == "SourcePath") {
sourcePath = value
} else if(id == "Version") {
} else if (id == "Version") {
versionNumber = value
} else if(id == "Imports") {
for(imp in value split(','))
} else if (id == "Imports") {
for (imp in value split(','))
imports add(imp trim())
} else if(id == "Origin" || id == "Variant") {
} else if (id == "Origin" || id == "Variant") {
// known, but ignored ids
} else if(id == "Main") {
} else if (id == "Main") {
main = value
} else if(id startsWith?("_")) {
} else if (id startsWith?("_")) {
// unknown and ignored ids
} else if(!id empty?()) {
} else if (!id empty?()) {
"Unknown key in %s: %s" format(file getPath(), id) println()
}
}

reader close()
versionBlocks add(stack pop())
}

getRelevantProperties: func (params: BuildParams) -> UseProperties {
result := UseProperties new()

versionBlocks filter(|vb| vb satisfied?(params)) each(|vb|
result merge!(vb properties)
)
result
}
}

UseProperties: class {
additionals : ArrayList<Additional> { get set }

init: func {
additionals = ArrayList<Additional> new()
}

merge!: func (other: This) -> This {
additionals addAll(other additionals)
}
}

/**
* Versioned block in a use def file
*
* This one is always satisfied
*/
UseVersion: class {
properties: UseProperties { get set }

init: func {
properties = UseProperties new()
}

satisfied?: func (params: BuildParams) -> Bool {
true
}
}

0 comments on commit a0982e5

Please sign in to comment.