From 10e77770399d5f7c84bb365d56a012b65ba512df Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Tue, 17 Jun 2014 14:09:40 -0700 Subject: AVD/SDK Launchers win build. Change-Id: Iacff7f6bfe95a2a95b85cf00cd3e2dd34e5358b6 --- avdlauncher/Android.mk | 2 +- avdlauncher/avdlauncher.c | 134 ------------------------------ avdlauncher/build.gradle | 36 ++++++++ avdlauncher/src/source/avdlauncher.c | 134 ++++++++++++++++++++++++++++++ sdklauncher/Android.mk | 2 +- sdklauncher/build.gradle | 36 ++++++++ sdklauncher/sdklauncher.c | 154 ----------------------------------- sdklauncher/src/source/sdklauncher.c | 154 +++++++++++++++++++++++++++++++++++ 8 files changed, 362 insertions(+), 290 deletions(-) delete mode 100644 avdlauncher/avdlauncher.c create mode 100644 avdlauncher/build.gradle create mode 100644 avdlauncher/src/source/avdlauncher.c create mode 100644 sdklauncher/build.gradle delete mode 100644 sdklauncher/sdklauncher.c create mode 100644 sdklauncher/src/source/sdklauncher.c diff --git a/avdlauncher/Android.mk b/avdlauncher/Android.mk index fb48e15..97b6d73 100644 --- a/avdlauncher/Android.mk +++ b/avdlauncher/Android.mk @@ -16,7 +16,7 @@ include $(CLEAR_VARS) ifeq ($(HOST_OS),windows) LOCAL_SRC_FILES := \ - avdlauncher.c + src/source/avdlauncher.c LOCAL_CFLAGS += -Wall -Wno-unused-parameter LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE -DSH_HISTORY diff --git a/avdlauncher/avdlauncher.c b/avdlauncher/avdlauncher.c deleted file mode 100644 index 12b1285..0000000 --- a/avdlauncher/avdlauncher.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * The "AVD Manager" is for Windows only. - * This simple .exe will sit at the root of the Windows SDK - * and currently simply executes tools\android.bat. - * - * TODO: replace by a jar-exe wrapper. - */ - -#ifdef _WIN32 - -#include -#include -#include -#include - - -int _enable_dprintf = 0; - -void dprintf(char *msg, ...) { - va_list ap; - va_start(ap, msg); - - if (_enable_dprintf) { - vfprintf(stderr, msg, ap); - } - - va_end(ap); -} - -void display_error(LPSTR description) { - DWORD err = GetLastError(); - LPSTR s, s2; - - fprintf(stderr, "%s, error %ld\n", description, err); - - if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | /* dwFlags */ - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, /* lpSource */ - err, /* dwMessageId */ - 0, /* dwLanguageId */ - (LPSTR)&s, /* lpBuffer */ - 0, /* nSize */ - NULL) != 0) { /* va_list args */ - fprintf(stderr, "%s", s); - - s2 = (LPSTR) malloc(strlen(description) + strlen(s) + 5); - sprintf(s2, "%s\r\n%s", description, s); - MessageBox(NULL, s2, "Android AVD Manager - Error", MB_OK); - free(s2); - LocalFree(s); - } -} - - -int avd_launcher() { - int result = 0; - STARTUPINFO startup; - PROCESS_INFORMATION pinfo; - CHAR program_dir[MAX_PATH]; - int ret, pos; - - ZeroMemory(&pinfo, sizeof(pinfo)); - - ZeroMemory(&startup, sizeof(startup)); - startup.cb = sizeof(startup); - startup.dwFlags = STARTF_USESHOWWINDOW; - startup.wShowWindow = SW_HIDE|SW_MINIMIZE; - - /* get path of current program, to switch dirs here when executing the command. */ - ret = GetModuleFileName(NULL, program_dir, sizeof(program_dir)); - if (ret == 0) { - display_error("Failed to get program's filename:"); - result = 1; - } else { - /* Remove the last segment to keep only the directory. */ - pos = ret - 1; - while (pos > 0 && program_dir[pos] != '\\') { - --pos; - } - program_dir[pos] = 0; - } - - if (!result) { - dprintf("Program dir: %s\n", program_dir); - - ret = CreateProcess( - NULL, /* program path */ - "tools\\android.bat avd", /* command-line */ - NULL, /* process handle is not inheritable */ - NULL, /* thread handle is not inheritable */ - TRUE, /* yes, inherit some handles */ - CREATE_NO_WINDOW, /* we don't want a console */ - NULL, /* use parent's environment block */ - program_dir, /* use parent's starting directory */ - &startup, /* startup info, i.e. std handles */ - &pinfo); - - dprintf("CreateProcess returned %d\n", ret); - - if (!ret) { - display_error("Failed to execute tools\\android.bat:"); - result = 1; - } - } - - dprintf("Cleanup.\n"); - - return result; -} - -int main(int argc, char **argv) { - _enable_dprintf = argc > 1 && strcmp(argv[1], "-v") == 0; - dprintf("Verbose debug mode.\n"); - - return avd_launcher(); -} - -#endif /* _WIN32 */ diff --git a/avdlauncher/build.gradle b/avdlauncher/build.gradle new file mode 100644 index 0000000..d796c69 --- /dev/null +++ b/avdlauncher/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'c' +apply plugin: 'sdk-files' +apply plugin: 'windows-setup' + +executables { + avdLauncher {} +} + +sources { + avdLauncher { + c { + source { + srcDir "src/source" + include "**/*.c" + } + } + } +} + +sdk { + windows { + item( { getExeName("windows") } ) { + into 'lib' + name 'AVD Launcher.exe' + builtBy 'avdLauncherExecutable' + } + } +} + +def getExeName(String platform) { + // binaries will return a set of binaries + def binaries = executables.avdLauncher.binaries.matching { it.name == "avdLauncherExecutable" } + // calling .exeFile on the set returns an array with the result from each item in the set... + return binaries.executableFile.get(0) +} + diff --git a/avdlauncher/src/source/avdlauncher.c b/avdlauncher/src/source/avdlauncher.c new file mode 100644 index 0000000..12b1285 --- /dev/null +++ b/avdlauncher/src/source/avdlauncher.c @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * The "AVD Manager" is for Windows only. + * This simple .exe will sit at the root of the Windows SDK + * and currently simply executes tools\android.bat. + * + * TODO: replace by a jar-exe wrapper. + */ + +#ifdef _WIN32 + +#include +#include +#include +#include + + +int _enable_dprintf = 0; + +void dprintf(char *msg, ...) { + va_list ap; + va_start(ap, msg); + + if (_enable_dprintf) { + vfprintf(stderr, msg, ap); + } + + va_end(ap); +} + +void display_error(LPSTR description) { + DWORD err = GetLastError(); + LPSTR s, s2; + + fprintf(stderr, "%s, error %ld\n", description, err); + + if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | /* dwFlags */ + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, /* lpSource */ + err, /* dwMessageId */ + 0, /* dwLanguageId */ + (LPSTR)&s, /* lpBuffer */ + 0, /* nSize */ + NULL) != 0) { /* va_list args */ + fprintf(stderr, "%s", s); + + s2 = (LPSTR) malloc(strlen(description) + strlen(s) + 5); + sprintf(s2, "%s\r\n%s", description, s); + MessageBox(NULL, s2, "Android AVD Manager - Error", MB_OK); + free(s2); + LocalFree(s); + } +} + + +int avd_launcher() { + int result = 0; + STARTUPINFO startup; + PROCESS_INFORMATION pinfo; + CHAR program_dir[MAX_PATH]; + int ret, pos; + + ZeroMemory(&pinfo, sizeof(pinfo)); + + ZeroMemory(&startup, sizeof(startup)); + startup.cb = sizeof(startup); + startup.dwFlags = STARTF_USESHOWWINDOW; + startup.wShowWindow = SW_HIDE|SW_MINIMIZE; + + /* get path of current program, to switch dirs here when executing the command. */ + ret = GetModuleFileName(NULL, program_dir, sizeof(program_dir)); + if (ret == 0) { + display_error("Failed to get program's filename:"); + result = 1; + } else { + /* Remove the last segment to keep only the directory. */ + pos = ret - 1; + while (pos > 0 && program_dir[pos] != '\\') { + --pos; + } + program_dir[pos] = 0; + } + + if (!result) { + dprintf("Program dir: %s\n", program_dir); + + ret = CreateProcess( + NULL, /* program path */ + "tools\\android.bat avd", /* command-line */ + NULL, /* process handle is not inheritable */ + NULL, /* thread handle is not inheritable */ + TRUE, /* yes, inherit some handles */ + CREATE_NO_WINDOW, /* we don't want a console */ + NULL, /* use parent's environment block */ + program_dir, /* use parent's starting directory */ + &startup, /* startup info, i.e. std handles */ + &pinfo); + + dprintf("CreateProcess returned %d\n", ret); + + if (!ret) { + display_error("Failed to execute tools\\android.bat:"); + result = 1; + } + } + + dprintf("Cleanup.\n"); + + return result; +} + +int main(int argc, char **argv) { + _enable_dprintf = argc > 1 && strcmp(argv[1], "-v") == 0; + dprintf("Verbose debug mode.\n"); + + return avd_launcher(); +} + +#endif /* _WIN32 */ diff --git a/sdklauncher/Android.mk b/sdklauncher/Android.mk index 6b317a5..3d5a989 100644 --- a/sdklauncher/Android.mk +++ b/sdklauncher/Android.mk @@ -16,7 +16,7 @@ include $(CLEAR_VARS) ifeq ($(HOST_OS),windows) LOCAL_SRC_FILES := \ - sdklauncher.c + src/source/sdklauncher.c LOCAL_CFLAGS += -Wall -Wno-unused-parameter LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE -DSH_HISTORY diff --git a/sdklauncher/build.gradle b/sdklauncher/build.gradle new file mode 100644 index 0000000..48ef10a --- /dev/null +++ b/sdklauncher/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'c' +apply plugin: 'sdk-files' +apply plugin: 'windows-setup' + +executables { + sdkLauncher {} +} + +sources { + sdkLauncher { + c { + source { + srcDir "src/source" + include "**/*.c" + } + } + } +} + +sdk { + windows { + item( { getExeName("windows") } ) { + into 'lib' + name 'SDK Launcher.exe' + builtBy 'sdkLauncherExecutable' + } + } +} + +def getExeName(String platform) { + // binaries will return a set of binaries + def binaries = executables.sdkLauncher.binaries.matching { it.name == "sdkLauncherExecutable" } + // calling .exeFile on the set returns an array with the result from each item in the set... + return binaries.executableFile.get(0) +} + diff --git a/sdklauncher/sdklauncher.c b/sdklauncher/sdklauncher.c deleted file mode 100644 index 6b2c45c..0000000 --- a/sdklauncher/sdklauncher.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * The "SDK Manager" is for Windows only. - * This simple .exe will sit at the root of the Windows SDK - * and currently simply executes tools\android.bat. - * - * TODO: replace by a jar-exe wrapper. - */ - -#ifdef _WIN32 - -#include -#include -#include -#include - - -int _enable_dprintf = 0; - -void dprintf(char *msg, ...) { - va_list ap; - va_start(ap, msg); - - if (_enable_dprintf) { - vfprintf(stderr, msg, ap); - } - - va_end(ap); -} - -void display_error(LPSTR description) { - DWORD err = GetLastError(); - LPSTR s, s2; - - fprintf(stderr, "%s, error %ld\n", description, err); - - if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | /* dwFlags */ - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, /* lpSource */ - err, /* dwMessageId */ - 0, /* dwLanguageId */ - (LPSTR)&s, /* lpBuffer */ - 0, /* nSize */ - NULL) != 0) { /* va_list args */ - fprintf(stderr, "%s", s); - - s2 = (LPSTR) malloc(strlen(description) + strlen(s) + 5); - sprintf(s2, "%s\r\n%s", description, s); - MessageBox(NULL, s2, "Android SDK Manager - Error", MB_OK); - free(s2); - LocalFree(s); - } -} - - -int sdk_launcher() { - int result = 0; - STARTUPINFO startup; - PROCESS_INFORMATION pinfo; - CHAR program_dir[MAX_PATH]; - int ret, pos; - - ZeroMemory(&pinfo, sizeof(pinfo)); - - ZeroMemory(&startup, sizeof(startup)); - startup.cb = sizeof(startup); - startup.dwFlags = STARTF_USESHOWWINDOW; - startup.wShowWindow = SW_HIDE|SW_MINIMIZE; - - /* get path of current program, to switch dirs here when executing the command. */ - ret = GetModuleFileName(NULL, program_dir, sizeof(program_dir)); - if (ret == 0) { - display_error("Failed to get program's filename:"); - result = 1; - } else { - /* Remove the last segment to keep only the directory. */ - pos = ret - 1; - while (pos > 0 && program_dir[pos] != '\\') { - --pos; - } - program_dir[pos] = 0; - } - - if (!result) { - dprintf("Program dir: %s\n", program_dir); - - // SDK Manager.exe is installed by the Windows Installer just below - // the tools directory and needs to access tools\android.bat - ret = CreateProcess( - NULL, /* program path */ - "tools\\android.bat sdk", /* command-line */ - NULL, /* process handle is not inheritable */ - NULL, /* thread handle is not inheritable */ - TRUE, /* yes, inherit some handles */ - CREATE_NO_WINDOW, /* we don't want a console */ - NULL, /* use parent's environment block */ - program_dir, /* use parent's starting directory */ - &startup, /* startup info, i.e. std handles */ - &pinfo); - - if (!ret) { - dprintf("CreateProcess returned %d\n", ret); - - // In the ADT bundle, SDK Manager.exe is located in the sdk folder - // and needs to access sdk\tools\android.bat - ret = CreateProcess( - NULL, /* program path */ - "sdk\\tools\\android.bat sdk", /* command-line */ - NULL, /* process handle is not inheritable */ - NULL, /* thread handle is not inheritable */ - TRUE, /* yes, inherit some handles */ - CREATE_NO_WINDOW, /* we don't want a console */ - NULL, /* use parent's environment block */ - program_dir, /* use parent's starting directory */ - &startup, /* startup info, i.e. std handles */ - &pinfo); - } - - dprintf("CreateProcess returned %d\n", ret); - - if (!ret) { - display_error("Failed to execute tools\\android.bat:"); - result = 1; - } - } - - dprintf("Cleanup.\n"); - - return result; -} - -int main(int argc, char **argv) { - _enable_dprintf = argc > 1 && strcmp(argv[1], "-v") == 0; - dprintf("Verbose debug mode.\n"); - - return sdk_launcher(); -} - -#endif /* _WIN32 */ diff --git a/sdklauncher/src/source/sdklauncher.c b/sdklauncher/src/source/sdklauncher.c new file mode 100644 index 0000000..6b2c45c --- /dev/null +++ b/sdklauncher/src/source/sdklauncher.c @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * The "SDK Manager" is for Windows only. + * This simple .exe will sit at the root of the Windows SDK + * and currently simply executes tools\android.bat. + * + * TODO: replace by a jar-exe wrapper. + */ + +#ifdef _WIN32 + +#include +#include +#include +#include + + +int _enable_dprintf = 0; + +void dprintf(char *msg, ...) { + va_list ap; + va_start(ap, msg); + + if (_enable_dprintf) { + vfprintf(stderr, msg, ap); + } + + va_end(ap); +} + +void display_error(LPSTR description) { + DWORD err = GetLastError(); + LPSTR s, s2; + + fprintf(stderr, "%s, error %ld\n", description, err); + + if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | /* dwFlags */ + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, /* lpSource */ + err, /* dwMessageId */ + 0, /* dwLanguageId */ + (LPSTR)&s, /* lpBuffer */ + 0, /* nSize */ + NULL) != 0) { /* va_list args */ + fprintf(stderr, "%s", s); + + s2 = (LPSTR) malloc(strlen(description) + strlen(s) + 5); + sprintf(s2, "%s\r\n%s", description, s); + MessageBox(NULL, s2, "Android SDK Manager - Error", MB_OK); + free(s2); + LocalFree(s); + } +} + + +int sdk_launcher() { + int result = 0; + STARTUPINFO startup; + PROCESS_INFORMATION pinfo; + CHAR program_dir[MAX_PATH]; + int ret, pos; + + ZeroMemory(&pinfo, sizeof(pinfo)); + + ZeroMemory(&startup, sizeof(startup)); + startup.cb = sizeof(startup); + startup.dwFlags = STARTF_USESHOWWINDOW; + startup.wShowWindow = SW_HIDE|SW_MINIMIZE; + + /* get path of current program, to switch dirs here when executing the command. */ + ret = GetModuleFileName(NULL, program_dir, sizeof(program_dir)); + if (ret == 0) { + display_error("Failed to get program's filename:"); + result = 1; + } else { + /* Remove the last segment to keep only the directory. */ + pos = ret - 1; + while (pos > 0 && program_dir[pos] != '\\') { + --pos; + } + program_dir[pos] = 0; + } + + if (!result) { + dprintf("Program dir: %s\n", program_dir); + + // SDK Manager.exe is installed by the Windows Installer just below + // the tools directory and needs to access tools\android.bat + ret = CreateProcess( + NULL, /* program path */ + "tools\\android.bat sdk", /* command-line */ + NULL, /* process handle is not inheritable */ + NULL, /* thread handle is not inheritable */ + TRUE, /* yes, inherit some handles */ + CREATE_NO_WINDOW, /* we don't want a console */ + NULL, /* use parent's environment block */ + program_dir, /* use parent's starting directory */ + &startup, /* startup info, i.e. std handles */ + &pinfo); + + if (!ret) { + dprintf("CreateProcess returned %d\n", ret); + + // In the ADT bundle, SDK Manager.exe is located in the sdk folder + // and needs to access sdk\tools\android.bat + ret = CreateProcess( + NULL, /* program path */ + "sdk\\tools\\android.bat sdk", /* command-line */ + NULL, /* process handle is not inheritable */ + NULL, /* thread handle is not inheritable */ + TRUE, /* yes, inherit some handles */ + CREATE_NO_WINDOW, /* we don't want a console */ + NULL, /* use parent's environment block */ + program_dir, /* use parent's starting directory */ + &startup, /* startup info, i.e. std handles */ + &pinfo); + } + + dprintf("CreateProcess returned %d\n", ret); + + if (!ret) { + display_error("Failed to execute tools\\android.bat:"); + result = 1; + } + } + + dprintf("Cleanup.\n"); + + return result; +} + +int main(int argc, char **argv) { + _enable_dprintf = argc > 1 && strcmp(argv[1], "-v") == 0; + dprintf("Verbose debug mode.\n"); + + return sdk_launcher(); +} + +#endif /* _WIN32 */ -- cgit v1.1