You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8 KiB

  1. const path = require('path');
  2. const fs = require('fs');
  3. const root = path.resolve(__dirname, '..', '..');
  4. const pjsPath = path.join(root, 'package.json');
  5. const librdkafkaPath = path.resolve(root, 'deps', 'librdkafka');
  6. const pjs = require(pjsPath);
  7. const majorMask = 0xff000000;
  8. const minorMask = 0x00ff0000;
  9. const patchMask = 0x0000ff00;
  10. const revMask = 0x000000ff;
  11. // Read the header file
  12. const headerFileLines = fs.readFileSync(path.resolve(librdkafkaPath, 'src', 'rdkafka.h')).toString().split('\n');
  13. const precompilerDefinitions = headerFileLines.filter((line) => line.startsWith('#def'));
  14. const definedLines = precompilerDefinitions.map(definedLine => {
  15. const content = definedLine.split(' ').filter(v => v != '');
  16. return {
  17. command: content[0],
  18. key: content[1],
  19. value: content[2]
  20. };
  21. });
  22. const defines = {};
  23. for (let item of definedLines) {
  24. if (item.command == '#define') {
  25. defines[item.key] = item.value;
  26. }
  27. }
  28. function parseLibrdkafkaVersion(version) {
  29. const intRepresentation = parseInt(version);
  30. const major = (intRepresentation & majorMask) >> (8 * 3);
  31. const minor = (intRepresentation & minorMask) >> (8 * 2);
  32. const patch = (intRepresentation & patchMask) >> (8 * 1);
  33. const rev = (intRepresentation & revMask) >> (8 * 0);
  34. return {
  35. major,
  36. minor,
  37. patch,
  38. rev
  39. };
  40. }
  41. function versionAsString(version) {
  42. return [
  43. version.major,
  44. version.minor,
  45. version.patch,
  46. version.rev === 255 ? null : version.rev,
  47. ].filter(v => v != null).join('.');
  48. }
  49. const librdkafkaVersion = parseLibrdkafkaVersion(defines.RD_KAFKA_VERSION);
  50. const versionString = versionAsString(librdkafkaVersion);
  51. if (pjs.librdkafka !== versionString) {
  52. console.error(`Librdkafka version of ${versionString} does not match package json: ${pjs.librdkafka}`);
  53. process.exit(1);
  54. }