blob: d6126275af4bca99adf3fe42f82e6335019288f6 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// TODO(https://fxbug.dev/84961): Fix null safeety and remove this language version.
// @dart=2.9
import 'dart:io';
// Diff two API files. Return the results to the calling method.
String diffTwoFiles(String leftPath, String rightPath) {
var leftAPIString = readFile(leftPath);
var rightAPIString = readFile(rightPath);
if (leftAPIString == rightAPIString) {
return '';
}
// TODO(fxbug.dev/6541): Describe the differences.
var message = 'Error: API has changed!\n'
'Please acknowledge this change by running:\n'
' cp $leftPath $rightPath \n';
return message;
}
String readFile(String path) {
File f = File(path);
if (!f.existsSync()) {
throw FileSystemException('File $path does not exist');
}
return f.readAsStringSync();
}