@Override String executeProcess(ProcessInfoBuilder processBuilder) throws ProcessException, IOException { return ExternalNativeBuildTaskUtils .executeBuildProcessAndLogError( androidBuilder, processBuilder, true /* logStdioToInfo */); }
/** * Deserialize a JSON files into NativeBuildConfigValue. */ @NonNull public static Collection<NativeBuildConfigValue> getNativeBuildConfigValues( @NonNull Collection<File> jsons, @NonNull String groupName) throws IOException { List<NativeBuildConfigValue> configValues = Lists.newArrayList(); for (File json : jsons) { configValues.add(getNativeBuildConfigValue(json, groupName)); } return configValues; }
/** * Utility function that gets the name of the output JSON for a particular ABI. */ @NonNull public static File getOutputJson(@NonNull File jsonFolder, @NonNull String abi) { return new File(getOutputFolder(jsonFolder, abi), "android_gradle_build.json"); }
@NonNull public static List<File> getOutputJsons(@NonNull File jsonFolder, @NonNull Collection<String> abis) { List<File> outputs = Lists.newArrayList(); for (String abi : abis) { outputs.add(getOutputJson(jsonFolder, abi)); } return outputs; }
List<File> expectedJson = ExternalNativeBuildTaskUtils.getOutputJsons( generator.getJsonFolder(), Arrays.asList(buildTargetAbi.split(",")));
@NonNull public Collection<NativeBuildConfigValue> readExistingNativeBuildConfigurations() throws IOException { List<File> files = getNativeBuildConfigurationsJsons(); diagnostic("reading %s JSON files", files.size()); List<NativeBuildConfigValue> result = Lists.newArrayList(); List<File> existing = Lists.newArrayList(); for(File file : files) { if (file.exists()) { diagnostic("reading JSON file %s", file.getAbsolutePath()); existing.add(file); } else { // If the tool didn't create the JSON file then create fallback with the // information we have so the user can see partial information in the UI. diagnostic("using fallback JSON for %s", file.getAbsolutePath()); NativeBuildConfigValue fallback = new NativeBuildConfigValue(); fallback.buildFiles = Lists.newArrayList(makefile); result.add(fallback); } } result.addAll(ExternalNativeBuildTaskUtils.getNativeBuildConfigValues( existing, variantName)); return result; }
/** * Resolve the path of any native build project. * @param config -- the AndroidConfig * @return Path resolution. */ @NonNull public static ExternalNativeBuildProjectPathResolution getProjectPath( @NonNull CoreExternalNativeBuild config) { // Path discovery logic: // If there is exactly 1 path in the DSL, then use it. // If there are more than 1, then that is an error. The user has specified both cmake and // ndkBuild in the same project. Map<NativeBuildSystem, File> externalProjectPaths = getExternalBuildExplicitPaths(config); if (externalProjectPaths.size() > 1) { return new ExternalNativeBuildProjectPathResolution( null, null, "More than one externalNativeBuild path specified"); } if (externalProjectPaths.isEmpty()) { // No external projects present. return new ExternalNativeBuildProjectPathResolution(null, null, null); } return new ExternalNativeBuildProjectPathResolution( externalProjectPaths.keySet().iterator().next(), externalProjectPaths.values().iterator().next(), null); }
public void createNdkTasks(@NonNull TaskFactory tasks, @NonNull VariantScope scope) { if (ExternalNativeBuildTaskUtils.isExternalNativeBuildEnabled( extension.getExternalNativeBuild())) { return; } AndroidTask<NdkCompile> ndkCompileTask = androidTasks.create(tasks, new NdkCompile.ConfigAction(scope)); ndkCompileTask.dependsOn(tasks, scope.getPreBuildTask()); if (Boolean.TRUE.equals( scope.getVariantData() .getVariantConfiguration() .getMergedFlavor() .getRenderscriptNdkModeEnabled())) { ndkCompileTask.dependsOn(tasks, scope.getRenderscriptCompileTask()); } scope.getCompileTask().dependsOn(tasks, ndkCompileTask); }
public void createExternalNativeBuildJsonGenerators(@NonNull VariantScope scope) { CoreExternalNativeBuild externalNativeBuild = extension.getExternalNativeBuild(); ExternalNativeBuildTaskUtils.ExternalNativeBuildProjectPathResolution pathResolution = ExternalNativeBuildTaskUtils.getProjectPath(externalNativeBuild); if (pathResolution.errorText != null) { androidBuilder.getErrorReporter().handleSyncError( scope.getVariantConfiguration().getFullName(), SyncIssue.TYPE_EXTERNAL_NATIVE_BUILD_CONFIGURATION, pathResolution.errorText); return; } if (pathResolution.makeFile == null) { // No project return; } scope.setExternalNativeJsonGenerator(ExternalNativeJsonGenerator.create( project.getProjectDir(), pathResolution.buildSystem, pathResolution.makeFile, androidBuilder, sdkHandler, scope )); }
File expectedJson = ExternalNativeBuildTaskUtils.getOutputJson(getJsonFolder(), abi); Files.write(actualResult, expectedJson, Charsets.UTF_8);
@Override public void execute(@NonNull ExternalNativeCleanTask task) { final BaseVariantData<? extends BaseVariantOutputData> variantData = scope.getVariantData(); task.setVariantName(variantData.getName()); // Attempt to clean every possible ABI even those that aren't currently built. // This covers cases where user has changed abiFilters or platform. We don't want // to leave stale results hanging around. List<String> abiNames = Lists.newArrayList(); for(Abi abi : NdkHandler.getAbiList()) { abiNames.add(abi.getName()); } task.setNativeBuildConfigurationsJsons(ExternalNativeBuildTaskUtils.getOutputJsons( generator.getJsonFolder(), abiNames)); task.setAndroidBuilder(androidBuilder); task.setStlSharedObjectFiles(generator.getStlSharedObjectFiles()); task.setObjFolder(generator.getObjFolder()); } }
.getNativeBuildConfigValues( existingJsons, checkNotNull(getVariantName())); List<String> cleanCommands = Lists.newArrayList();
@Override String executeProcess(ProcessInfoBuilder processBuilder) throws ProcessException, IOException { return ExternalNativeBuildTaskUtils .executeBuildProcessAndLogError( androidBuilder, processBuilder, false /* logStdioToInfo */); }
abiPlatformVersion, abi, minSdkVersion); File expectedJson = ExternalNativeBuildTaskUtils.getOutputJson( getJsonFolder(), abi.getName());
List<File> expectedJsons = ExternalNativeBuildTaskUtils.getOutputJsons( externalNativeBuildFolder, userRequestedAbis);
diagnostic("reading expected JSONs"); Collection<NativeBuildConfigValue> configValueList = ExternalNativeBuildTaskUtils .getNativeBuildConfigValues( nativeBuildConfigurationsJsons, getVariantName()); diagnostic("done reading expected JSONs");
.getNativeBuildConfigValue(json, groupName); if (config.buildFiles != null) { long jsonLastModified = java.nio.file.Files.getLastModifiedTime(
/** * Given a list of build commands, execute each. If there is a failure, processing is stopped at * that point. */ protected void executeProcessBatch(@NonNull List<String> commands, @NonNull List<String> targetNames) throws ProcessException, IOException { for (int commandIndex = 0; commandIndex < commands.size(); ++commandIndex) { String command = commands.get(commandIndex); String target = targetNames.get(commandIndex); getLogger().lifecycle(String.format("Clean %s", target)); List<String> tokens = StringHelper.tokenizeString(command); ProcessInfoBuilder processBuilder = new ProcessInfoBuilder(); processBuilder.setExecutable(tokens.get(0)); for (int i = 1; i < tokens.size(); ++i) { processBuilder.addArgs(tokens.get(i)); } diagnostic("%s", processBuilder); ExternalNativeBuildTaskUtils.executeBuildProcessAndLogError( getBuilder(), processBuilder, true /* logStdioToInfo */); } }
/** * Given a list of build commands, execute each. If there is a failure, processing is stopped at * that point. */ protected void executeProcessBatch( @NonNull List<String> libraryNames, @NonNull List<String> commands) throws BuildCommandException, IOException { // Order of building doesn't matter to final result but building in reverse order causes // the dependencies to be built first for CMake and ndk-build. This gives better progress // visibility to the user because they will see "building XXXXX.a" before // "building XXXXX.so". Nicer still would be to have the dependency information in the JSON // so we can build in toposort order. for (int library = libraryNames.size() - 1; library >= 0; --library) { String libraryName = libraryNames.get(library); getLogger().lifecycle(String.format("Build %s", libraryName)); String command = commands.get(library); List<String> tokens = StringHelper.tokenizeString(command); ProcessInfoBuilder processBuilder = new ProcessInfoBuilder(); processBuilder.setExecutable(tokens.get(0)); for (int i = 1; i < tokens.size(); ++i) { processBuilder.addArgs(tokens.get(i)); } diagnostic("%s", processBuilder); ExternalNativeBuildTaskUtils.executeBuildProcessAndLogError( getBuilder(), processBuilder, true /* logStdioToInfo */); } }