diff options
author | Raphael Moll <ralf@android.com> | 2014-05-31 01:07:47 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-05-31 01:07:48 +0000 |
commit | 0725c94cb68378e2c587107766cfd2261c84a8c2 (patch) | |
tree | 46a927c26c74b8263ae092cf83f4f7946441dccd | |
parent | 94663532d5a79d2be840e4b23f55adc2f192bbeb (diff) | |
parent | fee3378b0c6d4c1b33f46daf540a88e47698fc5e (diff) | |
download | base-tools_r22.6.tar.gz |
Merge "SDK loader: mark build-tools as broken if they don't match the current OS. DO NOT MERGE." into tools_r22.6tools_r22.6
3 files changed, 109 insertions, 50 deletions
diff --git a/sdklib/src/main/java/com/android/sdklib/internal/repository/packages/BuildToolPackage.java b/sdklib/src/main/java/com/android/sdklib/internal/repository/packages/BuildToolPackage.java index 51a199551f..cd31311088 100755 --- a/sdklib/src/main/java/com/android/sdklib/internal/repository/packages/BuildToolPackage.java +++ b/sdklib/src/main/java/com/android/sdklib/internal/repository/packages/BuildToolPackage.java @@ -146,7 +146,7 @@ public class BuildToolPackage extends FullRevisionPackage { } if (error == null && rev != null) { - return new BuildToolPackage( + BuildToolPackage pkg = new BuildToolPackage( null, //source props, 0, //revision (extracted from props) @@ -157,6 +157,11 @@ public class BuildToolPackage extends FullRevisionPackage { Arch.getCurrentArch(), //archiveArch buildToolDir.getAbsolutePath()); + if (pkg.hasCompatibleArchive()) { + return pkg; + } else { + error = "Package is not compatible with current OS"; + } } diff --git a/sdklib/src/test/java/com/android/sdklib/SdkManagerTestCase.java b/sdklib/src/test/java/com/android/sdklib/SdkManagerTestCase.java index 91aa7397f5..1ba47a1e89 100755 --- a/sdklib/src/test/java/com/android/sdklib/SdkManagerTestCase.java +++ b/sdklib/src/test/java/com/android/sdklib/SdkManagerTestCase.java @@ -180,7 +180,7 @@ public class SdkManagerTestCase extends AndroidLocationTestCase { makePlatformTools(new File(mFakeSdk, SdkConstants.FD_PLATFORM_TOOLS)); if (mRepoXsdLevel >= 8) { - makeBuildTools(new File(mFakeSdk, SdkConstants.FD_BUILD_TOOLS)); + makeBuildTools(mFakeSdk); } File toolsLibEmuDir = new File(mFakeSdk, SdkConstants.OS_SDK_TOOLS_LIB_FOLDER + "emulator"); @@ -448,58 +448,73 @@ public class SdkManagerTestCase extends AndroidLocationTestCase { new File(platformToolsDir, SdkConstants.FN_ADB).createNewFile(); } - private void makeBuildTools(File buildToolsTopDir) throws IOException { - buildToolsTopDir.mkdir(); + private void makeBuildTools(File sdkDir) throws IOException { for (String revision : new String[] { "3.0.0", "3.0.1", "18.3.4 rc5" }) { - - File buildToolsDir = new File(buildToolsTopDir, revision); - createSourceProps(buildToolsDir, PkgProps.PKG_REVISION, revision); - - FullRevision fullRevision = FullRevision.parseRevision(revision); - - createFakeBuildTools( - buildToolsDir, fullRevision, - BuildToolInfo.PathId.AAPT, SdkConstants.FN_AAPT); - createFakeBuildTools( - buildToolsDir, fullRevision, - BuildToolInfo.PathId.AIDL, SdkConstants.FN_AIDL); - createFakeBuildTools( - buildToolsDir, fullRevision, - BuildToolInfo.PathId.DX, SdkConstants.FN_DX); - createFakeBuildTools( - buildToolsDir, fullRevision, - BuildToolInfo.PathId.DX_JAR, SdkConstants.FD_LIB + File.separator + - SdkConstants.FN_DX_JAR); - createFakeBuildTools( - buildToolsDir, fullRevision, - BuildToolInfo.PathId.LLVM_RS_CC, SdkConstants.FN_RENDERSCRIPT); - createFakeBuildTools( - buildToolsDir, fullRevision, - BuildToolInfo.PathId.ANDROID_RS, SdkConstants.OS_FRAMEWORK_RS + File.separator + - "placeholder.txt"); - createFakeBuildTools( - buildToolsDir, fullRevision, - BuildToolInfo.PathId.ANDROID_RS_CLANG, SdkConstants.OS_FRAMEWORK_RS_CLANG + File.separator + - "placeholder.txt"); - createFakeBuildTools( - buildToolsDir, fullRevision, - BuildToolInfo.PathId.BCC_COMPAT, SdkConstants.FN_BCC_COMPAT); - createFakeBuildTools( - buildToolsDir, fullRevision, - BuildToolInfo.PathId.LD_ARM, SdkConstants.FN_LD_ARM); - createFakeBuildTools( - buildToolsDir, fullRevision, - BuildToolInfo.PathId.LD_MIPS, SdkConstants.FN_LD_MIPS); - createFakeBuildTools( - buildToolsDir, fullRevision, - BuildToolInfo.PathId.LD_X86, SdkConstants.FN_LD_X86); + createFakeBuildTools(sdkDir, "ANY", revision); } } - private void createFakeBuildTools(@NonNull File dir, - @NonNull FullRevision buildToolsRevision, - @NonNull BuildToolInfo.PathId pathId, - @NonNull String filepath) + /** + * Adds a new fake build tools to the SDK In the given SDK/build-tools folder. + * + * @param sdkDir The SDK top folder. Must already exist. + * @param os The OS. One of {@link HostOs#toString()} or "ANY". + * @param revision The "x.y.z rc r" revision number from {@link FullRevision#toShortString()}. + * @throws IOException + */ + protected void createFakeBuildTools(File sdkDir, String os, String revision) + throws IOException { + File buildToolsTopDir = new File(sdkDir, SdkConstants.FD_BUILD_TOOLS); + buildToolsTopDir.mkdir(); + File buildToolsDir = new File(buildToolsTopDir, revision); + createSourceProps(buildToolsDir, + PkgProps.PKG_REVISION, revision, + "Archive.Os", os); + + FullRevision fullRevision = FullRevision.parseRevision(revision); + + createFakeBuildToolsFile( + buildToolsDir, fullRevision, + BuildToolInfo.PathId.AAPT, SdkConstants.FN_AAPT); + createFakeBuildToolsFile( + buildToolsDir, fullRevision, + BuildToolInfo.PathId.AIDL, SdkConstants.FN_AIDL); + createFakeBuildToolsFile( + buildToolsDir, fullRevision, + BuildToolInfo.PathId.DX, SdkConstants.FN_DX); + createFakeBuildToolsFile( + buildToolsDir, fullRevision, + BuildToolInfo.PathId.DX_JAR, SdkConstants.FD_LIB + File.separator + + SdkConstants.FN_DX_JAR); + createFakeBuildToolsFile( + buildToolsDir, fullRevision, + BuildToolInfo.PathId.LLVM_RS_CC, SdkConstants.FN_RENDERSCRIPT); + createFakeBuildToolsFile( + buildToolsDir, fullRevision, + BuildToolInfo.PathId.ANDROID_RS, SdkConstants.OS_FRAMEWORK_RS + File.separator + + "placeholder.txt"); + createFakeBuildToolsFile( + buildToolsDir, fullRevision, + BuildToolInfo.PathId.ANDROID_RS_CLANG, SdkConstants.OS_FRAMEWORK_RS_CLANG + File.separator + + "placeholder.txt"); + createFakeBuildToolsFile( + buildToolsDir, fullRevision, + BuildToolInfo.PathId.BCC_COMPAT, SdkConstants.FN_BCC_COMPAT); + createFakeBuildToolsFile( + buildToolsDir, fullRevision, + BuildToolInfo.PathId.LD_ARM, SdkConstants.FN_LD_ARM); + createFakeBuildToolsFile( + buildToolsDir, fullRevision, + BuildToolInfo.PathId.LD_MIPS, SdkConstants.FN_LD_MIPS); + createFakeBuildToolsFile( + buildToolsDir, fullRevision, + BuildToolInfo.PathId.LD_X86, SdkConstants.FN_LD_X86); + } + + private void createFakeBuildToolsFile(@NonNull File dir, + @NonNull FullRevision buildToolsRevision, + @NonNull BuildToolInfo.PathId pathId, + @NonNull String filepath) throws IOException { if (pathId.isPresentIn(buildToolsRevision)) { diff --git a/sdklib/src/test/java/com/android/sdklib/internal/repository/LocalSdkParserTest.java b/sdklib/src/test/java/com/android/sdklib/internal/repository/LocalSdkParserTest.java index 585448b5c2..a0c17beb17 100755 --- a/sdklib/src/test/java/com/android/sdklib/internal/repository/LocalSdkParserTest.java +++ b/sdklib/src/test/java/com/android/sdklib/internal/repository/LocalSdkParserTest.java @@ -23,6 +23,7 @@ import com.android.sdklib.SdkManager; import com.android.sdklib.SdkManagerTestCase; import com.android.sdklib.SystemImage; import com.android.sdklib.internal.androidTarget.PlatformTarget; +import com.android.sdklib.internal.repository.archives.Archive; import com.android.sdklib.io.FileOp; import java.io.File; @@ -269,6 +270,44 @@ public class LocalSdkParserTest extends SdkManagerTestCase { sanitizeInput(p.getSystemImages()[1].getSkins())); } + public void testLocalSdkParser_BuildTools_InvalidOs() throws Exception { + assertEquals( + "[Android SDK Build-tools, revision 18.3.4 rc5, " + + "Android SDK Build-tools, revision 3.0.1, " + + "Android SDK Build-tools, revision 3, " + + "Platform Tools, revision 17.1.2, Tools, revision 1.0.1]", + Arrays.toString(mParser.parseSdk(mSdkMan.getLocation(), + mSdkMan, + LocalSdkParser.PARSE_BUILD_TOOLS | + LocalSdkParser.PARSE_EXTRAS, + mMonitor))); + + // We have many OS possible. Choose 2 that do not match the current platform. + Archive.Os current = Archive.Os.getCurrentOs(); + Archive.Os others[] = new Archive.Os[2]; + int i = 0; + for (Archive.Os o : Archive.Os.values()) { + if (o != Archive.Os.ANY && o != current && i < others.length) { + others[i++] = o; + } + } + createFakeBuildTools(new File(mSdkMan.getLocation()), others[0].toString(), "5.0.1"); + createFakeBuildTools(new File(mSdkMan.getLocation()), others[1].toString(), "5.0.2"); + + assertEquals( + "[Android SDK Build-tools, revision 18.3.4 rc5, " + + "Android SDK Build-tools, revision 3.0.1, " + + "Android SDK Build-tools, revision 3, " + + "Broken Build-Tools Package, revision 5.0.1, " + + "Broken Build-Tools Package, revision 5.0.2, " + + "Platform Tools, revision 17.1.2, Tools, revision 1.0.1]", + Arrays.toString(mParser.parseSdk(mSdkMan.getLocation(), + mSdkMan, + LocalSdkParser.PARSE_BUILD_TOOLS | + LocalSdkParser.PARSE_EXTRAS, + mMonitor))); + } + private String sanitizeInput(Object[] array) { String input = Arrays.toString(array); String sdkPath = mSdkMan.getLocation(); |