2013-04-29 12:09:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-06-03 14:02:15 +00:00
|
|
|
void usage() {
|
|
|
|
printf("[USAGE] skia_launcher program_name [options]\n");
|
2013-04-29 12:09:31 +00:00
|
|
|
printf(" program_name: the skia program you want to launch (e.g. tests, bench)\n");
|
|
|
|
printf(" options: options specific to the program you are launching\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool file_exists(const char* fileName) {
|
|
|
|
FILE* file = fopen(fileName, "r");
|
|
|
|
if (file) {
|
|
|
|
fclose(file);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int launch_app(int (*app_main)(int, const char**), int argc,
|
|
|
|
const char** argv) {
|
|
|
|
return (*app_main)(argc, argv);
|
|
|
|
}
|
|
|
|
|
2013-06-03 14:02:15 +00:00
|
|
|
void* load_library(const char* appLocation, const char* libraryName)
|
2013-06-03 12:10:19 +00:00
|
|
|
{
|
|
|
|
// attempt to lookup the location of the shared libraries
|
|
|
|
char libraryLocation[100];
|
2014-04-09 23:38:57 +00:00
|
|
|
sprintf(libraryLocation, "%s/lib%s.so", appLocation, libraryName);
|
2013-06-03 12:10:19 +00:00
|
|
|
if (!file_exists(libraryLocation)) {
|
2013-06-03 14:51:14 +00:00
|
|
|
printf("ERROR: Unable to find the '%s' library in the Skia App.\n", libraryName);
|
2013-06-03 12:10:19 +00:00
|
|
|
printf("ERROR: Did you provide the correct program_name?\n");
|
2013-06-03 14:02:15 +00:00
|
|
|
usage();
|
2013-06-03 12:10:19 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// load the appropriate library
|
|
|
|
void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY);
|
|
|
|
if (!appLibrary) {
|
|
|
|
printf("ERROR: Unable to open the shared library.\n");
|
|
|
|
printf("ERROR: %s", dlerror());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return appLibrary;
|
|
|
|
}
|
|
|
|
|
2013-04-29 12:09:31 +00:00
|
|
|
int main(int argc, const char** argv) {
|
|
|
|
|
|
|
|
// check that the program name was specified
|
|
|
|
if (argc < 2) {
|
|
|
|
printf("ERROR: No program_name was specified\n");
|
2013-06-03 14:02:15 +00:00
|
|
|
usage();
|
2013-04-29 12:09:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// attempt to lookup the location of the skia app
|
2013-08-12 12:30:04 +00:00
|
|
|
const char* appLocation = "/data/local/tmp";
|
2013-04-29 12:09:31 +00:00
|
|
|
if (!file_exists(appLocation)) {
|
2013-08-12 12:30:04 +00:00
|
|
|
printf("ERROR: Unable to find /data/local/tmp on the device.\n");
|
2013-04-29 12:09:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-12-02 13:50:38 +00:00
|
|
|
#if defined(SKIA_DLL)
|
2013-06-03 12:10:19 +00:00
|
|
|
// load the local skia shared library
|
2016-04-18 19:57:35 +00:00
|
|
|
void* skiaLibrary = load_library(appLocation, "skia_android");
|
2013-06-03 12:10:19 +00:00
|
|
|
if (NULL == skiaLibrary)
|
|
|
|
{
|
2013-04-29 12:09:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-12-02 13:50:38 +00:00
|
|
|
#endif
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
// load the appropriate library
|
2013-06-03 14:02:15 +00:00
|
|
|
void* appLibrary = load_library(appLocation, argv[1]);
|
2013-06-03 12:10:19 +00:00
|
|
|
if (NULL == appLibrary) {
|
2013-04-29 12:09:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the address of the main function
|
|
|
|
int (*app_main)(int, const char**);
|
|
|
|
*(void **) (&app_main) = dlsym(appLibrary, "main");
|
|
|
|
|
|
|
|
if (!app_main) {
|
|
|
|
printf("ERROR: Unable to load the main function of the selected program.\n");
|
|
|
|
printf("ERROR: %s\n", dlerror());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// pass all additional arguments to the main function
|
|
|
|
return launch_app(app_main, argc - 1, ++argv);
|
|
|
|
}
|