OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 | 10 |
11 #ifdef SK_BUILD_FOR_WIN | |
12 #define snprintf _snprintf | |
13 #endif | |
14 | |
15 void usage() { | 11 void usage() { |
16 printf("[USAGE] skia_launcher program_name [options]\n"); | 12 printf("[USAGE] skia_launcher program_name [options]\n"); |
17 printf(" program_name: the skia program you want to launch (e.g. tests, ben
ch)\n"); | 13 printf(" program_name: the skia program you want to launch (e.g. tests, ben
ch)\n"); |
18 printf(" options: options specific to the program you are launching\n"); | 14 printf(" options: options specific to the program you are launching\n"); |
19 } | 15 } |
20 | 16 |
21 bool file_exists(const char* fileName) { | 17 bool file_exists(const char* fileName) { |
22 FILE* file = fopen(fileName, "r"); | 18 FILE* file = fopen(fileName, "r"); |
23 if (file) { | 19 if (file) { |
24 fclose(file); | 20 fclose(file); |
25 return true; | 21 return true; |
26 } | 22 } |
27 return false; | 23 return false; |
28 } | 24 } |
29 | 25 |
30 int launch_app(int (*app_main)(int, const char**), int argc, | 26 int launch_app(int (*app_main)(int, const char**), int argc, |
31 const char** argv) { | 27 const char** argv) { |
32 return (*app_main)(argc, argv); | 28 return (*app_main)(argc, argv); |
33 } | 29 } |
34 | 30 |
35 void* load_library(const char* appLocation, const char* libraryName) | 31 void* load_library(const char* appLocation, const char* libraryName) |
36 { | 32 { |
37 // attempt to lookup the location of the shared libraries | 33 // attempt to lookup the location of the shared libraries |
38 char libraryLocation[100]; | 34 char libraryLocation[100]; |
39 snprintf(libraryLocation, SK_ARRAY_COUNT(libraryLocation), | 35 sprintf(libraryLocation, "%s/lib%s.so", appLocation, libraryName); |
40 "%s/lib%s.so", appLocation, libraryName); | |
41 if (!file_exists(libraryLocation)) { | 36 if (!file_exists(libraryLocation)) { |
42 printf("ERROR: Unable to find the '%s' library in the Skia App.\n", libr
aryName); | 37 printf("ERROR: Unable to find the '%s' library in the Skia App.\n", libr
aryName); |
43 printf("ERROR: Did you provide the correct program_name?\n"); | 38 printf("ERROR: Did you provide the correct program_name?\n"); |
44 usage(); | 39 usage(); |
45 return NULL; | 40 return NULL; |
46 } | 41 } |
47 | 42 |
48 // load the appropriate library | 43 // load the appropriate library |
49 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY); | 44 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY); |
50 if (!appLibrary) { | 45 if (!appLibrary) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 if (app_SkDebugToStdOut) { | 105 if (app_SkDebugToStdOut) { |
111 (*app_SkDebugToStdOut)(true); | 106 (*app_SkDebugToStdOut)(true); |
112 } else { | 107 } else { |
113 printf("WARNING: Unable to redirect output to the console.\n"); | 108 printf("WARNING: Unable to redirect output to the console.\n"); |
114 printf("WARNING: %s\n", dlerror()); | 109 printf("WARNING: %s\n", dlerror()); |
115 } | 110 } |
116 | 111 |
117 // pass all additional arguments to the main function | 112 // pass all additional arguments to the main function |
118 return launch_app(app_main, argc - 1, ++argv); | 113 return launch_app(app_main, argc - 1, ++argv); |
119 } | 114 } |
OLD | NEW |