Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. private compile_contracts(contractFiles: any[], cb: Callback<any>) {
  2. if (contractFiles.length === 0) {
  3. return cb(null, {});
  4. }
  5.  
  6. async.waterfall(
  7. [
  8. (next: Callback<any[]>) => {
  9. this.plugins.runActionsForEvent(
  10. "compiler:contracts:compile:before",
  11. contractFiles,
  12. (err?: Error | null, files: any[] = []) => {
  13. if (err) {
  14. return next(err);
  15. }
  16. next(
  17. null,
  18. files.map((file: any) =>
  19. file instanceof File
  20. ? file
  21. : new File({
  22. originalPath: file.path,
  23. path: file.path,
  24. resolver: (callback: Callback<any>) => {
  25. fs.readFile(file.path, { encoding: "utf-8" }, callback);
  26. },
  27. type: Types.dappFile
  28. })
  29. )
  30. );
  31. }
  32. );
  33. },
  34. (files: any[], next: Callback<any>) => {
  35. const compiledObject: { [index: string]: any } = {};
  36.  
  37. const compilerOptions = {
  38. isCoverage: this.isCoverage
  39. };
  40.  
  41. async.eachObject(
  42. this.getAvailableCompilers(),
  43. (extension: string, compilers: any, nextObj: any) => {
  44. const matchingFiles = files.filter(this.filesMatchingExtension(extension));
  45. if (matchingFiles.length === 0) {
  46. return nextObj();
  47. }
  48.  
  49. async.someLimit(
  50. compilers,
  51. 1,
  52. (compiler: any, someCb: Callback<boolean>) => {
  53. compiler.call(compiler, matchingFiles, compilerOptions, (err: any, compileResult: any) => {
  54. if (err) {
  55. return someCb(err);
  56. }
  57. if (compileResult === false) {
  58. // Compiler not compatible, trying the next one
  59. return someCb(null, false);
  60. }
  61. Object.assign(compiledObject, compileResult);
  62. someCb(null, true);
  63. });
  64. },
  65. (err: Error, result: boolean) => {
  66. if (err) {
  67. return nextObj(err);
  68. }
  69. if (!result) {
  70. // No compiler was compatible
  71. return nextObj(
  72. new Error(__("No installed compiler was compatible with your version of %s files", extension))
  73. );
  74. }
  75. nextObj();
  76. }
  77. );
  78. },
  79. (err?: Error | null) => {
  80. if (err) {
  81. return next(err);
  82. }
  83.  
  84. files
  85. .filter((f: any) => !f.compiled)
  86. .forEach((file: any) => {
  87. this.logger.warn(
  88. __("%s doesn't have a compatible contract compiler. Maybe a plugin exists for it.", file.path)
  89. );
  90. });
  91. next(null, compiledObject);
  92. }
  93. );
  94. },
  95. (compiledObject: any, next: Callback<any>) => {
  96. this.plugins.runActionsForEvent(
  97. "compiler:contracts:compile:after",
  98. compiledObject,
  99. (err?: Error | null, compiledObj: any = {}) => {
  100. if (err) {
  101. return next(err);
  102. }
  103. next(null, compiledObj);
  104. }
  105. );
  106. }
  107. ],
  108. (err?: Error | null, compiledObject?: any) => {
  109. if (err) {
  110. return cb(err);
  111. }
  112. cb(null, compiledObject || {});
  113. }
  114. );
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement