diff options
-rw-r--r-- | files/ant_rules_r3.xml | 20 | ||||
-rw-r--r-- | sdklauncher/sdklauncher.c | 83 | ||||
-rw-r--r-- | sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java | 2 | ||||
-rw-r--r-- | sdkmanager/app/src/com/android/sdkmanager/Main.java | 12 | ||||
-rw-r--r-- | templates/build.template | 74 |
5 files changed, 128 insertions, 63 deletions
diff --git a/files/ant_rules_r3.xml b/files/ant_rules_r3.xml index 82abb6d..76f54e4 100644 --- a/files/ant_rules_r3.xml +++ b/files/ant_rules_r3.xml @@ -81,7 +81,7 @@ <property name="out.release.package" location="${out.absolute.dir}/${ant.project.name}-release.apk" /> - <!-- set some property used for filtering/override. If those weren't defined + <!-- set some properties used for filtering/override. If those weren't defined before, then this will create them with empty values, which are then ignored by the custom tasks receiving them. --> <property name="version.code" value="" /> @@ -216,8 +216,12 @@ <mkdir dir="${out.classes.absolute.dir}" /> </target> + <!-- empty default pre-build target. Create a similar target in + your build.xml and it'll be called instead of this one. --> + <target name="-pre-build"/> + <!-- Generates the R.java file for this project's resources. --> - <target name="-resource-src" depends="-dirs"> + <target name="-resource-src" depends="-dirs, -pre-build"> <echo>Generating R.java / Manifest.java from the resources...</echo> <aaptexec executable="${aapt}" command="package" @@ -242,8 +246,12 @@ </apply> </target> + <!-- empty default pre-compile target. Create a similar target in + your build.xml and it'll be called instead of this one. --> + <target name="-pre-compile"/> + <!-- Compiles this project's .java files into .class files. --> - <target name="compile" depends="-resource-src, -aidl" + <target name="compile" depends="-resource-src, -aidl, -pre-compile" description="Compiles project's .java files into .class files"> <!-- If android rules are used for a test project, its classpath should include tested project's location --> @@ -270,8 +278,12 @@ </javac> </target> + <!-- empty default post-compile target. Create a similar target in + your build.xml and it'll be called instead of this one. --> + <target name="-post-compile"/> + <!-- Converts this project's .class files into .dex files --> - <target name="-dex" depends="compile"> + <target name="-dex" depends="compile, -post-compile"> <dex-helper /> </target> diff --git a/sdklauncher/sdklauncher.c b/sdklauncher/sdklauncher.c index 23b785d..e1d97a1 100644 --- a/sdklauncher/sdklauncher.c +++ b/sdklauncher/sdklauncher.c @@ -29,9 +29,24 @@ #ifdef _WIN32 #include <stdio.h> +#include <stdarg.h> +#include <string.h> #include <windows.h> +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; @@ -170,8 +185,8 @@ int sdk_launcher() { int result = 0; STARTUPINFO startup; PROCESS_INFORMATION pinfo; - CHAR program_path[MAX_PATH]; - int ret; + CHAR program_dir[MAX_PATH]; + int ret, pos; CHAR temp_filename[MAX_PATH]; HANDLE temp_handle; @@ -189,29 +204,50 @@ int sdk_launcher() { startup.hStdOutput = temp_handle; startup.hStdError = temp_handle; - /* get path of current program */ - GetModuleFileName(NULL, program_path, sizeof(program_path)); - - ret = CreateProcess( - NULL, /* program path */ - "tools\\android.bat update 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 */ - NULL, /* use parent's starting directory */ - &startup, /* startup info, i.e. std handles */ - &pinfo); - - if (!ret) { - display_error("Failed to execute tools\\android.bat:"); + /* 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 { - WaitForSingleObject(pinfo.hProcess, INFINITE); - CloseHandle(pinfo.hProcess); - CloseHandle(pinfo.hThread); + /* 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 update 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; + } else { + dprintf("Wait for process to finish.\n"); + + WaitForSingleObject(pinfo.hProcess, INFINITE); + CloseHandle(pinfo.hProcess); + CloseHandle(pinfo.hThread); + } } + + dprintf("Cleanup.\n"); if (!CloseHandle(temp_handle)) { display_error("CloseHandle temp file failed"); @@ -229,6 +265,9 @@ int sdk_launcher() { } int main(int argc, char **argv) { + _enable_dprintf = argc > 1 && strcmp(argv[1], "-v") == 0; + dprintf("Verbose debug mode.\n"); + return sdk_launcher(); } diff --git a/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java b/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java index d24bed4..6536baa 100644 --- a/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java +++ b/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java @@ -115,7 +115,7 @@ class CommandLineProcessor { "Silent mode: only errors are printed out.", false); define(Mode.BOOLEAN, false, GLOBAL_FLAG_VERB, NO_VERB_OBJECT, "h", KEY_HELP, - "This help.", + "Help on a specific command.", false); } diff --git a/sdkmanager/app/src/com/android/sdkmanager/Main.java b/sdkmanager/app/src/com/android/sdkmanager/Main.java index 58a9a98..49eee7e 100644 --- a/sdkmanager/app/src/com/android/sdkmanager/Main.java +++ b/sdkmanager/app/src/com/android/sdkmanager/Main.java @@ -232,6 +232,10 @@ public class Main { updateTestProject(); } else if (SdkCommandLine.OBJECT_LIB_PROJECT.equals(directObject)) { updateProject(true /*library*/); + } else if (SdkCommandLine.OBJECT_SDK.equals(directObject)) { + showMainWindow(true /*autoUpdate*/); + } else if (SdkCommandLine.OBJECT_ADB.equals(directObject)) { + updateAdb(); } } else if (SdkCommandLine.VERB_DELETE.equals(verb) && SdkCommandLine.OBJECT_AVD.equals(directObject)) { @@ -244,14 +248,6 @@ public class Main { } else if (verb == null && directObject == null) { showMainWindow(false /*autoUpdate*/); - } else if (SdkCommandLine.VERB_UPDATE.equals(verb) && - SdkCommandLine.OBJECT_SDK.equals(directObject)) { - showMainWindow(true /*autoUpdate*/); - - } else if (SdkCommandLine.VERB_UPDATE.equals(verb) && - SdkCommandLine.OBJECT_ADB.equals(directObject)) { - updateAdb(); - } else { mSdkCommandLine.printHelpAndExit(null); } diff --git a/templates/build.template b/templates/build.template index 3959c57..549ce7c 100644 --- a/templates/build.template +++ b/templates/build.template @@ -1,40 +1,42 @@ <?xml version="1.0" encoding="UTF-8"?> <project name="PROJECT_NAME" default="help"> - <!-- The local.properties file is created and updated by the 'android' tool. - It contains the path to the SDK. It should *NOT* be checked in in Version - Control Systems. --> +<!-- The local.properties file is created and updated by the 'android' + tool. + It contains the path to the SDK. It should *NOT* be checked in in + Version Control Systems. --> <property file="local.properties" /> <!-- The build.properties file can be created by you and is never touched - by the 'android' tool. This is the place to change some of the default property values - used by the Ant rules. + by the 'android' tool. This is the place to change some of the + default property values used by the Ant rules. Here are some properties you may want to change/update: application.package - the name of your application package as defined in the manifest. Used by the - 'uninstall' rule. + The name of your application package as defined in the manifest. + Used by the 'uninstall' rule. source.dir - the name of the source directory. Default is 'src'. + The name of the source directory. Default is 'src'. out.dir - the name of the output directory. Default is 'bin'. + The name of the output directory. Default is 'bin'. - Properties related to the SDK location or the project target should be updated - using the 'android' tool with the 'update' action. + Properties related to the SDK location or the project target should + be updated using the 'android' tool with the 'update' action. - This file is an integral part of the build system for your application and - should be checked in in Version Control Systems. + This file is an integral part of the build system for your + application and should be checked in in Version Control Systems. --> <property file="build.properties" /> - <!-- The default.properties file is created and updated by the 'android' tool, as well - as ADT. - This file is an integral part of the build system for your application and - should be checked in in Version Control Systems. --> + <!-- The default.properties file is created and updated by the 'android' + tool, as well as ADT. + This file is an integral part of the build system for your + application and should be checked in in Version Control Systems. --> <property file="default.properties" /> - <!-- Custom Android task to deal with the project target, and import the proper rules. + <!-- Custom Android task to deal with the project target, and import the + proper rules. This requires ant 1.6.0 or above. --> <path id="android.antlibs"> <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" /> @@ -48,19 +50,35 @@ classname="com.android.ant.SetupTask" classpathref="android.antlibs" /> - <!-- Execute the Android Setup task that will setup some properties specific to the target, - and import the build rules files. +<!-- extension targets. Uncomment the ones where you want to do custom work + in between standard targets --> +<!-- + <target name="-pre-build"> + </target> + <target name="-pre-compile"> + </target> + <target name="-post-compile"> + </target> +--> - The rules file is imported from - <SDK>/platforms/<target_platform>/templates/android_rules.xml - To customize some build steps for your project: - - copy the content of the main node <project> from android_rules.xml - - paste it in this build.xml below the <setup /> task. - - disable the import by changing the setup task below to <setup import="false" /> + <!-- Execute the Android Setup task that will setup some properties + specific to the target, and import the build rules files. + + The rules file is imported from + <SDK>/platforms/<target_platform>/ant/ant_rules_r#.xml - This will ensure that the properties are setup correctly but that your customized - build steps are used. + To customize existing targets, there are two options: + - Customize only one target: + - copy/paste the target into this file, *before* the + <setup> task. + - customize it to your needs. + - Customize the whole script. + - copy/paste the content of the rules files (minus the top node) + into this file, *after* the <setup> task + - disable the import of the rules by changing the setup task + below to <setup import="false" />. + - customize to your needs. --> <setup /> |