Skip to content

Commit

Permalink
qmake: system_quote and shell_quote support. fix shell_path
Browse files Browse the repository at this point in the history
TODO: some special chars can not convert. How to avoid converting
multiple
times
  • Loading branch information
wang-bin committed Apr 21, 2013
1 parent 6ebfec7 commit bd399a5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
58 changes: 44 additions & 14 deletions common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 134,15 @@ defineTest(empty_file) {
lessThan(QT_MAJOR_VERSION, 5): {

defineTest(log){
system(echo $$1)
system(echo $$system_quote($$1))
}

defineTest(mkpath) {
win32 {
#why always return false?
system("md $$system_path($$1) 2>nul")|return(false)
} else {
log("mkdir -p $$shell_path($$1)")
#log("mkdir -p $$shell_path($$1)")
#why msys failed?
system("mkdir -p $$shell_path($$1)")|return(false)
}
Expand All @@ -162,7 162,7 @@ defineTest(write_file) {
empty_file($$1)
}
for(val, $$2) {
system("echo $$val >> \"$$1\"")|return(false)
system("echo $$system_quote($$val) >> \"$$1\"")|return(false)
}
return(true)
}
Expand Down Expand Up @@ -196,32 196,62 @@ defineReplace(shadowed) {

defineReplace(shell_path) {
# QMAKE_DIR_SEP: \ for win cmd and / for sh
return($$replace(1, /, $$QMAKE_DIR_SEP))
1 ~= s,\\\\,$$QMAKE_DIR_SEP,g
1 ~= s,//,$$QMAKE_DIR_SEP,g
return($$1)
}

##TODO: see qmake/library/ioutils.cpp
defineReplace(shell_quote) {
defineReplace(shell_quote_win) {
# Chars that should be quoted (TM).
# - control chars & space
# - the windows shell meta chars "&()<>^|
# - the potential separators ,;=
#TODO: how to deal with "^", "|"? every char are seperated by "|"?
#how to avoid replacing "^" again for the second time
isEmpty(1):error("shell_quote(arg) requires one argument.")
return($$quote($$1))
special_chars = & \( \) < >
for(c, special_chars) {
1 ~= s,$$c,^$$c,g
}
#for qmake \\
#1 ~= s,\\),^\),g
#1 ~= s,\\(,^\(,g
return($$1)
}

defineReplace(system_path) {
win32 {
1 ~= s,/,\\,g #qmake \\=>put \\=>real \?
} else {
1 ~= s,\\\\,/,g ##why is \\\\. real \=>we read \\=>qmake \\\\?
defineReplace(shell_quote_unix) {
# - unix shell: 0-32 \'"$`<>|;&(){}*?#!~[]
#TODO: how to deal with "#" "|" and "^"?
#how to avoid replacing "^" again for the second time
# \$ is eol
special_chars = & \( \) < > \\ \' \" ` ; \{ \} * ? ! ~ \[ \]
for(c, special_chars) {
1 ~= s,$$c,\\$$c,g
}
return($$1)
}
##TODO: see qmake/library/ioutils.cpp
defineReplace(shell_quote) {
win32:isEmpty(QMAKE_SH):return($$shell_quote_win($$1))
return($$shell_quote_unix($$1))
}

##TODO: see qmake/library/ioutils.cpp
defineReplace(system_quote) {
isEmpty(1):error("system_quote(arg) requires one argument.")
return($$quote($$1))
unix:return($$shell_quote_unix($$1))
return($$shell_quote_win($$1))
}

defineReplace(system_path) {
win32 {
1 ~= s,/,\\,g #qmake \\=>put \\=>real \?
} else {
1 ~= s,\\\\,/,g ##why is \\\\. real \=>we read \\=>qmake \\\\?
}
return($$1)
}

} #lessThan(QT_MAJOR_VERSION, 5)
#argument 1 is default dir if not defined
defineTest(getBuildRoot) {
!isEmpty(2): unset(BUILD_DIR)
Expand Down
3 changes: 1 addition & 2 deletions configure.pri
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 18,6 @@ defineTest(cache) {
write_file($$_QMAKE_CACHE_QT4_)|return(false)
}
isEmpty(1):return(true)

!isEmpty(2):isEqual(2, set):mode_set=1
isEmpty(3) {
isEmpty(mode_set):error("cache(): modes other than 'set' require a source variable.")
Expand Down Expand Up @@ -71,7 70,7 @@ equals(MAKEFILE_GENERATOR, UNIX) {

defineTest(qtRunLoggedCommand) {
msg = " $$1"
write_file($$QMAKE_CONFIG_LOG, msg, append)
write_file($$QMAKE_CONFIG_LOG, msg, append)#|error("write file failed") #for debug
system("$$1 >> \"$$QMAKE_CONFIG_LOG\" 2>&1")|return(false)
return(true)
}
Expand Down

0 comments on commit bd399a5

Please sign in to comment.