From 40becb79dacc4be4cff51a71f9fd8e0ede0cbe68 Mon Sep 17 00:00:00 2001 From: Tobias Becker Date: Tue, 21 Apr 2015 15:06:24 +0200 Subject: [PATCH 01/10] worked on promises --- cmake/cmakepp/cmakepp_configure.cmake | 27 +++++++++++ cmake/filesystem/globbing/glob_watch.cmake | 54 ++++++++++++++++++++++ cmake/function/callable/call2.cmake | 1 + cmake/task/promise.cmake | 51 -------------------- cmake/task/promise_from_anonymous.cmake | 10 ++++ cmake/task/promise_from_callable.cmake | 8 ++++ cmake/task/promise_from_task.cmake | 18 ++++++++ cmake/task/promise_from_value.cmake | 8 ++++ cmake/task/promise_new.cmake | 8 ++++ 9 files changed, 134 insertions(+), 51 deletions(-) create mode 100644 cmake/cmakepp/cmakepp_configure.cmake create mode 100644 cmake/filesystem/globbing/glob_watch.cmake create mode 100644 cmake/task/promise_from_anonymous.cmake create mode 100644 cmake/task/promise_from_callable.cmake create mode 100644 cmake/task/promise_from_task.cmake create mode 100644 cmake/task/promise_from_value.cmake create mode 100644 cmake/task/promise_new.cmake diff --git a/cmake/cmakepp/cmakepp_configure.cmake b/cmake/cmakepp/cmakepp_configure.cmake new file mode 100644 index 00000000..267a6450 --- /dev/null +++ b/cmake/cmakepp/cmakepp_configure.cmake @@ -0,0 +1,27 @@ +function(cmakepp_configure project_path) + print_Vars(project_path) + + pwd() + ans(cwd) + print_Vars(cwd) + + + + if(NOT EXISTS "${project_path}/CMakeLists.txt") + throw("no cmakelists found") + endif() + + + pushd(--create "${project_path}/build") + + + cmake(..) + + popd() + + + + + return(ok) + +endfunction() \ No newline at end of file diff --git a/cmake/filesystem/globbing/glob_watch.cmake b/cmake/filesystem/globbing/glob_watch.cmake new file mode 100644 index 00000000..4be68af1 --- /dev/null +++ b/cmake/filesystem/globbing/glob_watch.cmake @@ -0,0 +1,54 @@ +function(test) + + function(watch_glob) + + promise_from_anonymous(() + + message("promise: \${promise}") + map_tryget(\${promise} continue) + ans(continue) + if(NOT continue) + _message("stopping") + return() + endif() + + map_tryget(\${promise} files) + ans(files) + + + glob(${ARGN}) + ans(new_files) + + set_difference(files new_files) + ans(removed_files) + + set_difference(new_files files) + ans(added_files) + + + _message(files added \${added_files}) + _message(files removed \${removed_files}) + + promise_from_task(\${task}) + ans(next) + return(${next}) + ) + ans(watcher) + map_set(${watcher} continue true) + json_print(${watcher}) + _message("lol ${watcher}") + + return(${watcher}) + endfunction() + + + + + + watch_glob(*.txt) + ans(task) + + promise_wait(${task} --ticks 100) + + +endfunction() \ No newline at end of file diff --git a/cmake/function/callable/call2.cmake b/cmake/function/callable/call2.cmake index 548bd041..7a2aa547 100644 --- a/cmake/function/callable/call2.cmake +++ b/cmake/function/callable/call2.cmake @@ -8,6 +8,7 @@ endfunction() ## faster version function(call2 callable) callable_function("${callable}") + set(current_function "${__ans}") eval("${__ans}(${ARGN})") set(__ans ${__ans} PARENT_SCOPE) endfunction() \ No newline at end of file diff --git a/cmake/task/promise.cmake b/cmake/task/promise.cmake index 9e7d7d28..bdc84e82 100644 --- a/cmake/task/promise.cmake +++ b/cmake/task/promise.cmake @@ -26,54 +26,3 @@ function(promise) return_ref(promise) endfunction() - -function(promise_new) - map_new() - ans(promise) - map_set_special("${promise}" $type promise) - map_set("${promise}" promise_state "pending") - return_ref(promise) -endfunction() - -function(promise_from_value) - promise_new() - ans(promise) - map_set("${promise}" promise_state "resolved") - map_set("${promise}" value "${ARGN}") - return_ref(promise) -endfunction() - -function(promise_from_task) - promise_new() - ans(promise) - - task("${ARGN}") - ans(task) - - if(NOT task) - return() - endif() - - map_set("${promise}" task "${task}") - - return(${promise}) -endfunction() - - -function(promise_from_callable callable) - task_new("${callable}") - ans(task) - promise_from_task("${task}") - ans(promise) - return_ref(promise) -endfunction() - -function(promise_from_anonymous) - arguments_anonymous_function(0 ${ARGC}) - ans(function) - promise_from_callable("${function}") - return_ans() -endfunction() - - - diff --git a/cmake/task/promise_from_anonymous.cmake b/cmake/task/promise_from_anonymous.cmake new file mode 100644 index 00000000..27f7c727 --- /dev/null +++ b/cmake/task/promise_from_anonymous.cmake @@ -0,0 +1,10 @@ + +function(promise_from_anonymous) + arguments_anonymous_function(0 ${ARGC}) + ans(function) + promise_from_callable("${function}") + return_ans() +endfunction() + + + diff --git a/cmake/task/promise_from_callable.cmake b/cmake/task/promise_from_callable.cmake new file mode 100644 index 00000000..45402140 --- /dev/null +++ b/cmake/task/promise_from_callable.cmake @@ -0,0 +1,8 @@ + +function(promise_from_callable callable) + task_new("${callable}") + ans(task) + promise_from_task("${task}") + ans(promise) + return_ref(promise) +endfunction() diff --git a/cmake/task/promise_from_task.cmake b/cmake/task/promise_from_task.cmake new file mode 100644 index 00000000..9ed20154 --- /dev/null +++ b/cmake/task/promise_from_task.cmake @@ -0,0 +1,18 @@ + + +function(promise_from_task) + promise_new() + ans(promise) + + task("${ARGN}") + ans(task) + + if(NOT task) + return() + endif() + + map_set("${promise}" task "${task}") + + return(${promise}) +endfunction() + diff --git a/cmake/task/promise_from_value.cmake b/cmake/task/promise_from_value.cmake new file mode 100644 index 00000000..53a99478 --- /dev/null +++ b/cmake/task/promise_from_value.cmake @@ -0,0 +1,8 @@ + +function(promise_from_value) + promise_new() + ans(promise) + map_set("${promise}" promise_state "resolved") + map_set("${promise}" value "${ARGN}") + return_ref(promise) +endfunction() \ No newline at end of file diff --git a/cmake/task/promise_new.cmake b/cmake/task/promise_new.cmake new file mode 100644 index 00000000..ccd64042 --- /dev/null +++ b/cmake/task/promise_new.cmake @@ -0,0 +1,8 @@ + +function(promise_new) + map_new() + ans(promise) + map_set_special("${promise}" $type promise) + map_set("${promise}" promise_state "pending") + return_ref(promise) +endfunction() From 33620b304a9d7c84ff27fe63dc50918c1cf16ed2 Mon Sep 17 00:00:00 2001 From: Tobias Becker Date: Sun, 10 May 2015 15:15:32 +0200 Subject: [PATCH 02/10] added reinit as a pkg command added automatic project file recognition --- cmake/cmakepp/cmakepp_project_cli.cmake | 21 ++++++++++++-- cmake/core/exception/exception_new.cmake | 19 ++++++------ cmake/filesystem/globbing/glob.cmake | 1 + cmake/filesystem/globbing/glob_single.cmake | 17 +++++++++++ .../hooks/on_materialized_hook.cmake | 2 +- .../materialize/project_materialize.cmake | 14 +++++---- .../project_package_descriptor_reader.cmake | 29 +++++++++++++++++++ cmake/package/project/project_open.cmake | 5 ++-- cmake/package/project/project_read.cmake | 9 ++---- .../project/utility/project_install.cmake | 2 ++ cmake/testing/assert.cmake | 17 ++++++++++- cmake/vcs/git/git_cached_clone.cmake | 2 +- .../project_materialize_test.cmake | 3 +- tests/web/download_async_test.cmake | 18 ++++++++++++ 14 files changed, 129 insertions(+), 30 deletions(-) create mode 100644 cmake/filesystem/globbing/glob_single.cmake create mode 100644 tests/web/download_async_test.cmake diff --git a/cmake/cmakepp/cmakepp_project_cli.cmake b/cmake/cmakepp/cmakepp_project_cli.cmake index 41862970..68fd00e3 100644 --- a/cmake/cmakepp/cmakepp_project_cli.cmake +++ b/cmake/cmakepp/cmakepp_project_cli.cmake @@ -17,6 +17,7 @@ function(cmakepp_project_cli) if(verbose) event_addhandler("on_log_message" "[](entry)message(FORMAT '{entry.function}: {entry.message}')") + event_addhandler("project_on_new" "[](entry) message(FORMAT '{event.event_id}')") event_addhandler("project_on_opening" "[](proj) message(FORMAT '{event.event_id}: {proj.content_dir}'); message(PUSH)") event_addhandler("project_on_opened" "[](proj) message(FORMAT '{event.event_id}')") event_addhandler("project_on_loading" "[](proj) message(FORMAT '{event.event_id}'); message(PUSH)") @@ -41,6 +42,9 @@ function(cmakepp_project_cli) endif() + list_pop_front(args) + ans(cmd) + list_extract_flag(args --save) ans(save) @@ -56,18 +60,28 @@ function(cmakepp_project_cli) else() project_read("${project_dir}") ans(project) + ## removes the current config directory + if("${cmd}" STREQUAL reinit) + map_tryget("${project}" project_descriptor ) + ans(project_descriptor) + map_tryget("${project_descriptor}" config_dir) + ans(config_dir) + project_close("${project}") + log("reinitializing project - deleting config dir ${project_dir}/${config_dir}") + rm(-r "${project_dir}/${config_dir}") + set(cmd init) + endif() endif() - list_pop_front(args) - ans(cmd) - if(NOT cmd) set(cmd run) endif() + ## creates the project int the specified path if("${cmd}" STREQUAL "init") list_pop_front(args) ans(path) + log("initializeing project in ${path}") project_open("${path}") ans(project) endif() @@ -90,6 +104,7 @@ function(cmakepp_project_cli) if("${cmd}" STREQUAL "init") + elseif("${cmd}" STREQUAL "get") if("${args}" MATCHES "(.+)\\((.*)\\)$") diff --git a/cmake/core/exception/exception_new.cmake b/cmake/core/exception/exception_new.cmake index 1ead3a62..9b983438 100644 --- a/cmake/core/exception/exception_new.cmake +++ b/cmake/core/exception/exception_new.cmake @@ -3,14 +3,15 @@ ## an exception is map ` ::= { message: }` of $type `exception` ## if checked in an if statement it evaluates to false because it ends with -NOTFOUND ## -function(exception_new message) +function(exception_new) address_new() - ans(error) - set(error "${error}-NOTFOUND") - map_set(${error} message "${message}") - if(ARGN) - map_set(${error} inner_exceptions ${ARGN}) - endif() - map_set_special(${error} $type exception) - return_ref(error) + ans(exception) + set(exception "${exception}-NOTFOUND") + set(args ${ARGN}) + list_pop_front(args) + ans(code) + map_set(${exception} code "${code}") + map_set(${exception} message ${args}) + map_set_special(${exception} $type exception) + return_ref(exception) endfunction() \ No newline at end of file diff --git a/cmake/filesystem/globbing/glob.cmake b/cmake/filesystem/globbing/glob.cmake index aec28e44..eaf30a65 100644 --- a/cmake/filesystem/globbing/glob.cmake +++ b/cmake/filesystem/globbing/glob.cmake @@ -41,3 +41,4 @@ function(glob) return_ref(paths) endfunction() + diff --git a/cmake/filesystem/globbing/glob_single.cmake b/cmake/filesystem/globbing/glob_single.cmake new file mode 100644 index 00000000..07baf6ef --- /dev/null +++ b/cmake/filesystem/globbing/glob_single.cmake @@ -0,0 +1,17 @@ + +## +## +## returns a single file name to which the glob expression matches +## if the glob expression matches multiple files then nothing is returned +function(glob_single) + glob(${ARGN}) + ans(found) + + + list(LENGTH found len) + if(${len} EQUAL 1) + return_ref(found) + endif() + + return() +endfunction() \ No newline at end of file diff --git a/cmake/package/project/extensions/hooks/on_materialized_hook.cmake b/cmake/package/project/extensions/hooks/on_materialized_hook.cmake index 8b0926fc..4406393d 100644 --- a/cmake/package/project/extensions/hooks/on_materialized_hook.cmake +++ b/cmake/package/project/extensions/hooks/on_materialized_hook.cmake @@ -3,7 +3,7 @@ ## **config** ## ## **hooks**: -## `package_descriptor.cmakepp.hooks.on_materialized( )` +## `package_descriptor.hooks.on_materialized( )` ## this hook is invoked if it exists. it is invoked before the on_load hook ## this means that the project's exports were not loaded when the hook is called ## however since cmake files are callable you can specify a local path diff --git a/cmake/package/project/extensions/materialize/project_materialize.cmake b/cmake/package/project/extensions/materialize/project_materialize.cmake index 3680e25b..bba33ede 100644 --- a/cmake/package/project/extensions/materialize/project_materialize.cmake +++ b/cmake/package/project/extensions/materialize/project_materialize.cmake @@ -8,7 +8,7 @@ ## ## returns the package handle on success ## -## **events**: +## **emits**: ## * `[pwd=target_dir]project_on_package_materializing( )` ## * `[pwd=target_dir]project_on_package_materialized( )` ## @@ -18,6 +18,10 @@ ## * `project_handle.project_descriptor.package_materializations. = ` ## * `package_handle.materialization_descriptor = ` ## +## **throws** +## * invalid_package_uri - uri cannot be resolved +## * invalid_package_dir +## ## ``` ## ::= { ## content_dir: # path relative to project root @@ -69,9 +73,10 @@ function(project_materialize project_handle package_uri) ## get a package handle from uri package_source_resolve(${package_source} "${package_uri}" --cache ${package_cache}) + ans(package_handle) if(NOT package_handle) - return() + throw("invalid_package_uri" "could not resolve package uri {package_uri}" --function project_materialize) endif() @@ -110,8 +115,7 @@ function(project_materialize project_handle package_uri) map_set(${package_handle} content_dir ${package_content_dir}) if("${package_content_dir}" STREQUAL "${project_dir}") - message(WARNING"project_materialize: invalid package dir '${package_content_dir}'") - return() + throw("invalid_package_dir" "the specified content dir is the project dir: '${project_dir}'") endif() pushd(${installation_dir} --create) @@ -125,7 +129,7 @@ function(project_materialize project_handle package_uri) if(NOT pull_handle) map_remove(${package_handle} materialization_descriptor) popd() - return() + throw("package_pull_error" "could not pull package") endif() map_set(${package_materializations} ${package_uri} ${package_handle}) diff --git a/cmake/package/project/extensions/package_descriptor/project_package_descriptor_reader.cmake b/cmake/package/project/extensions/package_descriptor/project_package_descriptor_reader.cmake index 52b5ad0b..731fde01 100644 --- a/cmake/package/project/extensions/package_descriptor/project_package_descriptor_reader.cmake +++ b/cmake/package/project/extensions/package_descriptor/project_package_descriptor_reader.cmake @@ -30,3 +30,32 @@ function(project_package_descriptor_reader project) endif() endfunction() + +function(project_package_descriptor_initialize_new project) + map_tryget("${project}" "content_dir") + ans(content_dir) + glob_single("${content_dir}/package.*") + ans(package_file) + + if(NOT package_file) + message("no pakcage file") + return() + endif() + + + log("using existing package_descriptor in '${package_file}'") + + path_relative("${content_dir}" "${package_file}") + ans(relative_package_file) + + map_tryget(${project} project_descriptor) + ans(project_descriptor) + + map_set(${project_descriptor} package_descriptor_file "${relative_package_file}") + + return() + +endfunction() + + +task_enqueue("[]() message(wot); event_addhandler(project_on_new project_package_descriptor_initialize_new)") \ No newline at end of file diff --git a/cmake/package/project/project_open.cmake b/cmake/package/project/project_open.cmake index dbbb980c..6a490f96 100644 --- a/cmake/package/project/project_open.cmake +++ b/cmake/package/project/project_open.cmake @@ -47,11 +47,10 @@ function(project_open content_dir) ## emit events - - ## if project is new emit that event - project_state_matches("${project_handle}" "^(unknown)$") + project_state_matches("${project_handle}" "unknown") ans(is_new) + if(is_new) event_emit(project_on_new ${project_handle}) project_state_change("${project_handle}" closed) diff --git a/cmake/package/project/project_read.cmake b/cmake/package/project/project_read.cmake index b4d07fb7..a095d727 100644 --- a/cmake/package/project/project_read.cmake +++ b/cmake/package/project/project_read.cmake @@ -28,8 +28,7 @@ function(project_read) endif() if(NOT project_file) - error("no project file found for location '{location}' " --function project_read) - return() + throw("no project file found for location '{location}' " --function project_read) endif() @@ -37,16 +36,14 @@ function(project_read) ans(project_handle) if(NOT project_handle) - error("not a valid project file '{project_file}' " --function project_read) - return() + throw("not a valid project file '{project_file}' " --function project_read) endif() ## derive content dir from configured relative project file path assign(project_file_path = project_handle.project_descriptor.project_file) if(NOT project_file_path) - error("project_descriptor.project_file is missing" --function project_read) - return() + throw("project_descriptor.project_file is missing" --function project_read) endif() string_remove_ending("${project_file}" "/${project_file_path}") ans(content_dir) diff --git a/cmake/package/project/utility/project_install.cmake b/cmake/package/project/utility/project_install.cmake index bfce997b..1b40036a 100644 --- a/cmake/package/project/utility/project_install.cmake +++ b/cmake/package/project/utility/project_install.cmake @@ -4,10 +4,12 @@ function(project_install project_handle) set(args ${ARGN}) project_change_dependencies(${project_handle} ${args}) + rethrow() ans(changeset) project_materialize_dependencies(${project_handle}) + rethrow() ans(changes_handles) return(${changeset}) diff --git a/cmake/testing/assert.cmake b/cmake/testing/assert.cmake index b1b16c28..de009fb7 100644 --- a/cmake/testing/assert.cmake +++ b/cmake/testing/assert.cmake @@ -23,7 +23,7 @@ function(assert) # parse arguments set(options == EQUALS AREEQUAL ARE_EQUAL ACCU SILENT DEREF INCONCLUSIVE ISNULL ISNOTNULL) - set(oneValueArgs EXISTS COUNT MESSAGE RESULT MESSAGE_TYPE CONTAINS MISSING MATCH MAP_MATCHES FILE_CONTAINS) + set(oneValueArgs EXISTS EXCEPTION COUNT MESSAGE RESULT MESSAGE_TYPE CONTAINS MISSING MATCH MAP_MATCHES FILE_CONTAINS) set(multiValueArgs CALL PREDICATE ) set(prefix) cmake_parse_arguments("${prefix}" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -90,6 +90,21 @@ function(assert) # message("predicate '${_PREDICATE}'") call(${_PREDICATE}(${_UNPARSED_ARGUMENTS})) ans(result) + elseif(_EXCEPTION) + is_exception("${_UNPARSED_ARGUMENTS}") + ans(is_exception) + set(result false) + + if(is_exception) + + map_tryget("${_UNPARSED_ARGUMENTS}" code) + ans(exception_type) + if("${_EXCEPTION}_" STREQUAL "${exception_type}_") + set(result true) + else() + set(_MESSAGE "invalid exception: expected exception code to be '${_EXCEPTION}', got '${exception_type}'") + endif() + endif() elseif(_FILE_CONTAINS) if(NOT _MESSAGE) set(_MESSAGE "assertion failed: file '${_FILE_CONTAINS}' does not contain: ${_UNPARSED_ARGUMENTS}") diff --git a/cmake/vcs/git/git_cached_clone.cmake b/cmake/vcs/git/git_cached_clone.cmake index 41b2f66b..d912ebe8 100644 --- a/cmake/vcs/git/git_cached_clone.cmake +++ b/cmake/vcs/git/git_cached_clone.cmake @@ -66,7 +66,7 @@ git_lean(clone --reference "${repo_cache_dir}" "${remote_uri}" "${target_dir}") ans_extract(error) if(error) - message(FATAL_ERROR "failed to reference clone") + message(FATAL_ERROR "failed to reference clone (${error}) ${__ans}") endif() pushd("${target_dir}") git_lean(checkout "${git_ref}") diff --git a/tests/package/project_tests/project_materialize_test.cmake b/tests/package/project_tests/project_materialize_test.cmake index 22da8d08..4a4457d2 100644 --- a/tests/package/project_tests/project_materialize_test.cmake +++ b/tests/package/project_tests/project_materialize_test.cmake @@ -26,11 +26,12 @@ function(test) assertf("{tracker.project_on_package_materialized[0].args[1]}" STREQUAL "{handle}") assert(EXISTS "${test_dir}/packages/mock_A-0.0.0") + ## does not exist timer_start(t2) project_materialize("${project}" "meh") ans(handle) timer_print_elapsed(t2) - + assert(EXCEPTION "invalid_package_uri" "${handle}") assert(NOT handle) diff --git a/tests/web/download_async_test.cmake b/tests/web/download_async_test.cmake new file mode 100644 index 00000000..2e418f94 --- /dev/null +++ b/tests/web/download_async_test.cmake @@ -0,0 +1,18 @@ +function(test) + + function(download_async uri) + set(args ${ARGN}) + + set(uri_string "${uri}") + + uri_coerce(uri) + + execute_script_async(" + + + ") + + + endfunction() + +endfunction() \ No newline at end of file From e611bef7359689839845bd711dca0fa307016000 Mon Sep 17 00:00:00 2001 From: Tobias Becker Date: Mon, 11 May 2015 22:14:12 +0200 Subject: [PATCH 03/10] made message function leaner and git_cached_clone now throws exceptions instead of fataly failig --- .../target_include_directories.cmake | 2 +- cmake/core/message.cmake | 53 ++---- cmake/filesystem/path/path_relative.cmake | 28 +--- .../git/package_source_pull_git.cmake | 1 + .../git/package_source_resolve_git.cmake | 1 + cmake/shell/alias_create.cmake | 6 - cmake/vcs/git/git_cached_clone.cmake | 158 +++++++++--------- tests/vcs/git/git_cached_clone_test.cmake | 12 +- 8 files changed, 107 insertions(+), 154 deletions(-) diff --git a/cmake/cmake/targets/overrides/target_include_directories.cmake b/cmake/cmake/targets/overrides/target_include_directories.cmake index aaeb872e..e2b1ec2a 100644 --- a/cmake/cmake/targets/overrides/target_include_directories.cmake +++ b/cmake/cmake/targets/overrides/target_include_directories.cmake @@ -2,7 +2,7 @@ function(target_include_directories target) if(NOT COMMAND _target_include_directories) cmake_parse_arguments("" "SYSTEM;BEFORE;PUBLIC;INTERFACE;PRIVATE" "" "" ${ARGN} ) - message(DEBUG "using fallback version of target_include_directories, consider upgrading to cmake >= 2.8.10") + # message(DEBUG "using fallback version of target_include_directories, consider upgrading to cmake >= 2.8.10") if(_SYSTEM OR _BEFORE OR _INTERFACE OR _PRIVATE) message(FATAL_ERROR "shim for target_include_directories does not support SYSTEM, PRIVATE, INTERFACE or BEFORE upgrade to cmake >= 2.8.10") diff --git a/cmake/core/message.cmake b/cmake/core/message.cmake index 763b7506..78346626 100644 --- a/cmake/core/message.cmake +++ b/cmake/core/message.cmake @@ -1,8 +1,14 @@ function(message) - cmake_parse_arguments("" "PUSH_AFTER;POP_AFTER;DEBUG;INFO;FORMAT;PUSH;POP" "LEVEL" "" ${ARGN}) - set(log_level ${_LEVEL}) - set(text ${_UNPARSED_ARGUMENTS}) + cmake_parse_arguments("" "PUSH_AFTER;POP_AFTER;INFO;FORMAT;PUSH;POP" "" "" ${ARGN}) + ## format + if(_FORMAT) + format("${_UNPARSED_ARGUMENTS}") + ans(text) + else() + set(text ${_UNPARSED_ARGUMENTS}) + endif() + ## indentation if(_PUSH) @@ -24,26 +30,7 @@ function(message) ## end of indentationb - ## log_level - if(_DEBUG) - if(NOT log_level) - set(log_level 3) - endif() - set(text STATUS ${text}) - endif() - if(_INFO) - if(NOT log_level) - set(log_level 2) - endif() - set(text STATUS ${text}) - endif() - if(NOT log_level) - set(log_level 0) - endif() - if(NOT MESSAGE_LEVEL) - set(MESSAGE_LEVEL 3) - endif() list(GET text 0 modifier) if(${modifier} MATCHES "FATAL_ERROR|STATUS|AUTHOR_WARNING|WARNING|SEND_ERROR|DEPRECATION") @@ -52,15 +39,8 @@ function(message) set(modifier) endif() - ## format - if(_FORMAT) - format( "${text}") - ans(text) - endif() + - if(NOT MESSAGE_DEPTH ) - set(MESSAGE_DEPTH -1) - endif() if(NOT text) return() @@ -70,22 +50,9 @@ function(message) ans(message) map_set(${message} text "${text}") map_set(${message} indent_level ${message_indent_level}) - map_set(${message} log_level ${log_level}) map_set(${message} mode "${modifier}") event_emit(on_message ${message}) - if(log_level GREATER MESSAGE_LEVEL) - return() - endif() - if(MESSAGE_QUIET) - return() - endif() - # check if deep message are to be ignored - if(NOT MESSAGE_DEPTH LESS 0) - if("${message_indent_level}" GREATER "${MESSAGE_DEPTH}") - return() - endif() - endif() tock() diff --git a/cmake/filesystem/path/path_relative.cmake b/cmake/filesystem/path/path_relative.cmake index f9704778..cb4bd98f 100644 --- a/cmake/filesystem/path/path_relative.cmake +++ b/cmake/filesystem/path/path_relative.cmake @@ -67,30 +67,4 @@ function(path_relative path_base path_rel) return_ref(result_path) endfunction() -# transforms a path to a path relative to base_dir -#function(path_relative base_dir path) -# path("${base_dir}") -# ans(base_dir) -# path("${path}") -# ans(path) -# string_take(path "${base_dir}") -# ans(match) -# -# if(NOT match) -# return_ref(path) -# #message(FATAL_ERROR "${path} is not relative to ${base_dir}") -# endif() -# -# if("${path}" MATCHES "^\\/") -# string_substring("${path}" 1) -# ans(path) -# endif() -# -# -# if(match AND NOT path) -# set(path ".") -# endif() -# -# return_ref(path) -#endfunction() -# \ No newline at end of file + diff --git a/cmake/package/package_source/git/package_source_pull_git.cmake b/cmake/package/package_source/git/package_source_pull_git.cmake index ad6c5180..dc47bd3a 100644 --- a/cmake/package/package_source/git/package_source_pull_git.cmake +++ b/cmake/package/package_source/git/package_source_pull_git.cmake @@ -22,6 +22,7 @@ assign(revision = package_handle.scm_descriptor.ref.revision) git_cached_clone("${remote_uri}" "${target_dir}" --ref "${revision}" ${args}) + rethrow(true) ans(target_dir) map_set(${package_handle} content_dir "${target_dir}") diff --git a/cmake/package/package_source/git/package_source_resolve_git.cmake b/cmake/package/package_source/git/package_source_resolve_git.cmake index fdf536fd..51301b8f 100644 --- a/cmake/package/package_source/git/package_source_resolve_git.cmake +++ b/cmake/package/package_source/git/package_source_resolve_git.cmake @@ -19,6 +19,7 @@ function(package_source_resolve_git uri) assign(rev = package_handle.scm_descriptor.ref.revision) git_cached_clone("${remote_uri}" --ref ${rev} --read package.cmake) + rethrow(true) ans(package_descriptor_content) json_deserialize("${package_descriptor_content}") diff --git a/cmake/shell/alias_create.cmake b/cmake/shell/alias_create.cmake index bbf2d6e5..bf3440b2 100644 --- a/cmake/shell/alias_create.cmake +++ b/cmake/shell/alias_create.cmake @@ -10,11 +10,6 @@ function(alias_create name command_string) fwrite("${path}" "@echo off\r\n${command_string} %*") reg_append_if_not_exists(HKCU/Environment Path "${bin_dir}") ans(res) - if(res) - #message(INFO "alias ${name} was created - it will be available as soon as you restart your shell") - else() - #message(INFO "alias ${name} as created - it is directly available for use") - endif() return(true) endif() @@ -26,7 +21,6 @@ function(alias_create name command_string) path("~/.bashrc") ans(bc) fappend("${bc}" "\nalias ${name}='${command_string}'") - #message(INFO "alias ${name} was created - it will be available as soon as you restart your shell") else() message(FATAL_ERROR "creating alias is not supported by cmakepp on your system your current shell (${shell})") diff --git a/cmake/vcs/git/git_cached_clone.cmake b/cmake/vcs/git/git_cached_clone.cmake index d912ebe8..a6760d37 100644 --- a/cmake/vcs/git/git_cached_clone.cmake +++ b/cmake/vcs/git/git_cached_clone.cmake @@ -1,94 +1,100 @@ - ## git_cached_clone(> [--readonly] ([--file <>]|[--read<>]) [--ref ])-> - function(git_cached_clone remote_uri) - set(args ${ARGN}) +## `(> [--readonly] ([--file <>]|[--read<>]) [--ref ])-> ` +## +## +function(git_cached_clone remote_uri) + set(args ${ARGN}) - list_extract_flag(args --readonly) - ans(readonly) - - list_extract_labelled_value(args --ref) - ans(git_ref) + list_extract_flag(args --readonly) + ans(readonly) + + list_extract_labelled_value(args --ref) + ans(git_ref) - list_extract_labelled_value(args --file) - ans(file) + list_extract_labelled_value(args --file) + ans(file) - list_extract_labelled_value(args --read) - ans(read) + list_extract_labelled_value(args --read) + ans(read) - list_pop_front(args) - ans(target_dir) + list_pop_front(args) + ans(target_dir) - path_qualify(target_dir) + path_qualify(target_dir) - cmakepp_config(cache_dir) - ans(cache_dir) + cmakepp_config(cache_dir) + ans(cache_dir) - string(MD5 cache_key "${remote_uri}" ) + string(MD5 cache_key "${remote_uri}" ) - set(repo_cache_dir "${cache_dir}/git_cache/${cache_key}") + set(repo_cache_dir "${cache_dir}/git_cache/${cache_key}") - if(NOT EXISTS "${repo_cache_dir}") - git_lean(clone --mirror "${remote_uri}" "${repo_cache_dir}") + if(NOT EXISTS "${repo_cache_dir}") + log("creating bar clone of '${remote_uri}' in cache_dir" --function git_cached_clone) + git_lean(clone --mirror "${remote_uri}" "${repo_cache_dir}") + ans_extract(error) + if(error) + rm("${repo_cache_dir}") + throw(git_failed "git could not clone ${remote_uri}" --function git_cached_clon) + endif() + endif() + + + set(result) + pushd("${repo_cache_dir}") + set(ref "${git_ref}") + if(NOT ref) + set(ref "HEAD") + endif() + if(read OR file) + git_lean(fetch) + ans_extract(error) + if(error) + throw(git_failed "failed to fetch" --function git_cached_clon) + endif() + + log("updating cached clone of ${remote_uri}") + + git_lean(show "${ref}:${read}") + ans_extract(error) + ans(git_result) + + if(NOT error) + set(result "${git_result}") + if(file) + set(target_path "${target_dir}/${file}") + fwrite("${target_path}" "${git_result}") + set(result "${target_path}") + endif() + endif() + else() + git_lean(clone --reference "${repo_cache_dir}" "${remote_uri}" "${target_dir}") + ans_extract(error) + if(error) + throw(git_failed "failed to reference clone (${error}) ${__ans}" --function git_cached_clon) + endif() + pushd("${target_dir}") + git_lean(checkout "${git_ref}") ans_extract(error) if(error) - rm("${repo_cache_dir}") - message(FATAL_ERROR "git could not clone ${remote_uri}") + throw(git_failed "failed to checkout ${git_ref}" --function git_cached_clon) endif() - - endif() - set(result) - pushd("${repo_cache_dir}") - set(ref "${git_ref}") - if(NOT ref) - set(ref "HEAD") + git_lean(submodule init) + ans_extract(error) + if(error) + throw(git_failed "failed to init submodules for ${git_ref}" --function git_cached_clon) endif() - if(read OR file) - git_lean(fetch) - ans_extract(error) - if(error) - message(FATAL_ERROR "failed to fetch") - endif() - - git_lean(show "${ref}:${read}") - ans_extract(error) - ans(git_result) - - if(NOT error) - set(result "${git_result}") - if(file) - set(target_path "${target_dir}/${file}") - fwrite("${target_path}" "${git_result}") - set(result "${target_path}") - endif() - endif() - else() - git_lean(clone --reference "${repo_cache_dir}" "${remote_uri}" "${target_dir}") - ans_extract(error) - if(error) - message(FATAL_ERROR "failed to reference clone (${error}) ${__ans}") - endif() - pushd("${target_dir}") - git_lean(checkout "${git_ref}") - ans_extract(error) - if(error) - message(FATAL_ERROR "failed to checkout ${git_ref}") - endif() - git_lean(submodule init) - ans_extract(error) - if(error) - message(FATAL_ERROR "failed to init submodules for ${git_ref}") - endif() - git_lean(submodule update) - ans_extract(error) - if(error) - message(FATAL_ERROR "failed to update submodules for ${git_ref}") - endif() - popd() - set(result "${target_dir}") + git_lean(submodule update) + ans_extract(error) + if(error) + throw(git_failed "failed to update submodules for ${git_ref}" --function git_cached_clon) endif() - popd() + popd() + set(result "${target_dir}") + endif() + popd() - return_ref(result) + return_ref(result) - endfunction() \ No newline at end of file +endfunction() \ No newline at end of file diff --git a/tests/vcs/git/git_cached_clone_test.cmake b/tests/vcs/git/git_cached_clone_test.cmake index 65501989..46d8361b 100644 --- a/tests/vcs/git/git_cached_clone_test.cmake +++ b/tests/vcs/git/git_cached_clone_test.cmake @@ -2,19 +2,29 @@ function(test) timer_start(timer1) git_cached_clone("https://github.com/toeb/cmakepp" "dir1") + rethrow(true) timer_print_elapsed(timer1) timer_start(timer2) git_cached_clone("https://github.com/toeb/cmakepp" "dir2") + rethrow(true) timer_print_elapsed(timer2) + ## reclone + timer_start(timer22) + git_cached_clone("https://github.com/toeb/cmakepp" "dir2") + ans(res) + timer_print_elapsed(timer22) + assert(NOT res) + timer_start(timer3) git_cached_clone("https://github.com/toeb/cmakepp" "dir2" --read package.cmake) + rethrow(true) ans(res) assert(res) timer_print_elapsed(timer3) - message("${res}") + message("res ${res}") From 058fff45cc09c818df582aea5e9c6f8c2a48da87 Mon Sep 17 00:00:00 2001 From: Tobias Becker Date: Tue, 12 May 2015 22:26:43 +0200 Subject: [PATCH 04/10] removed unnecessary functions --- cmake/core/dbg.cmake | 46 --------------------------- cmake/core/err.cmake | 0 cmake/debugging/breakpoint.cmake | 36 --------------------- cmake/filesystem/file_map_write.cmake | 1 - cmake/filesystem/fwrite_temp.cmake | 1 - 5 files changed, 84 deletions(-) delete mode 100644 cmake/core/dbg.cmake delete mode 100644 cmake/core/err.cmake delete mode 100644 cmake/debugging/breakpoint.cmake diff --git a/cmake/core/dbg.cmake b/cmake/core/dbg.cmake deleted file mode 100644 index b9b3393d..00000000 --- a/cmake/core/dbg.cmake +++ /dev/null @@ -1,46 +0,0 @@ -function(dbg) - set(args ${ARGN}) - list_extract_flag(args --indented) - ans(indented) - if(NOT args) - set(last_return_value "${__ans}") - set(args last_return_value) - endif() - if("${args}") - is_map("${${args}}") - ans(ismap) - if(ismap) - if(indented) - json_indented("${${args}}") - else() - json("${${args}}") - endif() - ans("${args}") - endif() - dbg("${args}: '${${args}}'") - return() - endif() - list_length(args) - ans(len) - if("${len}" EQUAL 1) - is_map("${args}") - ans(ismap) - if(ismap) - if(indented) - json_indented("${args}") - else() - json("${args}") - endif() - ans("${args}") - - endif() - message(FORMAT "dbg (${__function_call_func}): '${args}'") - return() - endif() - - foreach(arg ${args}) - dbg("${arg}") - endforeach() - - return() -endfunction() \ No newline at end of file diff --git a/cmake/core/err.cmake b/cmake/core/err.cmake deleted file mode 100644 index e69de29b..00000000 diff --git a/cmake/debugging/breakpoint.cmake b/cmake/debugging/breakpoint.cmake deleted file mode 100644 index f3647888..00000000 --- a/cmake/debugging/breakpoint.cmake +++ /dev/null @@ -1,36 +0,0 @@ -# creates a breakpoint -# usage: breakpoint(${CMAKE_CURRENT_LIST_FILE} ${CMAKE_CURRENT_LIST_LINE}) -function(breakpoint file line) - if(NOT DEBUG_CMAKE) - return() - endif() - message("breakpoint reached ${file}:${line}") - while(1) - echo_append("> ") - read_line() - ans(cmd) - if("${cmd}" STREQUAL "") - message("continuing execution") - break() - endif() - - - if("${cmd}" MATCHES "^\\$.*") - string(SUBSTRING "${cmd}" 1 -1 var) - - - get_cmake_property(_variableNames VARIABLES) - foreach(v ${_variableNames}) - if("${v}" MATCHES "${cmd}") - dbg("${v}") - - endif() - endforeach() - - endif() - - - - - endwhile() -endfunction() diff --git a/cmake/filesystem/file_map_write.cmake b/cmake/filesystem/file_map_write.cmake index 273e0db3..1ebc7f24 100644 --- a/cmake/filesystem/file_map_write.cmake +++ b/cmake/filesystem/file_map_write.cmake @@ -1,4 +1,3 @@ - ## writes a file_map to the pwd. ## empty directories are not created ## fm is parsed according to obj() diff --git a/cmake/filesystem/fwrite_temp.cmake b/cmake/filesystem/fwrite_temp.cmake index 5300ddb3..502e19c8 100644 --- a/cmake/filesystem/fwrite_temp.cmake +++ b/cmake/filesystem/fwrite_temp.cmake @@ -1,4 +1,3 @@ - ## ## ## creates a temporary file containing the specified content From c3b5e1cb29a43ff1a3d7c76fe823855a3c7668d8 Mon Sep 17 00:00:00 2001 From: Tobias Becker Date: Wed, 13 May 2015 22:26:01 +0200 Subject: [PATCH 05/10] added is_git_dir function and added a warning to pull_git --- .../git/package_source_pull_git.cmake | 45 +++++++++++-------- cmake/vcs/git/git_cached_clone.cmake | 6 ++- cmake/vcs/git/is_git_dir.cmake | 24 ++++++++++ 3 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 cmake/vcs/git/is_git_dir.cmake diff --git a/cmake/package/package_source/git/package_source_pull_git.cmake b/cmake/package/package_source/git/package_source_pull_git.cmake index dc47bd3a..afb88f73 100644 --- a/cmake/package/package_source/git/package_source_pull_git.cmake +++ b/cmake/package/package_source/git/package_source_pull_git.cmake @@ -2,31 +2,40 @@ ## ## pulls the package described by the uri into the target_dir ## e.g. package_source_pull_git("https://github.com/toeb/cutil.git?ref=devel") - function(package_source_pull_git uri) - set(args ${ARGN}) +function(package_source_pull_git uri) + set(args ${ARGN}) - list_pop_front(args) - ans(target_dir) + list_pop_front(args) + ans(target_dir) - path_qualify(target_dir) + path_qualify(target_dir) - package_source_resolve_git("${uri}") - ans(package_handle) + package_source_resolve_git("${uri}") + ans(package_handle) - if(NOT package_handle) - return() - endif() + if(NOT package_handle) + return() + endif() - assign(remote_uri = package_handle.scm_descriptor.ref.uri) - assign(revision = package_handle.scm_descriptor.ref.revision) + is_git_dir("${target_dir}") + ans(is_git) - git_cached_clone("${remote_uri}" "${target_dir}" --ref "${revision}" ${args}) - rethrow(true) - ans(target_dir) + if(is_git) + ## if directory exists then + ##http://stackoverflow.com/questions/2411031/how-do-i-clone-into-a-non-empty-directory + message(WARNING "this operation will fail because the directory already exists") + endif() - map_set(${package_handle} content_dir "${target_dir}") + assign(remote_uri = package_handle.scm_descriptor.ref.uri) + assign(revision = package_handle.scm_descriptor.ref.revision) - return_ref(package_handle) - endfunction() + git_cached_clone("${remote_uri}" "${target_dir}" --ref "${revision}" ${args}) + rethrow(true) + ans(target_dir) + + map_set(${package_handle} content_dir "${target_dir}") + + return_ref(package_handle) +endfunction() diff --git a/cmake/vcs/git/git_cached_clone.cmake b/cmake/vcs/git/git_cached_clone.cmake index a6760d37..4915781b 100644 --- a/cmake/vcs/git/git_cached_clone.cmake +++ b/cmake/vcs/git/git_cached_clone.cmake @@ -1,9 +1,13 @@ ## `(> [--readonly] ([--file <>]|[--read<>]) [--ref ])-> ` ## +## clones the specified remote repository to the specified target directory ## +## **flags** +## `--file ` +## `--read ` function(git_cached_clone remote_uri) set(args ${ARGN}) - + list_extract_flag(args --readonly) ans(readonly) diff --git a/cmake/vcs/git/is_git_dir.cmake b/cmake/vcs/git/is_git_dir.cmake new file mode 100644 index 00000000..d6e148a2 --- /dev/null +++ b/cmake/vcs/git/is_git_dir.cmake @@ -0,0 +1,24 @@ + +## `(?)->` +## +## returns true if the specified path is managed by git +## this is valid for all subdiretories of a git root as well +function(is_git_dir) + path("${ARGN}") + ans(path) + + if(NOT IS_DIRECTORY "${path}") + return(false) + endif() + pushd("${path}") + git_lean(status) + ans_extract(error) + + popd() + + if(error) + return(false) + endif() + + return(true) +endfunction() \ No newline at end of file From 96e4fdd11de28516f00928ae0323edcff9f66530 Mon Sep 17 00:00:00 2001 From: Tobias Becker Date: Mon, 18 May 2015 23:32:37 +0200 Subject: [PATCH 06/10] worked on fixign up package_source_pull_git --- .../git/package_source_pull_git.cmake | 17 ++++++++++++++--- .../project_package_descriptor_reader.cmake | 2 +- .../git/package_source_pull_git_test.cmake | 13 +++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/cmake/package/package_source/git/package_source_pull_git.cmake b/cmake/package/package_source/git/package_source_pull_git.cmake index afb88f73..4fd7db01 100644 --- a/cmake/package/package_source/git/package_source_pull_git.cmake +++ b/cmake/package/package_source/git/package_source_pull_git.cmake @@ -14,7 +14,7 @@ function(package_source_pull_git uri) ans(package_handle) if(NOT package_handle) - return() + return() endif() @@ -22,9 +22,20 @@ function(package_source_pull_git uri) ans(is_git) if(is_git) - ## if directory exists then + log("'${target_dir}' is already a git repository. checking if it is the same") + package_source_resolve_git("${target_dir}") + ans(target_repo) + assign(target_revision = target_repo.scm_descriptor.ref.revision) + assign(package_revision = package_handle.scm_descriptor.ref.revision) + if("${target_revision}_" STREQUAL "${package_revision}_") + log("'${target_dir}' is already a git repository is already up to date.") + map_set(${package_handle} content_dir "${target_dir}") + return_ref(package_handle) + endif() + log("removing '${target_dir}' because it is incompatible with {uri.uri}") + + rm(-r "${target_dir}") ##http://stackoverflow.com/questions/2411031/how-do-i-clone-into-a-non-empty-directory - message(WARNING "this operation will fail because the directory already exists") endif() assign(remote_uri = package_handle.scm_descriptor.ref.uri) diff --git a/cmake/package/project/extensions/package_descriptor/project_package_descriptor_reader.cmake b/cmake/package/project/extensions/package_descriptor/project_package_descriptor_reader.cmake index 731fde01..c44b248b 100644 --- a/cmake/package/project/extensions/package_descriptor/project_package_descriptor_reader.cmake +++ b/cmake/package/project/extensions/package_descriptor/project_package_descriptor_reader.cmake @@ -58,4 +58,4 @@ function(project_package_descriptor_initialize_new project) endfunction() -task_enqueue("[]() message(wot); event_addhandler(project_on_new project_package_descriptor_initialize_new)") \ No newline at end of file +task_enqueue("[]() event_addhandler(project_on_new project_package_descriptor_initialize_new)") \ No newline at end of file diff --git a/tests/package/package_source_tests/git/package_source_pull_git_test.cmake b/tests/package/package_source_tests/git/package_source_pull_git_test.cmake index 3af64225..70cf283f 100644 --- a/tests/package/package_source_tests/git/package_source_pull_git_test.cmake +++ b/tests/package/package_source_tests/git/package_source_pull_git_test.cmake @@ -1,5 +1,18 @@ function(test) +## should be able to pull the correct repo + package_source_pull_git("https://github.com/toeb/cmakepp" "clone3") + package_source_pull_git("https://github.com/toeb/cmakepp" "clone3") + ans(res) + assertf("{res.content_dir}" STREQUAL "${test_dir}/clone3") + + + # package_source_pull_git("https://github.com/toeb/cmakepp" "clone3") + # package_source_pull_git("https://github.com/toeb/accounting" "clone3") + # ans(res) + # assert(res) + # todo: existing dir with no git, existing dir with git. ... + package_source_pull_git("https://github.com/toeb/cmakepp" "clone3") From ef80b87614f31e66f5ca0f10a080f40d47a9e8cd Mon Sep 17 00:00:00 2001 From: Tobias Becjer Date: Mon, 25 May 2015 15:07:54 +0200 Subject: [PATCH 07/10] minor changes --- cmake/csharp/csharp_project.cmake | 45 ++++++++++++++++++++++ cmake/process/process_execute.cmake | 21 +++++++--- cmake/process/process_start_info_new.cmake | 4 ++ cmake/string/string_repeat.cmake | 3 +- tests/string/string_repeat_test.cmake | 7 ++++ 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 cmake/csharp/csharp_project.cmake create mode 100644 tests/string/string_repeat_test.cmake diff --git a/cmake/csharp/csharp_project.cmake b/cmake/csharp/csharp_project.cmake new file mode 100644 index 00000000..64abf910 --- /dev/null +++ b/cmake/csharp/csharp_project.cmake @@ -0,0 +1,45 @@ +function(csharp_project name) + set(sources ${ARGN}) + message(csharp_project) +endfunction() + + +function(cmake_configure project_root) + set(args ${ARGN}) + + list_extract_flag(args --clean) + ans(clean) + + pushd("${project_root}") + ans(project_root) + + if(EXISTS "${project_root}" AND clean) + rm(-r build) + endif() + + pushd(--create build) + cmake(.. --passthru) + rethrow() + popd() + popd() + return() +endfunction() + + +function(cmake_build project_root) + message("starting build") + pushd("${project_root}") + ans(project_root) + if(NOT EXISTS "${project_root}/build") + cmake_configure("${project_root}" ${ARGN}) + rethrow() + endif() + pushd("build") + cmake(--build . --passthru) + rethrow() + popd() + popd() + + return() + endfunction() + diff --git a/cmake/process/process_execute.cmake b/cmake/process/process_execute.cmake index 1ff5b3e6..68495447 100644 --- a/cmake/process/process_execute.cmake +++ b/cmake/process/process_execute.cmake @@ -74,14 +74,24 @@ function(process_execute process_handle) set(timeout) endif() + map_tryget(${process_start_info} passthru) + ans(passthru) + + if(passthru) + set(output_vars) + else() + set(output_vars + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + ) + endif() #message("executing ${command} ${command_arguments_string}") set(eval_this " execute_process( COMMAND ${command} ${command_arguments_string} RESULT_VARIABLE exit_code - OUTPUT_VARIABLE stdout - ERROR_VARIABLE stderr + ${output_vars} WORKING_DIRECTORY ${cwd} ${timeout} ) @@ -94,9 +104,10 @@ function(process_execute process_handle) map_set(${process_handle} pid) endif() map_set(${process_handle} exit_code "${exit_code}") - map_set(${process_handle} stdout "${stdout}") - map_set(${process_handle} stderr "${stderr}") - + if(NOT passthru) + map_set(${process_handle} stdout "${stdout}") + map_set(${process_handle} stderr "${stderr}") + endif() ## change state process_handle_change_state(${process_handle} terminated) diff --git a/cmake/process/process_start_info_new.cmake b/cmake/process/process_start_info_new.cmake index 15524666..bd9676be 100644 --- a/cmake/process/process_start_info_new.cmake +++ b/cmake/process/process_start_info_new.cmake @@ -23,6 +23,9 @@ function(process_start_info_new) ans(working_directory) list_extract_any_labelled_value(arguments_list TIMEOUT) ans(timeout) + list_extract_flag(arguments_list --passthru) + ans(passthru) + if(NOT timeout) set(timeout -1) @@ -47,6 +50,7 @@ function(process_start_info_new) map_set(${process_start_info} command_arguments "${arguments_list}") map_set(${process_start_info} working_directory "${working_directory}") map_set(${process_start_info} timeout "${timeout}") + map_set(${process_start_info} passthru ${passthru}) return_ref(process_start_info) endfunction() diff --git a/cmake/string/string_repeat.cmake b/cmake/string/string_repeat.cmake index 49aa320d..4224f661 100644 --- a/cmake/string/string_repeat.cmake +++ b/cmake/string/string_repeat.cmake @@ -7,9 +7,10 @@ endif() foreach(i RANGE 1 ${n}) if(NOT ${i} EQUAL 1) - set(res "${separator}${res}") + set(res "${res}${separator}") endif() set(res "${res}${what}") + _message("${separator} _ ${what} _ ${n} _ ${res}") endforeach() return_ref(res) endfunction() diff --git a/tests/string/string_repeat_test.cmake b/tests/string/string_repeat_test.cmake new file mode 100644 index 00000000..c5eeb1cd --- /dev/null +++ b/tests/string/string_repeat_test.cmake @@ -0,0 +1,7 @@ +function(test) + + + string_repeat("a" "3" "-") + ans(res) + message("${res}") +endfunction() \ No newline at end of file From 22c62733f38916977249441a320eb59207182084 Mon Sep 17 00:00:00 2001 From: Tobias Becker Date: Wed, 12 Aug 2015 17:18:30 +0200 Subject: [PATCH 08/10] worked on promises --- cmake/function/arguments_cmake_code.cmake | 2 +- cmake/task/promise.cmake | 2 + cmake/task/promise_continuation_resolve.cmake | 1 + cmake/task/promise_execute.cmake | 20 +++++++- cmake/task/promise_start.cmake | 9 ++++ cmake/task/task_invoke.cmake | 1 + tests/promises/promises_test.cmake | 49 ++++++++++++++++++- 7 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 cmake/task/promise_start.cmake diff --git a/cmake/function/arguments_cmake_code.cmake b/cmake/function/arguments_cmake_code.cmake index 75482aa3..3a290f03 100644 --- a/cmake/function/arguments_cmake_code.cmake +++ b/cmake/function/arguments_cmake_code.cmake @@ -19,7 +19,7 @@ macro(arguments_cmake_code __args_start __args_end) endif() else() - if("${__args_current_token}" MATCHES "[ \\$\"\\(\\)#\\^\t\r\n\\\;]") + if("_${__args_current_token}" MATCHES "[ \\$\"\\(\\)#\\^\t\r\n\\\;]") ## encoded list encode cmake string... ## @ todo this has to be extracted however it does not work correctly because ## of macro evaluation when using cmake_string_escape2 diff --git a/cmake/task/promise.cmake b/cmake/task/promise.cmake index bdc84e82..1ead5fff 100644 --- a/cmake/task/promise.cmake +++ b/cmake/task/promise.cmake @@ -26,3 +26,5 @@ function(promise) return_ref(promise) endfunction() + + diff --git a/cmake/task/promise_continuation_resolve.cmake b/cmake/task/promise_continuation_resolve.cmake index 93f7efb6..0102508e 100644 --- a/cmake/task/promise_continuation_resolve.cmake +++ b/cmake/task/promise_continuation_resolve.cmake @@ -1,3 +1,4 @@ + ## `()->` ## ## internal function which resolves a continuation diff --git a/cmake/task/promise_execute.cmake b/cmake/task/promise_execute.cmake index 45515c96..09d6d182 100644 --- a/cmake/task/promise_execute.cmake +++ b/cmake/task/promise_execute.cmake @@ -5,13 +5,31 @@ function(promise_execute) () process_isrunning("${process_handle}") ans(still_running) + message("${process_handle} - ${still_running}") + if(still_running) map_tryget("\${task}" task_queue) ans(task_queue) task_queue_push("\${task_queue}" "\${task}") - return() + task_yield() endif() return("${process_handle}") ) return_ans() +endfunction() + + +macro(task_yield) + address_new() + + eval("macro(task_yield) \n message(yielding) \n set(__ans ${__ans}) \n _return()\n endmacro()") + task_yield() +endmacro() +function(task_yield_token) + task_yield() +endfunction() + +function(promise_then_execute promise) + promise_then_anonymous(${promise} () promise_execute(${ARGN}) return_ans()) + return_ans() endfunction() \ No newline at end of file diff --git a/cmake/task/promise_start.cmake b/cmake/task/promise_start.cmake new file mode 100644 index 00000000..bd79f3f4 --- /dev/null +++ b/cmake/task/promise_start.cmake @@ -0,0 +1,9 @@ +## `(~)-> ` +## +## initializes the specified promise by adding it to its task queue +function(promise_start promise) + promise("${promise}") + ans(promise) + continuation_resolve("" "${promise}") + return(${promise}) +endfunction() diff --git a/cmake/task/task_invoke.cmake b/cmake/task/task_invoke.cmake index af9b6611..00418275 100644 --- a/cmake/task/task_invoke.cmake +++ b/cmake/task/task_invoke.cmake @@ -12,6 +12,7 @@ function(task_invoke task) ans(arguments) call2("${callable}" ${arguments}) ans(res) + map_set(${task} return_value ${res}) return_ref(res) diff --git a/tests/promises/promises_test.cmake b/tests/promises/promises_test.cmake index 10fafb61..2ea5e4f1 100644 --- a/tests/promises/promises_test.cmake +++ b/tests/promises/promises_test.cmake @@ -2,6 +2,41 @@ function(test) + promise_from_anonymous(() message("before_start") timer_start(t1)) + ans(p3) + message("1 ${p3}") + promise_start(${p3}) + promise_then_execute(${p3} COMMAND ${CMAKE_COMMAND} -E sleep 1) + ans(p3) + message("1 ${p3}") + + promise_wait(${p3}) + ans(result) + + + return() + + + promise_then_anonymous(${p3} () message(after_start) timer_print_elapsed(t1) json_print(\${ARGN})) + ans(p3) + + + +return() + + promise_from_anonymous(() return(1)) + ans(uut) + + + promise_start(${uut}) + + promise_wait(${uut}) + ans(value) + + assert(${value} STREQUAL 1) + + + ## promise_then_anonymous("1" () math(EXPR i "\${ARGN} + \${ARGN}") return(\${i})) ans(promise) @@ -137,14 +172,26 @@ function(test) promise_execute(COMMAND ${CMAKE_COMMAND} -E sleep 4) ans(p2) - promise_execute(COMMAND ${CMAKE_COMMAND} -E sleep 5) + + promise_from_anonymous(() message("before_start") timer_start(t1)) + ans(p3) + promise_start(${p3}) + promise_wait(${p3}) + promise_then_execute(${p3} COMMAND ${CMAKE_COMMAND} -E sleep 1) ans(p3) + promise_then_anonymous(${p3} () message(after_start) timer_print_elapsed(t1) json_print(\${ARGN})) + ans(p3) + promise_then_anonymous(${p3} () message(number3finished)) + ans(p3) promise_all("${p1}" "${p2}" "${p3}") ans(p4) promise_wait("${p4}") + + + From 90d8449fb3976d5776814048ccb7805ccf457a26 Mon Sep 17 00:00:00 2001 From: Tobias Becker Date: Sat, 15 Aug 2015 13:52:35 +0200 Subject: [PATCH 09/10] continiued work --- cmake/task/promise.cmake | 15 +++++++++++++-- cmake/task/task_invoke.cmake | 2 -- tests/promises/promises_test.cmake | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/cmake/task/promise.cmake b/cmake/task/promise.cmake index 1ead5fff..e71dc151 100644 --- a/cmake/task/promise.cmake +++ b/cmake/task/promise.cmake @@ -16,8 +16,19 @@ function(promise) promise_from_task("${promise}") ans(promise) else() - promise_from_value("${promise}") - ans(promise) + is_anonymous_function(${ARGN}) + ans(is_anonymous_function) + if( is_anonymous_function) + arguments_anonymous_function(0 ${ARGC}) + ans(function) + promise_from_callable("${function}") + ans(promise) + else() + promise_from_value("${promise}") + ans(promise) + endif() + + endif() endif() task_queue_global() diff --git a/cmake/task/task_invoke.cmake b/cmake/task/task_invoke.cmake index 00418275..fa6be1ed 100644 --- a/cmake/task/task_invoke.cmake +++ b/cmake/task/task_invoke.cmake @@ -12,8 +12,6 @@ function(task_invoke task) ans(arguments) call2("${callable}" ${arguments}) ans(res) - - map_set(${task} return_value ${res}) return_ref(res) endfunction() diff --git a/tests/promises/promises_test.cmake b/tests/promises/promises_test.cmake index 2ea5e4f1..270331b1 100644 --- a/tests/promises/promises_test.cmake +++ b/tests/promises/promises_test.cmake @@ -1,6 +1,21 @@ function(test) + promise(() return(20) ) + ans(p1) + + promise_start("${p1}") + + message("p1 ${p1}") + ans(p2) + + json_print(${p1}) + + message("p1 ${p2}") + + return() + + promise_from_anonymous(() message("before_start") timer_start(t1)) ans(p3) From ecd50c6bb8acd7f581157fa6c7c9f55a91d801f4 Mon Sep 17 00:00:00 2001 From: Tobias Becker Date: Tue, 25 Aug 2015 22:35:18 +0200 Subject: [PATCH 10/10] ... --- tests/promises/promises_test.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/promises/promises_test.cmake b/tests/promises/promises_test.cmake index 270331b1..e375d1ce 100644 --- a/tests/promises/promises_test.cmake +++ b/tests/promises/promises_test.cmake @@ -7,6 +7,7 @@ function(test) promise_start("${p1}") message("p1 ${p1}") + promise_wait("${p1}") ans(p2) json_print(${p1})