/src/tools/main/liberty_main.e

http://github.com/tybor/Liberty · Specman e · 139 lines · 103 code · 19 blank · 17 comment · 3 complexity · d0dbce6e4f848544b238ea13717adcd6 MD5 · raw file

  1. -- This file is part of Liberty Eiffel.
  2. --
  3. -- Liberty Eiffel is free software: you can redistribute it and/or modify
  4. -- it under the terms of the GNU General Public License as published by
  5. -- the Free Software Foundation, version 3 of the License.
  6. --
  7. -- Liberty Eiffel is distributed in the hope that it will be useful,
  8. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. -- GNU General Public License for more details.
  11. --
  12. -- You should have received a copy of the GNU General Public License
  13. -- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>.
  14. --
  15. deferred class LIBERTY_MAIN
  16. --
  17. -- Provides a common structure for Liberty tools.
  18. --
  19. insert
  20. ARGUMENTS
  21. LOGGING
  22. feature {}
  23. make is
  24. local
  25. root: LIBERTY_ACTUAL_TYPE
  26. root_feature_name: LIBERTY_FEATURE_NAME
  27. etc: LIBERTY_ETC
  28. log_location: like default_log_location
  29. do
  30. log_location := default_log_location
  31. if not arguments.parse_command_line then
  32. arguments.usage(std_error)
  33. die_with_code(1)
  34. end
  35. etc.configure_for(arg_loadpath.item, create {LIBERTY_ETC_VISITOR_IMPL}.make("libertyi"))
  36. set_log(log_location)
  37. etc.log_clusters
  38. create universe.make
  39. create root_feature_name.make(arg_root_feature_name.item)
  40. root := universe.get_type(Void, errors.unknown_position, arg_root_type.item, create {FAST_ARRAY[LIBERTY_ACTUAL_TYPE]}.with_capacity(0))
  41. run(root, root_feature_name)
  42. end
  43. arg_loadpath, arg_root_type, arg_root_feature_name: COMMAND_LINE_TYPED_ARGUMENT[FIXED_STRING]
  44. opt_variables: COMMAND_LINE_TYPED_ARGUMENT[TRAVERSABLE[FIXED_STRING]]
  45. opt_log_level: COMMAND_LINE_TYPED_ARGUMENT[LIBERTY_MAIN_LOG_LEVEL]
  46. opt_check_level: COMMAND_LINE_TYPED_ARGUMENT[LIBERTY_MAIN_CHECK_LEVEL]
  47. opt_debug: COMMAND_LINE_TYPED_ARGUMENT[BOOLEAN]
  48. arguments: COMMAND_LINE_ARGUMENTS is
  49. local
  50. factory: COMMAND_LINE_ARGUMENT_FACTORY
  51. log_level_factory: COMMAND_LINE_ARGUMENT_CUSTOM_FACTORY[LIBERTY_MAIN_LOG_LEVEL]
  52. check_level_factory: COMMAND_LINE_ARGUMENT_CUSTOM_FACTORY[LIBERTY_MAIN_CHECK_LEVEL]
  53. log_level: LIBERTY_MAIN_LOG_LEVEL
  54. check_level: LIBERTY_MAIN_CHECK_LEVEL
  55. once
  56. arg_loadpath := factory.positional_string("loadpath", "The path to the root loadpath.se")
  57. arg_root_type := factory.positional_string("root type", "The name of the root type")
  58. arg_root_feature_name := factory.positional_string("root feature name", "The name of the creation feature in the root type")
  59. opt_variables := factory.option_strings("v", "variable", "variable", "[
  60. var=value -- Set the variable 'var' to 'value'.
  61. Useful for plugin paths. For example:
  62. -v sys=`se -environment | grep '^SE_SYS=' | cut -c8-`
  63. ]")
  64. opt_log_level := log_level_factory.option_custom("l", "log", "log level", "The log level: trace, info, warning, error",
  65. agent log_level.valid_arg,
  66. agent log_level.set)
  67. opt_check_level := check_level_factory.option_custom("c", "check", "check level", "The contract checking level: all, invariant, ensure, require, none",
  68. agent check_level.valid_arg,
  69. agent check_level.set)
  70. opt_debug := factory.option_boolean("d", "debug", "Enable debug sections")
  71. create Result.make(arg_loadpath and arg_root_type and arg_root_feature_name
  72. and opt_variables and opt_log_level and opt_check_level and opt_debug
  73. and factory.remaining_parameters)
  74. end
  75. usage is
  76. do
  77. arguments.usage(std_error)
  78. die_with_code(1)
  79. end
  80. run (root: LIBERTY_ACTUAL_TYPE; root_feature_name: LIBERTY_FEATURE_NAME) is
  81. require
  82. root /= Void
  83. root_feature_name /= Void
  84. deferred
  85. end
  86. set_log (logpath: STRING) is
  87. local
  88. log_conf: LOG_CONFIGURATION
  89. tfr: TEXT_FILE_READ
  90. do
  91. env.substitute(logpath)
  92. create tfr.connect_to(logpath)
  93. if not tfr.is_connected then
  94. std_error.put_line("Unknown log configuration file: " + logpath)
  95. die_with_code(1)
  96. end
  97. log_conf.load(tfr, agent on_error, agent resolve_path)
  98. tfr.disconnect
  99. end
  100. on_error (message: STRING) is
  101. do
  102. std_error.put_line(message)
  103. die_with_code(1)
  104. end
  105. levels: LOG_LEVELS
  106. env: LIBERTY_ENVIRONMENT
  107. default_log_location: STRING is
  108. deferred
  109. ensure
  110. Result /= Void
  111. end
  112. errors: LIBERTY_ERRORS
  113. universe: LIBERTY_UNIVERSE
  114. resolve_path (a_path: STRING): STRING is
  115. do
  116. Result := once ""
  117. Result.copy(a_path)
  118. env.substitute(Result)
  119. end
  120. end -- class LIBERTY_MAIN