Skip to content

Commit

Permalink
added string indent fnctin for formatting runtime help
Browse files Browse the repository at this point in the history
  • Loading branch information
toeb committed Mar 30, 2017
1 parent fa242bb commit 7ec4ada
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 24 deletions.
36 changes: 20 additions & 16 deletions cmake/cmake/targets/target_add_auto.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
parameter_definition(target_add_auto
<--name{"the name of the target, if empty or '.' the current folder name is used as project name"}:<string>=.>
[--cppFeatures:<string>=cxx_variadic_templates;cxx_override]
[--version{"the version of this target"}:<semver>=0.0.1]
[--include-dir{"directory containing the public headers"}=>includeDir:<path>=include]
[--source-dir{"directory containing the source files and private headers"}=>sourceDir:<string>=src]
[--install{"generate install targets"}:<bool>=true]
[--shared{"generate shared lib target"}:<bool>=true]
[--static{"generate static lib target"}:<bool>=true]
[--tests:<bool>=true]
[--executable:<bool>=false]
[--linkLibraries:<string>=]
[--verbose]
"#generates automatic targets for the current folder. assumes default package layout:
# * directory `src` containing compilable files
# * directory `header` containing public header files (which are installed)
# * asdasd"
)

function(target_add_auto)
arguments_extract_typed_values(0 ${ARGC}
<--name:<string>=.>
[--cppFeatures:<string>=cxx_variadic_templates;cxx_override]
[--version:<semver>=0.0.1]
[--includeDir:<string>=include]
[--sourceDir:<string>=src]
[--install:<bool>=true]
[--shared:<bool>=true]
[--static:<bool>=true]
[--tests:<bool>=true]
[--executable:<bool>=false]
[--linkLibraries:<string>=]
[--verbose]

)

arguments_extract_defined_values(0 ${ARGC} target_add_auto)


if("${name}_" STREQUAL "_" OR "${name}_" STREQUAL "._")
## get target name from current path
Expand Down
1 change: 1 addition & 0 deletions cmake/log/error.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ function(error)
log(--error ${ARGN})
return_ans()
endfunction()

3 changes: 3 additions & 0 deletions cmake/log/warning.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function(warning ${ARGN})
return_ans()
endfunction()
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
## returns a list of valid package uris which contain the scheme gitscm
## you can specify a query for ref/branch/tag by adding ?ref=* or ?ref=name
## only ?ref=* returns multiple uris

parameter_definition(
package_source_query_git
<uri{"the query uri of a git package"}:<uri>>
[--package-handle{"if set, return a package handle instead of <unique_uri>"}=>return_package_handle]
"#returns a list of valid gitscm:// `<package uri>`s. You can specify a query for ref/branch/tag by adding `?ref=*`, `?ref=name`, `?ref=<hash>`. Only when using `?ref=*` are multiple `<package uri>`s returned."
)
function(package_source_query_git)
arguments_extract_defined_values(0 ${ARGC} package_source_query_git)
Expand Down Expand Up @@ -38,6 +37,10 @@ function(package_source_query_git)
assign(tag = uri.params.tag)
assign(rev = uri.params.rev)

## todo: check if unused params are passed
## which should result in a warning


set(ref ${ref} ${branch} ${tag})
list_pop_front(ref)
ans(ref)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ function(package_source_resolve_path uri)

list(LENGTH package_handle count)
if(NOT "${count}" EQUAL 1)
error("could not find a unique immutbale uri for {uri.uri}")
error("could not find a unique immutable uri for {uri.uri}")
return()
endif()


return_ref(package_handle)

endfunction()

6 changes: 6 additions & 0 deletions cmake/session/session.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function(session)


## maybe later some kind of session which restores values between cmakepp runs

endfunction()
66 changes: 66 additions & 0 deletions cmake/string/string_indent.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

function(string_indent str indentation)
string_codes()

set(maxWidth ${ARGN})
if("${maxWidth}_" STREQUAL "_")
set(maxWidth 0)
endif()

# normalize line endings
string(REPLACE "\r\n" "\n" str "${str}")

if("${maxWidth}" LESS 1)
string(REPLACE "\n" "\n${indentation}" str "${str}")
set(str "${indentation}${str}")
return_ref(str)
endif()

# desemicolonize
string(REPLACE ";" "${semicolon_code}" str "${str}")

#string(REPLACE "\n" ";" str "${str}")

