Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 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(
  26. file.path,
  27. { encoding: "utf-8" },
  28. callback
  29. );
  30. },
  31. type: Types.dappFile
  32. })
  33. )
  34. );
  35. }
  36. );
  37. },
  38. (files: any[], next: Callback<any>) => {
  39. const compiledObject: { [index: string]: any } = {};
  40.  
  41. const compilerOptions = {
  42. isCoverage: this.isCoverage
  43. };
  44.  
  45. async.eachObject(
  46. this.getAvailableCompilers(),
  47. (extension: string, compilers: any, nextObj: any) => {
  48. const matchingFiles = files.filter(
  49. this.filesMatchingExtension(extension)
  50. );
  51. if (matchingFiles.length === 0) {
  52. return nextObj();
  53. }
  54.  
  55. async.someLimit(
  56. compilers,
  57. 1,
  58. (compiler: any, someCb: Callback<boolean>) => {
  59. compiler.call(
  60. compiler,
  61. matchingFiles,
  62. compilerOptions,
  63. (err: any, compileResult: any) => {
  64. if (err) {
  65. return someCb(err);
  66. }
  67. if (compileResult === false) {
  68. // Compiler not compatible, trying the next one
  69. return someCb(null, false);
  70. }
  71. Object.assign(compiledObject, compileResult);
  72. someCb(null, true);
  73. }
  74. );
  75. },
  76. (err: Error, result: boolean) => {
  77. if (err) {
  78. return nextObj(err);
  79. }
  80. if (!result) {
  81. // No compiler was compatible
  82. return nextObj(
  83. new Error(
  84. __(
  85. "No installed compiler was compatible with your version of %s files",
  86. extension
  87. )
  88. )
  89. );
  90. }
  91. nextObj();
  92. }
  93. );
  94. },
  95. (err?: Error | null) => {
  96. if (err) {
  97. return next(err);
  98. }
  99.  
  100. files
  101. .filter((f: any) => !f.compiled)
  102. .forEach((file: any) => {
  103. this.logger.warn(
  104. __(
  105. "%s doesn't have a compatible contract compiler. Maybe a plugin exists for it.",
  106. file.path
  107. )
  108. );
  109. });
  110. next(null, compiledObject);
  111. }
  112. );
  113. },
  114. (compiledObject: any, next: Callback<any>) => {
  115. this.plugins.runActionsForEvent(
  116. "compiler:contracts:compile:after",
  117. compiledObject,
  118. (err?: Error | null, compiledObj: any = {}) => {
  119. if (err) {
  120. return next(err);
  121. }
  122. next(null, compiledObj);
  123. }
  124. );
  125. }
  126. ],
  127. (err?: Error | null, compiledObject?: any) => {
  128. if (err) {
  129. return cb(err);
  130. }
  131. cb(null, compiledObject || {});
  132. }
  133. );
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement