From 9831560caf51e3029e34b24c05341e6a2ce68356 Mon Sep 17 00:00:00 2001 From: Daniel Zaoui Date: Tue, 28 Aug 2018 17:38:19 +0300 Subject: [PATCH] Use source codes stored in the unit as application This can be useful if the application is not in an official repository like elementary_test. This feature allows compiling the source code and using it to run the scenario on. The command (e.g gcc...) must be stored in the unit as well. $SRC and $DEST can be used to specify the source and destination files in the command. --- src/bin/exactness.c | 7 +++-- src/bin/player.c | 67 +++++++++++++++++++++++++++++++++------------ src/lib/Exactness.h | 8 ++++++ src/lib/unit.c | 8 ++++++ 4 files changed, 71 insertions(+), 19 deletions(-) diff --git a/src/bin/exactness.c b/src/bin/exactness.c index b46d64e..b9b9062 100644 --- a/src/bin/exactness.c +++ b/src/bin/exactness.c @@ -249,8 +249,11 @@ ok: if (_mode == RUN_INIT) eina_strbuf_append_printf(sbuf, "-o '%s/%s' ", _dest_dir, ORIG_SUBDIR); } - eina_strbuf_append(sbuf, "-- "); - eina_strbuf_append(sbuf, ent->command); + if (ent->command) + { + eina_strbuf_append(sbuf, "-- "); + eina_strbuf_append(sbuf, ent->command); + } strncpy(buf, eina_strbuf_string_get(sbuf), SCHEDULER_CMD_SIZE-1); eina_strbuf_free(sbuf); _printf(1, "Command: %s\n", buf); diff --git a/src/bin/player.c b/src/bin/player.c index e7d3dfe..afbd13f 100644 --- a/src/bin/player.c +++ b/src/bin/player.c @@ -9,6 +9,7 @@ #include #include +#include #include #ifdef HAVE_SYS_SYSINFO_H # include @@ -1100,12 +1101,6 @@ int main(int argc, char **argv) goto end; } - if (!argv[opt_args]) - { - fprintf(stderr, "no program specified\nUse -h for more information\n"); - goto end; - } - if (_dest_type == FTYPE_EXU) _dest_unit = calloc(1, sizeof(*_dest_unit)); if (!_src_open()) @@ -1158,21 +1153,59 @@ int main(int argc, char **argv) efl_object_init(); evas_init(); - /* Replace the current command line to hide the Exactness part */ - int len = argv[argc - 1] + strlen(argv[argc - 1]) - argv[opt_args]; - memcpy(argv[0], argv[opt_args], len); - memset(argv[0] + len, 0, _POSIX_PATH_MAX - len); - - int i; - for (i = opt_args; i < argc; i++) + if (argv[opt_args]) { - if (i != opt_args) + /* Replace the current command line to hide the Exactness part */ + int len = argv[argc - 1] + strlen(argv[argc - 1]) - argv[opt_args]; + memcpy(argv[0], argv[opt_args], len); + memset(argv[0] + len, 0, _POSIX_PATH_MAX - len); + + int i; + for (i = opt_args; i < argc; i++) { - argv[i - opt_args] = argv[0] + (argv[i] - argv[opt_args]); + if (i != opt_args) + { + argv[i - opt_args] = argv[0] + (argv[i] - argv[opt_args]); + } + _printf(1, "%s ", argv[i - opt_args]); } - _printf(1, "%s ", argv[i - opt_args]); + _printf(1, "\n"); } - _printf(1, "\n"); + else + { + Eina_List *itr; + Exactness_Source_Code *code; + Eina_Tmpstr *f_output = NULL; + EINA_LIST_FOREACH(_src_unit->codes, itr, code) + { + if (!strcmp(code->language, "C") && code->command) + { + int status; + Ecore_Exe *exe; + Eina_Tmpstr *f_code; + Eina_Strbuf *sbuf; + int fd_code = eina_file_mkstemp("exactness_XXXXXX.c", &f_code); + int fd_output = eina_file_mkstemp("exactness_XXXXXX.output", &f_output); + close(fd_output); + write(fd_code, code->content, strlen(code->content)); + close(fd_code); + + sbuf = eina_strbuf_new(); + eina_strbuf_append(sbuf, code->command); + eina_strbuf_replace_all(sbuf, "$SRC", f_code); + eina_strbuf_replace_all(sbuf, "$DEST", f_output); + exe = ecore_exe_pipe_run(eina_strbuf_string_get(sbuf), ECORE_EXE_NONE, NULL); + waitpid(ecore_exe_pid_get(exe), &status, 0); + } + } + if (!f_output) + { + fprintf(stderr, "no program specified\nUse -h for more information\n"); + goto end; + } + argv[0] = strdup(f_output); + } + ecore_evas_callback_new_set(_my_evas_new); if (_src_type != FTYPE_REMOTE) diff --git a/src/lib/Exactness.h b/src/lib/Exactness.h index 5392d04..090a3de 100644 --- a/src/lib/Exactness.h +++ b/src/lib/Exactness.h @@ -186,12 +186,20 @@ typedef struct void *pixels; /**< Pixels of the image */ } Exactness_Image; +typedef struct +{ + char *language; /**< String describing the language of the content e.g "C"...*/ + char *content; /**< Content used as source */ + char *command; /**< Command needed to generate the application from the content */ +} Exactness_Source_Code; + typedef struct { Eina_List *actions; /**< List of Exactness_Action */ /* imgs not in EET */ Eina_List *imgs; /**< List of Exactness_Image */ Eina_List *objs; /**< List of Exactness_Objects */ + Eina_List *codes; /**< List of Exactness_Source_Code */ const char *fonts_path; /**< Path to the fonts to use, relative to the fonts dir given in parameter to the player/recorder */ int nb_shots; /**< The number of shots present in the unit */ } Exactness_Unit; diff --git a/src/lib/unit.c b/src/lib/unit.c index 0977d86..a3d31e5 100644 --- a/src/lib/unit.c +++ b/src/lib/unit.c @@ -203,6 +203,13 @@ _unit_desc_make(void) } if (!unit_d) { + Eet_Data_Descriptor *code_d = NULL; + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Exactness_Source_Code); + code_d = eet_data_descriptor_stream_new(&eddc); + EET_DATA_DESCRIPTOR_ADD_BASIC(code_d, Exactness_Source_Code, "language", language, EET_T_STRING); + EET_DATA_DESCRIPTOR_ADD_BASIC(code_d, Exactness_Source_Code, "content", content, EET_T_STRING); + EET_DATA_DESCRIPTOR_ADD_BASIC(code_d, Exactness_Source_Code, "command", command, EET_T_STRING); + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Exactness_Action); action_d = eet_data_descriptor_stream_new(&eddc); @@ -243,6 +250,7 @@ _unit_desc_make(void) unit_d = eet_data_descriptor_stream_new(&eddc); EET_DATA_DESCRIPTOR_ADD_LIST(unit_d, Exactness_Unit, "actions", actions, action_d); EET_DATA_DESCRIPTOR_ADD_LIST(unit_d, Exactness_Unit, "objs", objs, objs_d); + EET_DATA_DESCRIPTOR_ADD_LIST(unit_d, Exactness_Unit, "codes", codes, code_d); EET_DATA_DESCRIPTOR_ADD_BASIC(unit_d, Exactness_Unit, "fonts_path", fonts_path, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(unit_d, Exactness_Unit, "nb_shots", nb_shots, EET_T_UINT); }