string(REPLACE " " ";" str "${str}")
string(REPLACE "\n" ";${free_token1}" str "${str}")
set(result)

set(currentLine)
set(currentLength 0)
##
while(true)
list(LENGTH str size)
if(NOT size)
if(NOT "${currentLine}_" STREQUAL "_")
list(APPEND result "${currentLine}")
endif()
break()
endif()

list_pop_front(str)
ans(word)

if("${word}" STREQUAL "${free_token1}")
list(APPEND result "${currentLine}")
set(currentLine)
continue()
endif()


set(currentLine "${currentLine} ${word}")
string(LENGTH "${currentLine}" len)
if(NOT "${len}" LESS "${maxWidth}")
list(APPEND result "${currentLine}")
set(currentLine)
endif()
endwhile()

string(REPLACE "${free_token1}" "\n" result "${result}")

string(REPLACE ";" "\n" result "${result}")
string(REPLACE "\n" "\n${indentation}" result "${result}")
string(REPLACE "${semicolon_code}" ";" result "${result}")
set(result "${indentation}${result}")

return_ref(result)
endfunction()
10 changes: 9 additions & 1 deletion cmake/type/help.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ function(help)
ans(res)
if(NOT res)
message(INFO "no help found for function ${ARGN}")
return()
endif()

map_import_properties(${res} positionals nonpositionals name)
map_import_properties(${res} positionals nonpositionals name description)

message("Usage:")

if(description)
string_indent("${description}" "\t" 50)
ans(description)
message("${description}\n")
endif()

message("\tpositional parameters: ")
set(counter 0)
foreach(positional ${positionals})
Expand Down
11 changes: 9 additions & 2 deletions cmake/type/typed_value_definitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ function(typed_value_definitions name)
regex_cmake()
string(REGEX MATCHALL "(^|;)<.*>($|;)" positionals "${ARGN}")
string(REGEX MATCHALL "(^|;)\\[.*\\]($|;)" nonpositionals "${ARGN}")
string(REGEX REPLACE "((^|;)<.*>($|;))|(^|;)\\[.*\\]($|;)" "" comments "${ARGN}")
string(REGEX REPLACE "(^|[\n])[ \t]*#([^\n]*)" "\\2\n" comments "${comments}")

map_new()
ans(def)
ans(def)
map_set(${def} name "${name}")

if(comments)
map_set(${def} description "${comments}")
endif()
foreach(positional ${positionals})
typed_value_definition("${positional}")
typed_value_definition("${positional}")
ans(d)
map_append(${def} positionals ${d})
endforeach()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function(test)



fwrite("test/asdasd/package.cmake" "{\"id\":\"mypkg\"}")
mkdir("test/asdasd2")
Expand Down
54 changes: 54 additions & 0 deletions tests/session/session_test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function(test)
set(session_file ".cmakepp-session")

function(get_session)

map_get(global "sess")
return_ans()
endfunction()

function(set_session)
map_set(global "sess" ${ARGN})
endfunction()

function(session)
file_find_anchor("${session_file}")
ans(anchor)
if(NOT anchor)
fwrite("${session_file}" "")
endif()
cmake_read("${session_file}")
ans(sessionData)
set_session("${sessionData}")
json_print("${sessionData}")
return_ref(sessionData)


endfunction()

function(session_write)
get_session()
ans(sess)
cmake_write("${session_file}" "${sess}")
endfunction()



set_session(asdasdasd)
session_write()






session()
ans(session)




assert(EXISTS "${test_dir}/.cmakepp-session")


endfunction()
21 changes: 20 additions & 1 deletion tests/string/string_indent_lines_test.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
function(test)




string_indent("aasdasdja kshdlkasjdl kajsddalska sdkajsd
asdasdkasdkajsdlkajsd
asdlasdk
asdasd
alskdjalksjdlkasjdlkajsdlkajsdlkajslkdjalksjdlkajsdlkajsdlkajsdlkjasldk" " " 20)

assert("${__ans}" STREQUAL " aasdasdja kshdlkasjdl
kajsddalska sdkajsd
asdasdkasdkajsdlkajsd
asdlasdk
asdasd
alskdjalksjdlkasjdlkajsdlkajsdlkajslkdjalksjdlkajsdlkajsdlkajsdlkjasldk")



endfunction()
endfunction()

0 comments on commit 7ec4ada

Please sign in to comment.