Skip to content

Commit

Permalink
Support 'CustomPkg' in .use files. Closes #492
Browse files Browse the repository at this point in the history
  • Loading branch information
Amos Wenger committed Dec 1, 2012
1 parent a095c35 commit 181b493
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
16 changes: 14 additions & 2 deletions source/rock/frontend/drivers/Driver.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ Driver: abstract class {

flagsDone addAll(useDef getLibs())

for(pkg in useDef getPkgs()) {
info := PkgConfigFrontend getInfo(pkg)
applyInfo := func (info: PkgInfo) {
for(cflag in info cflags) {
if(!flagsDone contains?(cflag)) {
flagsDone add(cflag)
Expand All @@ -119,6 +118,19 @@ Driver: abstract class {
}
}

for(pkg in useDef getPkgs()) {
info := PkgConfigFrontend getInfo(pkg)
applyInfo(info)
}

for(pkg in useDef getCustomPkgs()) {
info := PkgConfigFrontend getCustomInfo(
pkg utilName, pkg names,
pkg cflagArgs, pkg libsArgs
)
applyInfo(info)
}

for(includePath in useDef getIncludePaths()) {
ipath := "-I" + includePath
if(!flagsDone contains?(ipath)) {
Expand Down
37 changes: 24 additions & 13 deletions source/rock/frontend/pkgconfig/PkgConfigFrontend.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,33 @@ PkgConfigFrontend: class {
cflagArgs: ArrayList<String>, libsArgs: ArrayList<String>) -> PkgInfo {
utilPath := ShellUtils findExecutable(utilName, true) getPath()

cflagslist := [utilPath] as ArrayList<String>
cflagslist addAll(pkgs)
cflagslist addAll(cflagArgs)
cflags := _shell(cflagslist)
cflags := ""

for (cflagArg in cflagArgs) {
cflagslist := [utilPath] as ArrayList<String>
cflagslist addAll(pkgs)
cflagslist add(cflagArg)
result := _shell(cflagslist)
if(!cflags) {
Exception new("Error while running `%s`" format(cflagslist join(" "))) throw()
}

if(cflags == null) {
Exception new("Error while running `%s`" format(cflagslist join(" "))) throw()
cflags += result
cflags += " "
}

libslist := [utilPath] as ArrayList<String>
libslist addAll(pkgs)
libslist addAll(libsArgs)
libs := _shell(libslist)

if(libs == null) {
Exception new("Error while running `%s`" format(libslist join(" "))) throw()
libs := ""

for (libsArg in libsArgs) {
libslist := [utilPath] as ArrayList<String>
libslist addAll(pkgs)
libslist add(libsArg)
result := _shell(libslist)
if(result == null) {
Exception new("Error while running `%s`" format(libslist join(" "))) throw()
}
libs += result
libs += " "
}

PkgInfo new(pkgs join(" "), libs, cflags)
Expand Down
1 change: 1 addition & 0 deletions source/rock/frontend/pkgconfig/PkgInfo.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ PkgInfo: class {
init: func (=name, =libsString, =cflagsString) {
extractTokens("-L", libsString, libPaths)
extractTokens("-l", libsString, libraries)
"For %s, collected libraries: %s" printfln(name, libraries join(", "))
extractTokens("-I", cflagsString, includePaths)
extractTokens("", cflagsString, cflags)
}
Expand Down
7 changes: 4 additions & 3 deletions source/rock/middle/UseDef.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,16 @@ UseDef: class {
parseCustomPkg: func (value: String) -> CustomPkg {
vals := value split(',')
pkg := CustomPkg new(vals[0])
pkg names addAll(vals[1] split(' '))
pkg names addAll(vals[1] trim() split(' '))
if (vals size >= 4) {
pkg cflagArgs addAll(vals[2] split(' '))
pkg libsArgs addAll(vals[3] split(' '))
pkg cflagArgs addAll(vals[2] trim() split(' '))
pkg libsArgs addAll(vals[3] trim() split(' '))
} else {
// If 3rd and 4th argument aren't present, assume pkgconfig-like behavior
pkg cflagArgs add("--cflags")
pkg libsArgs add("--libs")
}
pkg
}

read: func (=file, params: BuildParams) {
Expand Down

0 comments on commit 181b493

Please sign in to comment.