/collects/drracket/drracket.rkt

http://github.com/gmarceau/PLT · Racket · 151 lines · 133 code · 12 blank · 6 comment · 19 complexity · 6ac9be85a1d69ebec3aeb389cd2326be MD5 · raw file

  1. #lang racket/base
  2. (require racket/gui/base "private/key.rkt")
  3. (define debugging? (getenv "PLTDRDEBUG"))
  4. (define profiling? (getenv "PLTDRPROFILE"))
  5. (define first-parallel? (getenv "PLTDRPAR"))
  6. (define install-cm? (and (not debugging?)
  7. (getenv "PLTDRCM")))
  8. (define cm-trace? (or (equal? (getenv "PLTDRCM") "trace")
  9. (equal? (getenv "PLTDRDEBUG") "trace")
  10. (equal? (getenv "PLTDRPAR") "trace")))
  11. ;; the flush is only here to ensure that the output is
  12. ;; appears when running in cygwin under windows.
  13. (define (flprintf fmt . args)
  14. (apply printf fmt args)
  15. (flush-output))
  16. (define (run-trace-thread)
  17. (let ([evt (make-log-receiver (current-logger) 'info)])
  18. (void
  19. (thread
  20. (λ ()
  21. (let loop ()
  22. (define vec (sync evt))
  23. (define str (vector-ref vec 1))
  24. (when (regexp-match #rx"^cm: *compil(ing|ed)" str)
  25. (display str)
  26. (newline))
  27. (loop)))))))
  28. (cond
  29. [debugging?
  30. (flprintf "PLTDRDEBUG: loading CM to load/create errortrace zos\n")
  31. (let-values ([(zo-compile
  32. make-compilation-manager-load/use-compiled-handler)
  33. (parameterize ([current-namespace (make-base-empty-namespace)]
  34. [use-compiled-file-paths '()])
  35. (values
  36. (dynamic-require 'errortrace/zo-compile 'zo-compile)
  37. (dynamic-require 'compiler/cm 'make-compilation-manager-load/use-compiled-handler)))])
  38. (flprintf "PLTDRDEBUG: installing CM to load/create errortrace zos\n")
  39. (current-compile zo-compile)
  40. (use-compiled-file-paths (list (build-path "compiled" "errortrace")))
  41. (current-load/use-compiled (make-compilation-manager-load/use-compiled-handler))
  42. (error-display-handler (dynamic-require 'errortrace/errortrace-lib
  43. 'errortrace-error-display-handler))
  44. (when cm-trace?
  45. (flprintf "PLTDRDEBUG: enabling CM tracing\n")
  46. (run-trace-thread)))]
  47. [install-cm?
  48. (flprintf "PLTDRCM: loading compilation manager\n")
  49. (let ([make-compilation-manager-load/use-compiled-handler
  50. (parameterize ([current-namespace (make-base-empty-namespace)])
  51. (dynamic-require 'compiler/cm 'make-compilation-manager-load/use-compiled-handler))])
  52. (flprintf "PLTDRCM: installing compilation manager\n")
  53. (current-load/use-compiled (make-compilation-manager-load/use-compiled-handler))
  54. (when cm-trace?
  55. (flprintf "PLTDRCM: enabling CM tracing\n")
  56. (run-trace-thread)))]
  57. [first-parallel?
  58. (flprintf "PLTDRPAR: loading compilation manager\n")
  59. (define tools? (not (getenv "PLTNOTOOLS")))
  60. (define (files-in-coll coll)
  61. (define dir (collection-path coll))
  62. (map (λ (x) (build-path dir x))
  63. (filter
  64. (λ (x) (regexp-match #rx"rkt$" (path->string x)))
  65. (directory-list dir))))
  66. (define (randomize lst)
  67. (define vec (make-vector (length lst) #f))
  68. (let loop ([i 0]
  69. [lst lst])
  70. (cond
  71. [(= i (vector-length vec)) (void)]
  72. [else
  73. (define index (random (- (vector-length vec) i)))
  74. (define ele (list-ref lst index))
  75. (vector-set! vec i ele)
  76. (loop (+ i 1) (remq ele lst))]))
  77. (vector->list vec))
  78. (define (tool-files id)
  79. (apply
  80. append
  81. (map
  82. (λ (x)
  83. (define proc (get-info/full x))
  84. (if proc
  85. (map (λ (dirs)
  86. (apply build-path
  87. x
  88. (if (list? dirs)
  89. dirs
  90. (list dirs))))
  91. (proc id (λ () '())))
  92. '()))
  93. (find-relevant-directories (list id)))))
  94. (define make-compilation-manager-load/use-compiled-handler
  95. (parameterize ([current-namespace (make-base-empty-namespace)])
  96. (dynamic-require 'compiler/cm 'make-compilation-manager-load/use-compiled-handler)))
  97. (when cm-trace?
  98. (flprintf "PLTDRPAR: enabling CM tracing\n")
  99. (run-trace-thread))
  100. (flprintf "PLTDRPAR: loading setup/parallel-build\n")
  101. (define-values (parallel-compile-files get-info/full find-relevant-directories)
  102. (parameterize ([current-load/use-compiled (make-compilation-manager-load/use-compiled-handler)])
  103. (values (dynamic-require 'setup/parallel-build 'parallel-compile-files)
  104. (and tools? (dynamic-require 'setup/getinfo 'get-info/full))
  105. (and tools? (dynamic-require 'setup/getinfo 'find-relevant-directories)))))
  106. (if tools?
  107. (flprintf "PLTDRPAR: parallel compile of framework, drracket, and tools\n")
  108. (flprintf "PLTDRPAR: parallel compile of framework and drracket\n"))
  109. (parallel-compile-files (randomize (append (files-in-coll "drracket")
  110. (files-in-coll "framework")
  111. (if tools?
  112. (append (tool-files 'drracket-tools)
  113. (tool-files 'tools))
  114. '())))
  115. #:handler
  116. (λ (handler-type path msg out err)
  117. (case handler-type
  118. [(done)
  119. (when cm-trace?
  120. (printf "PLTDRPAR: made ~a\n" path))]
  121. [else
  122. (printf "~a\n" msg)
  123. (printf "stdout from compiling ~a:\n~a\n" path out)
  124. (flush-output)
  125. (fprintf (current-error-port) "stderr from compiling ~a:\n~a\n" path err)])))
  126. (flprintf "PLTDRPAR: installing compilation manager\n")
  127. (current-load/use-compiled (make-compilation-manager-load/use-compiled-handler))])
  128. (when profiling?
  129. (flprintf "PLTDRPROFILE: installing profiler\n")
  130. ;; NOTE that this might not always work.
  131. ;; it creates a new custodian and installs it, but the
  132. ;; original eventspace was created on the original custodian
  133. ;; and this code does not create a new eventspace.
  134. (let ([orig-cust (current-custodian)]
  135. [orig-eventspace (current-eventspace)]
  136. [new-cust (make-custodian)])
  137. (current-custodian new-cust)
  138. ((dynamic-require 'drracket/private/profile-drs 'start-profile) orig-cust)))
  139. (dynamic-require 'drracket/private/drracket-normal #f)