deleteDerivedData static method

Future<bool> deleteDerivedData(
  1. BPConfig config,
  2. String derivedPath
)

This function deletes the derived data of the XCode before the build to prevent faulty caches affecting the production build

Implementation

static Future<bool> deleteDerivedData(
  BPConfig config,
  String derivedPath,
) async {
  bool deleted = false;
  List<String> logLines = LogUtils.getActionStartLines(
    "Deleting the derived data of XCode",
  );
  Console.logInfo("└── Deleting the XCode derived data...");

  var dir = Directory(derivedPath);
  if (!await dir.exists()) {
    logLines.addAll([
      "\n[error] The given path for XCode is invalid",
      "[path] $derivedPath\n",
    ]);
    Console.logError(
      "The given path for XCode derived data is invalid -> $derivedPath",
    );
  } else {
    try {
      dir.deleteSync(recursive: true);
      logLines.addAll([
        "\n[folder] $derivedPath",
        "[action] deleted",
      ]);
      stdout.write('\x1B[1A\x1B[2K\r');
      Console.logSuccess("└── √ XCode derived data is deleted");
      deleted = true;
    } catch (e) {
      logLines.addAll([
        "\n[error] ${e.toString()}",
        "[path] $derivedPath\n",
      ]);
      Console.logError(
        "There was an error deleting the derived data -> ${e.toString()}",
      );
    }
  }

  logLines.addAll(LogUtils.getActionEndLines());
  await LogUtils.appendLogUsingStringList(config, logLines);
  return deleted;
}