-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support archived sandboxed SDKs when generating dependencies manifest.
This changes the manifest generation command to also accept SDK archives and reading their metadata to get the SDK package name and version. Note that since this is meant for local deployment only, the APKs generated from the archives are still expected to be signed with a debug key. PiperOrigin-RevId: 567542808 Change-Id: I334a32fc002145db64210e96a71be2b6338e59fb
- Loading branch information
1 parent
cd4691d
commit 5170a29
Showing
11 changed files
with
233 additions
and
73 deletions.
There are no files selected for viewing
45 changes: 0 additions & 45 deletions
45
...a/com/google/devtools/build/android/sandboxedsdktoolbox/config/SdkModulesConfigUtils.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info/SdkInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
package com.google.devtools.build.android.sandboxedsdktoolbox.info; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Information about a Sandboxed SDK. Used to define an SDK dependency and read from an SDK archive | ||
* or bundle config. | ||
*/ | ||
public final class SdkInfo { | ||
|
||
private final String packageName; | ||
private final long versionMajor; | ||
|
||
SdkInfo(String packageName, long versionMajor) { | ||
this.packageName = packageName; | ||
this.versionMajor = versionMajor; | ||
} | ||
|
||
/** The SDK unique package name. */ | ||
public String getPackageName() { | ||
return packageName; | ||
} | ||
|
||
/** | ||
* The SDK versionMajor. This value is constructed from the full SDK version description and it | ||
* represents the actual version of the SDK as used by the package manager later. The major and | ||
* minor versions are merged and the patch version is ignored. | ||
*/ | ||
public long getVersionMajor() { | ||
return versionMajor; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (object instanceof SdkInfo) { | ||
SdkInfo that = (SdkInfo) object; | ||
return this.packageName.equals(that.packageName) && this.versionMajor == that.versionMajor; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(packageName, versionMajor); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info/SdkInfoReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
package com.google.devtools.build.android.sandboxedsdktoolbox.info; | ||
|
||
import com.android.bundle.SdkMetadataOuterClass.SdkMetadata; | ||
import com.android.bundle.SdkModulesConfigOuterClass.RuntimeEnabledSdkVersion; | ||
import com.android.bundle.SdkModulesConfigOuterClass.SdkModulesConfig; | ||
import com.android.tools.build.bundletool.model.RuntimeEnabledSdkVersionEncoder; | ||
import com.google.protobuf.ExtensionRegistry; | ||
import com.google.protobuf.util.JsonFormat; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.net.URI; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
|
||
/** Reads SDK information SDK archives and Bundle metadata files. */ | ||
public final class SdkInfoReader { | ||
|
||
// SDK metadata proto sits at the top level of an ASAR. | ||
private static final String SDK_METADATA_ENTRY_PATH = "SdkMetadata.pb"; | ||
|
||
public static SdkInfo readFromSdkModuleJsonFile(Path sdkModulesConfigPath) { | ||
SdkModulesConfig.Builder modulesConfig = SdkModulesConfig.newBuilder(); | ||
try { | ||
JsonFormat.parser().merge(Files.newBufferedReader(sdkModulesConfigPath), modulesConfig); | ||
return new SdkInfo( | ||
modulesConfig.getSdkPackageName(), getVersionMajor(modulesConfig.getSdkVersion())); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("Failed to parse SDK Module Config.", e); | ||
} | ||
} | ||
|
||
public static SdkInfo readFromSdkArchive(Path sdkArchivePath) { | ||
URI uri = URI.create("jar:" + sdkArchivePath.toUri()); | ||
try (FileSystem zipfs = FileSystems.newFileSystem(uri, new HashMap<String, String>())) { | ||
Path metadataInAsar = zipfs.getPath(SDK_METADATA_ENTRY_PATH); | ||
if (!Files.exists(metadataInAsar)) { | ||
throw new IllegalStateException( | ||
String.format("Could not find %s in %s", SDK_METADATA_ENTRY_PATH, sdkArchivePath)); | ||
} | ||
SdkMetadata metadata = | ||
SdkMetadata.parseFrom( | ||
Files.readAllBytes(metadataInAsar), ExtensionRegistry.getEmptyRegistry()); | ||
return new SdkInfo(metadata.getPackageName(), getVersionMajor(metadata.getSdkVersion())); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("Failed to extract SDK API descriptors.", e); | ||
} | ||
} | ||
|
||
private static long getVersionMajor(RuntimeEnabledSdkVersion version) { | ||
return RuntimeEnabledSdkVersionEncoder.encodeSdkMajorAndMinorVersion( | ||
version.getMajor(), version.getMinor()); | ||
} | ||
|
||
private SdkInfoReader() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.