diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2014-09-04 01:51:53 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-09-04 01:51:55 +0000 |
commit | 708df7bc45bc29bac3f2a7ed448249a9417df6c0 (patch) | |
tree | c273500ee8a3b0878c4183c804e7ec4555d3beb1 /tools/layoutlib/bridge | |
parent | db0b8a1997ef64536d27744e261e6bf094019f76 (diff) | |
parent | 0774bc4605fdd47178cc38258d1b4c40ae113b2f (diff) | |
download | frameworks_base-708df7bc45bc29bac3f2a7ed448249a9417df6c0.zip frameworks_base-708df7bc45bc29bac3f2a7ed448249a9417df6c0.tar.gz frameworks_base-708df7bc45bc29bac3f2a7ed448249a9417df6c0.tar.bz2 |
Merge "Remove ANDROID_BUILD_TOP from intelliJ path variables." into lmp-dev
Diffstat (limited to 'tools/layoutlib/bridge')
-rw-r--r-- | tools/layoutlib/bridge/bridge.iml | 4 | ||||
-rw-r--r-- | tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java | 60 |
2 files changed, 58 insertions, 6 deletions
diff --git a/tools/layoutlib/bridge/bridge.iml b/tools/layoutlib/bridge/bridge.iml index 7553b59..0f96916 100644 --- a/tools/layoutlib/bridge/bridge.iml +++ b/tools/layoutlib/bridge/bridge.iml @@ -34,11 +34,11 @@ <orderEntry type="module-library" scope="TEST"> <library> <CLASSES> - <root url="jar://$ANDROID_BUILD_TOP$/prebuilts/misc/common/sdk-common/sdk-common.jar!/" /> + <root url="jar://$MODULE_DIR$/../../../../../prebuilts/misc/common/sdk-common/sdk-common.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES> - <root url="jar://$ANDROID_BUILD_TOP$/prebuilts/misc/common/sdk-common/sdk-common-sources.jar!/" /> + <root url="jar://$MODULE_DIR$/../../../../../prebuilts/misc/common/sdk-common/sdk-common-sources.jar!/" /> </SOURCES> </library> </orderEntry> diff --git a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java index 31b3e25..a2588a6 100644 --- a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java +++ b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java @@ -104,9 +104,61 @@ public class Main { return platformDir; } // System Property not set. Try to find the directory in the build directory. - String out = System.getenv("ANDROID_HOST_OUT"); - if (out == null || out.isEmpty() || !new File(out).isDirectory()) { - // Can't find the out directory. + String androidHostOut = System.getenv("ANDROID_HOST_OUT"); + if (androidHostOut != null) { + platformDir = getPlatformDirFromHostOut(new File(androidHostOut)); + if (platformDir != null) { + return platformDir; + } + } + String workingDirString = System.getProperty("user.dir"); + File workingDir = new File(workingDirString); + // Test if workingDir is android checkout root. + platformDir = getPlatformDirFromRoot(workingDir); + if (platformDir != null) { + return platformDir; + } + // Test if workingDir is platform/frameworks/base/tools/layoutlib. That is, root should be + // workingDir/../../../../ (4 levels up) + File currentDir = workingDir; + for (int i = 0; i < 4; i++) { + if (currentDir != null) { + currentDir = currentDir.getParentFile(); + } + } + return currentDir == null ? null : getPlatformDirFromRoot(currentDir); + } + + private static String getPlatformDirFromRoot(File root) { + if (!root.isDirectory()) { + return null; + } + File out = new File(root, "out"); + if (!out.isDirectory()) { + return null; + } + File host = new File(out, "host"); + if (!host.isDirectory()) { + return null; + } + File[] hosts = host.listFiles(new FileFilter() { + @Override + public boolean accept(File path) { + return path.isDirectory() && (path.getName().startsWith("linux-") || path.getName() + .startsWith("darwin-")); + } + }); + for (File hostOut : hosts) { + String platformDir = getPlatformDirFromHostOut(hostOut); + if (platformDir != null) { + return platformDir; + } + } + return null; + } + + private static String getPlatformDirFromHostOut(File out) { + if (!out.isDirectory()) { return null; } File sdkDir = new File(out, "sdk" + File.separator + "sdk"); @@ -117,7 +169,7 @@ public class Main { File[] possibleSdks = sdkDir.listFiles(new FileFilter() { @Override public boolean accept(File path) { - return path.isDirectory() && path.getAbsolutePath().contains("android-sdk"); + return path.isDirectory() && path.getName().contains("android-sdk"); } }); for (File possibleSdk : possibleSdks) { |