[gjs] console: Env vars for coverage args



commit a8887e32286b4377cf9e80568ffbc778a0567af2
Author: Philip Chimento <philip endlessm com>
Date:   Mon Oct 31 15:10:26 2016 -0700

    console: Env vars for coverage args
    
    Encourage use of environment variables for coverage command line
    arguments, GJS_COVERAGE_PREFIXES instead of --coverage-prefix, and
    GJS_COVERAGE_OUTPUT instead of --coverage-output.
    
    This is because we want to pass arguments occurring after the script on
    the command line as arguments to the script and not to GJS. Without
    environment variables, it would otherwise be impossible to turn on
    coverage, for example, for a script that started with #!/usr/bin/gjs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772033

 gjs/console.cpp |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/gjs/console.cpp b/gjs/console.cpp
index 2472350..d60840b 100644
--- a/gjs/console.cpp
+++ b/gjs/console.cpp
@@ -121,7 +121,8 @@ check_script_args_for_stray_gjs_args(int           argc,
     if (new_coverage_prefixes != NULL) {
         g_warning("You used the --coverage-prefix option after the script on "
                   "the GJS command line. Support for this will be removed in a "
-                  "future version. Place the option before the script.");
+                  "future version. Place the option before the script or use "
+                  "the GJS_COVERAGE_PREFIXES environment variable.");
         char **old_coverage_prefixes = coverage_prefixes;
         coverage_prefixes = strcatv(old_coverage_prefixes, new_coverage_prefixes);
         g_strfreev(old_coverage_prefixes);
@@ -138,7 +139,8 @@ check_script_args_for_stray_gjs_args(int           argc,
     if (new_coverage_output_path != NULL) {
         g_warning("You used the --coverage-output option after the script on "
                   "the GJS command line. Support for this will be removed in a "
-                  "future version. Place the option before the script.");
+                  "future version. Place the option before the script or use "
+                  "the GJS_COVERAGE_OUTPUT environment variable.");
         g_free(coverage_output_path);
         coverage_output_path = new_coverage_output_path;
     }
@@ -162,6 +164,8 @@ main(int argc, char **argv)
     char **argv_copy = g_strdupv(argv), **argv_copy_addr = argv_copy;
     char **gjs_argv, **gjs_argv_addr;
     char * const *script_argv;
+    const char *env_coverage_output_path;
+    const char *env_coverage_prefixes;
 
     setlocale(LC_ALL, "");
 
@@ -243,6 +247,23 @@ main(int argc, char **argv)
                                             "program-name", program_name,
                                             NULL);
 
+    env_coverage_output_path = g_getenv("GJS_COVERAGE_OUTPUT");
+    if (env_coverage_output_path != NULL) {
+        g_free(coverage_output_path);
+        coverage_output_path = g_strdup(env_coverage_output_path);
+    }
+
+    env_coverage_prefixes = g_getenv("GJS_COVERAGE_PREFIXES");
+    if (env_coverage_prefixes != NULL) {
+        if (coverage_prefixes == NULL) {
+            coverage_prefixes = g_strdupv((char **) env_coverage_prefixes);
+        } else {
+            char **env_prefixes = g_strsplit(env_coverage_prefixes, ":", -1);
+            g_strfreev(coverage_prefixes);
+            coverage_prefixes = env_prefixes;
+        }
+    }
+
     if (coverage_prefixes) {
         if (!coverage_output_path)
             g_error("--coverage-output is required when taking coverage statistics");
@@ -282,7 +303,9 @@ main(int argc, char **argv)
     if (coverage && code == 0)
         gjs_coverage_write_statistics(coverage,
                                       coverage_output_path);
- 
+
+    g_free(coverage_output_path);
+    g_strfreev(coverage_prefixes);
     g_object_unref(js_context);
     g_free(script);
     exit(code);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]