Search in sources :

Example 1 with DeviceSpecParser

use of com.android.tools.build.bundletool.device.DeviceSpecParser in project bundletool by google.

the class BuildApksCommand method fromFlags.

static BuildApksCommand fromFlags(ParsedFlags flags, PrintStream out, SystemEnvironmentProvider systemEnvironmentProvider, AdbServer adbServer) {
    BuildApksCommand.Builder buildApksCommand = BuildApksCommand.builder().setBundlePath(BUNDLE_LOCATION_FLAG.getRequiredValue(flags)).setOutputFile(OUTPUT_FILE_FLAG.getRequiredValue(flags)).setOutputPrintStream(out);
    // Optional arguments.
    OUTPUT_FORMAT_FLAG.getValue(flags).ifPresent(buildApksCommand::setOutputFormat);
    OVERWRITE_OUTPUT_FLAG.getValue(flags).ifPresent(buildApksCommand::setOverwriteOutput);
    AAPT2_PATH_FLAG.getValue(flags).ifPresent(aapt2Path -> buildApksCommand.setAapt2Command(Aapt2Command.createFromExecutablePath(aapt2Path)));
    BUILD_MODE_FLAG.getValue(flags).ifPresent(buildApksCommand::setApkBuildMode);
    LOCAL_TESTING_MODE_FLAG.getValue(flags).ifPresent(buildApksCommand::setLocalTestingMode);
    MAX_THREADS_FLAG.getValue(flags).ifPresent(maxThreads -> buildApksCommand.setExecutorService(createInternalExecutorService(maxThreads)).setExecutorServiceCreatedByBundleTool(true));
    OPTIMIZE_FOR_FLAG.getValue(flags).ifPresent(buildApksCommand::setOptimizationDimensions);
    populateSigningConfigurationFromFlags(buildApksCommand, flags, out, systemEnvironmentProvider);
    populateSourceStampFromFlags(buildApksCommand, flags, out, systemEnvironmentProvider);
    boolean connectedDeviceMode = CONNECTED_DEVICE_FLAG.getValue(flags).orElse(false);
    CONNECTED_DEVICE_FLAG.getValue(flags).ifPresent(buildApksCommand::setGenerateOnlyForConnectedDevice);
    Optional<String> deviceSerialName = DEVICE_ID_FLAG.getValue(flags);
    if (connectedDeviceMode && !deviceSerialName.isPresent()) {
        deviceSerialName = systemEnvironmentProvider.getVariable(ANDROID_SERIAL_VARIABLE);
    }
    deviceSerialName.ifPresent(buildApksCommand::setDeviceId);
    // if ADB cannot be found in a normal mode.
    if (connectedDeviceMode) {
        Path adbPath = CommandUtils.getAdbPath(flags, ADB_PATH_FLAG, systemEnvironmentProvider);
        buildApksCommand.setAdbPath(adbPath).setAdbServer(adbServer);
    }
    ApkBuildMode apkBuildMode = BUILD_MODE_FLAG.getValue(flags).orElse(DEFAULT);
    boolean supportsPartialDeviceSpecs = apkBuildMode.equals(SYSTEM);
    Function<Path, DeviceSpec> deviceSpecParser = supportsPartialDeviceSpecs ? DeviceSpecParser::parsePartialDeviceSpec : DeviceSpecParser::parseDeviceSpec;
    Optional<ImmutableSet<SystemApkOption>> systemApkOptions = SYSTEM_APK_OPTIONS.getValue(flags);
    if (systemApkOptions.isPresent() && !apkBuildMode.equals(SYSTEM)) {
        throw InvalidCommandException.builder().withInternalMessage("'%s' flag is available in system mode only.", SYSTEM_APK_OPTIONS.getName()).build();
    }
    systemApkOptions.ifPresent(buildApksCommand::setSystemApkOptions);
    DEVICE_SPEC_FLAG.getValue(flags).map(deviceSpecParser).ifPresent(buildApksCommand::setDeviceSpec);
    DEVICE_TIER_FLAG.getValue(flags).ifPresent(buildApksCommand::setDeviceTier);
    MODULES_FLAG.getValue(flags).ifPresent(buildApksCommand::setModules);
    VERBOSE_FLAG.getValue(flags).ifPresent(buildApksCommand::setVerbose);
    P7ZIP_PATH_FLAG.getValue(flags).ifPresent(p7zipPath -> {
        int numThreads = MAX_THREADS_FLAG.getValue(flags).orElse(DEFAULT_THREAD_POOL_SIZE);
        buildApksCommand.setP7ZipCommand(P7ZipCommand.defaultP7ZipCommand(p7zipPath, numThreads));
    });
    RUNTIME_ENABLED_SDK_BUNDLE_LOCATIONS_FLAG.getValue(flags).ifPresent(buildApksCommand::setRuntimeEnabledSdkBundlePaths);
    flags.checkNoUnknownFlags();
    return buildApksCommand.build();
}
Also used : Path(java.nio.file.Path) DeviceSpec(com.android.bundle.Devices.DeviceSpec) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) DeviceSpecParser(com.android.tools.build.bundletool.device.DeviceSpecParser)

Aggregations

DeviceSpec (com.android.bundle.Devices.DeviceSpec)1 DeviceSpecParser (com.android.tools.build.bundletool.device.DeviceSpecParser)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Path (java.nio.file.Path)1