Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. defmodule RustCompile do
  2. @rust_path "D:/var/Rust/hello"
  3. @rust_target "D:/var/Rust/hello/bin"
  4.  
  5. def get_files(path_name) do
  6. with {:ok, files} <- File.ls(path_name) do
  7. files
  8. else
  9. {:error, reason} ->
  10. reason
  11. end
  12. end
  13.  
  14. def run do
  15. error_file = Path.expand(".") <> "/list_error_compile.txt"
  16. if File.exists?(error_file) do
  17. File.rm(error_file)
  18. end
  19.  
  20. files =
  21. Enum.filter(get_files(@rust_path), fn x ->
  22. fullpath = Path.join([@rust_path, x])
  23. !File.dir?(fullpath)
  24. end)
  25.  
  26. Enum.each(files, fn file ->
  27. if Path.extname(file) == ".rs" do
  28. IO.puts("Compiling '#{file}'..")
  29. t = Task.async(fn -> compile_rust(@rust_path <> "/" <> file, @rust_target) end)
  30. Task.await(t)
  31. end
  32. end)
  33.  
  34. delete_debug_files(@rust_target)
  35. end
  36.  
  37. def compile_rust(file_name, target) do
  38. {result, exit_code} = System.cmd("rustc", ["-v", "-O", "--out-dir=" <> target, file_name], stderr_to_stdout: true)
  39. if exit_code > 0 do
  40. {:ok, file} = File.open(Path.expand(".") <> "/list_error_compile.txt", [:append])
  41. IO.binwrite(file, file_name <> "\n")
  42. IO.binwrite(file, result <> "\n--------------------------------------------------\n")
  43. File.close(file)
  44. end
  45. end
  46.  
  47. def delete_debug_files(path) do
  48. files = Enum.filter(get_files(path), fn x ->
  49. fullpath = Path.join([@rust_target, x])
  50. !File.dir?(fullpath)
  51. end)
  52.  
  53. Enum.each(files, fn file ->
  54. if Path.extname(file) == ".pdb" do
  55. IO.puts("Menghapus '#{file}'..")
  56. File.rm!(@rust_target <> "/" <> file)
  57. end
  58. end)
  59. end
  60. end
  61.  
  62. RustCompile.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement