sdkconfig_compare.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //https://github.com/nkolban/esp32-snippets/blob/master/tools/sdkconfig_compare/sdkconfig_compare.js
  2. // Node.js application for comparing two ESP-IDF configuration files (sdkconfig)
  3. const fs = require("fs"); // Require the file system processing library
  4. const readline = require("readline"); // Require the readline processing library
  5. // buildMap
  6. // Read the sdkconfig file specified by fileName and produce a map of the name/value pairs contained
  7. // within. A Promise is returned that is fulfilled when the file has been read.
  8. function buildMap(fileName) {
  9. const promise = new Promise(function (resolve, reject) {
  10. var readStream = fs.createReadStream(fileName);
  11. readStream.on("error", (err) => {
  12. reject(err);
  13. });
  14. const map = {};
  15. const lineReader = readline.createInterface({
  16. input: readStream,
  17. crlfDelay: Infinity
  18. });
  19. // Called when a new line has been read from the file.
  20. lineReader.on("line", (line) => {
  21. line = line.trim(); // Trim whitespace from the line.
  22. if (line.length == 0) { // Ignore empty lines
  23. return;
  24. }
  25. if (line.startsWith("#")) { // Ignore comment lines
  26. return;
  27. }
  28. const parts = line.split("="); // Split the line into parts separated by the '=' character.
  29. if (map.hasOwnProperty(parts[0])) {
  30. console.log(`Odd ... we found ${parts[0]} twice.`);
  31. }
  32. map[parts[0]] = parts[1]; // Populate the map element.
  33. }); // on(line)
  34. // Called when all the lines from the file have been consumed.
  35. lineReader.on("close", () => {
  36. resolve(map);
  37. }); // on(close)
  38. });
  39. return promise;
  40. } // buildMap
  41. const args = process.argv;
  42. if (args.length != 4) {
  43. console.log("Usage: node sdkconfig_compare file1 file2");
  44. process.exit();
  45. }
  46. const file1 = args[2];
  47. const file2 = args[3];
  48. buildMap(file1).then((result) => {
  49. buildMap(file2).then((result2) => {
  50. buildMap("./sdkconfig.defaults").then((result3) => {
  51. // Three passes
  52. // In A and not B
  53. // in B and not A
  54. // value different in A and B
  55. console.log(`\n\n${file1} properties that are missing in ${file2}\n**************************`);
  56. for (const prop in result) {
  57. if (result.hasOwnProperty(prop)) {
  58. if (!result2.hasOwnProperty(prop) && !result3.hasOwnProperty(prop)) {
  59. console.log(`${prop}=${result[prop]}`);
  60. }
  61. }
  62. }
  63. console.log(`\n\n${file2} properties that are missing in ${file1}\n**************************`);
  64. for (const prop in result2) {
  65. if (result2.hasOwnProperty(prop)) {
  66. if (!result.hasOwnProperty(prop) && !result3.hasOwnProperty(prop)) {
  67. console.log(`${prop}=${result2[prop]}`);
  68. }
  69. }
  70. }
  71. console.log(`\n\nproperties that are different between the 2 files \n**************************`);
  72. for (const prop in result) {
  73. if (result.hasOwnProperty(prop)) {
  74. if (result2.hasOwnProperty(prop)) {
  75. if (result[prop] != result2[prop]) {
  76. console.log(`${prop} : [${result[prop]}] != [${result2[prop]}]`);
  77. }
  78. }
  79. }
  80. }
  81. }).catch((err) => {
  82. console.log(err);
  83. process.exit();
  84. });
  85. }).catch((err) => {
  86. console.log(err);
  87. process.exit();
  88. });
  89. }).catch((err) => {
  90. console.log(err);
  91. process.exit();
  92. }
  93. );