Guest User

Untitled

a guest
Apr 23rd, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. ;; Monkeypatch for filesystem separator
  2. FileSystem separator = method(case(System windows?, true, "\\", false, "/"))
  3.  
  4. ;; Task object
  5. Task = Origin mimic do(
  6.  
  7. invoke = method(
  8. @dependencies each(d,
  9. dep = Biild tasks select(t, t name asText == d asText) first
  10. if(dep cell?(:success) not, dep invoke)
  11. if(dep success not, error!("Dependency `#{dep name}' of `#{@name}' failed"))
  12. )
  13. @success = bind(
  14. rescue(fn(c,
  15. c report println
  16. false
  17. )),
  18. @body evaluateOn(Ground)
  19. )
  20. )
  21.  
  22. )
  23.  
  24. Biild = Origin mimic do(
  25.  
  26. ;; Current namespace path pieces
  27. ns = []
  28.  
  29. ;; Task container
  30. tasks = []
  31.  
  32. ;; Adds a task to the list
  33. addTask = method(name, body, desc nil,
  34. dependencies = if(name kind?("Pair"), if(name second kind?("List"), name second, [name second]), [])
  35. if(name kind?("Pair"), name = name first)
  36. names = if(name kind?("List"), name, [name])
  37. names each(name,
  38. name = (ns + [name]) join(":")
  39. if(tasks select(t, t name asText == name asText) empty? not, error!("Task `#{name}' already defined"))
  40. @tasks << Task with(name: name, dependencies: dependencies, body: body, desc: desc)
  41. )
  42. )
  43.  
  44. ;; Returns a list of valid Biild files in the search path
  45. getFiles = method(search_path,
  46. ["Biildfile", "biildfile", "Biildfile.ik", "biildfile.ik"] select(file,
  47. FileSystem file?(search_path + FileSystem separator + file)
  48. )
  49. )
  50.  
  51. )
  52.  
  53. namespace = macro(
  54. if(call arguments size != 2, error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
  55. Biild ns << call argAt(0)
  56. call arguments[1] evaluateOn(call ground)
  57. Biild ns pop!
  58. )
  59.  
  60. task = macro(
  61. case(call arguments size,
  62. 1, Biild addTask(call argAt(0), fn(true)),
  63. 2, Biild addTask(call argAt(0), call arguments[1]),
  64. 3, Biild addTask(call argAt(0), call arguments[2], call argAt(1)),
  65. error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)
  66. )
  67. )
  68.  
  69. ;; Add some basic tasks
  70. task(["--tasks", "-T"], "List all tasks and their descriptions",
  71. tasks = Biild tasks select(name[0] != 45)
  72. longest = tasks map(name length) max
  73. tasks each(t,
  74. "biild #{t name}" print
  75. if(t desc is?(nil) not,
  76. (longest - t name length) times(" " print)
  77. desc_trunc = 80 - (longest + 14)
  78. if(t desc length > desc_trunc,
  79. " ; #{t desc[0..desc_trunc]}..." print,
  80. " ; #{t desc}" print
  81. )
  82. )
  83. "" println
  84. )
  85. )
  86.  
  87. task(["--version", "-v"], "Shows current Biild version",
  88. "Biild version 0.1.0" println
  89. true
  90. )
  91.  
  92. task(["--help", "-h"], "Shows basic Biild help",
  93. "Usage: biild [options] rule1 [rule2, rule3, ...]" println
  94. "Execute simple build instructions with the Ioke language." println
  95. "" println
  96. "Options:" println
  97. " -T, --tasks Show all available non-system tasks" println
  98. " -v, --version Show current Biild version" println
  99. " -h, --help Show basic help summary" println
  100. true
  101. )
  102.  
  103. System ifMain(
  104. biildfiles = Biild getFiles(System currentDirectory)
  105. case(biildfiles empty?,
  106. false, source = FileSystem readFully(System currentDirectory + FileSystem separator + biildfiles first),
  107. true, source = nil
  108. )
  109. if(source == nil, error!("No biildfile found"))
  110. Message doText(source)
  111. System programArguments each(opt,
  112. task = Biild tasks select(t, t name asText == opt)
  113. if(task empty? not, task first invoke, error!("No task `#{opt}'"))
  114. if(task first success not, error!("Task `#{task first name}' failed"))
  115. )
  116. )
Add Comment
Please, Sign In to add comment