main.swift 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2017, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Foundation
  17. let TEMPLATES = "Templates"
  18. var s = ""
  19. s += "/*\n"
  20. s += " *\n"
  21. s += " * Copyright 2017, Google Inc.\n"
  22. s += " * All rights reserved.\n"
  23. s += " *\n"
  24. s += " * Redistribution and use in source and binary forms, with or without\n"
  25. s += " * modification, are permitted provided that the following conditions are\n"
  26. s += " * met:\n"
  27. s += " *\n"
  28. s += " * * Redistributions of source code must retain the above copyright\n"
  29. s += " * notice, this list of conditions and the following disclaimer.\n"
  30. s += " * * Redistributions in binary form must reproduce the above\n"
  31. s += " * copyright notice, this list of conditions and the following disclaimer\n"
  32. s += " * in the documentation and/or other materials provided with the\n"
  33. s += " * distribution.\n"
  34. s += " * * Neither the name of Google Inc. nor the names of its\n"
  35. s += " * contributors may be used to endorse or promote products derived from\n"
  36. s += " * this software without specific prior written permission.\n"
  37. s += " *\n"
  38. s += " * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
  39. s += " * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
  40. s += " * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
  41. s += " * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n"
  42. s += " * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
  43. s += " * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
  44. s += " * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
  45. s += " * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
  46. s += " * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
  47. s += " * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
  48. s += " * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
  49. s += " *\n"
  50. s += " */\n"
  51. s += "// GENERATED: DO NOT EDIT\n"
  52. s += "//\n"
  53. s += "// This file contains base64 encodings of templates used for Swift GRPC code generation.\n"
  54. s += "//\n"
  55. s += "func loadTemplates() -> [String:String] {\n"
  56. s += " var templates : [String:String] = [:]\n"
  57. let filenames = try FileManager.default.contentsOfDirectory(atPath:TEMPLATES)
  58. for filename in filenames {
  59. if filename.hasSuffix(".swift") {
  60. let fileURL = URL(fileURLWithPath:TEMPLATES + "/" + filename)
  61. let filedata = try Data(contentsOf:fileURL)
  62. let encoding = filedata.base64EncodedString()
  63. s += "\n"
  64. s += " templates[\"" + filename + "\"] = \"" + encoding + "\"\n"
  65. }
  66. }
  67. s += " return templates\n"
  68. s += "}\n"
  69. print(s)