PageRenderTime 47ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/tool/geant/src/command/geant_copy_command.e

http://github.com/gobo-eiffel/gobo
Specman e | 232 lines | 172 code | 36 blank | 24 comment | 11 complexity | b7b38836d978258366609a8b253e8c65 MD5 | raw file
  1. note
  2. description:
  3. "Copy commands"
  4. library: "Gobo Eiffel Ant"
  5. copyright: "Copyright (c) 2001-2018, Sven Ehrke and others"
  6. license: "MIT License"
  7. date: "$Date$"
  8. revision: "$Revision$"
  9. class GEANT_COPY_COMMAND
  10. inherit
  11. GEANT_FILESYSTEM_COMMAND
  12. KL_IMPORTED_BOOLEAN_ROUTINES
  13. export {NONE} all end
  14. create
  15. make
  16. feature -- Status report
  17. is_file_to_file_executable: BOOLEAN
  18. -- Can command be executed on sourcefile `file' to targetfile `to_file'?
  19. do
  20. Result := attached file as l_file and then l_file.count > 0 and then
  21. attached to_file as l_to_file and then l_to_file.count > 0
  22. ensure
  23. file_not_void_and_not_empty: Result implies attached file as l_file and then l_file.count > 0
  24. to_file_not_void_and_not_empty: Result implies attached to_file as l_to_file and then l_to_file.count > 0
  25. end
  26. is_file_to_directory_executable: BOOLEAN
  27. -- Can command be executed on sourcefile `file' to targetdirectory `to_directory'?
  28. do
  29. Result := attached file as l_file and then l_file.count > 0 and then
  30. attached to_directory as l_to_directory and then l_to_directory.count > 0
  31. ensure
  32. file_not_void_and_not_empty: Result implies attached file as l_file and then l_file.count > 0
  33. to_directory_not_void_and_not_empty: Result implies attached to_directory as l_to_directory and then l_to_directory.count > 0
  34. end
  35. is_fileset_to_directory_executable: BOOLEAN
  36. -- Can command be executed on source fileset `fileset' to targetdirectory `to_directory'?
  37. do
  38. Result := fileset /= Void and then
  39. attached to_directory as l_to_directory and then l_to_directory.count > 0
  40. ensure
  41. fileset_not_void: Result implies fileset /= Void
  42. to_directory_not_void_and_not_empty: Result implies attached to_directory as l_to_directory and then l_to_directory.count > 0
  43. end
  44. is_executable: BOOLEAN
  45. -- Can command be executed?
  46. do
  47. Result := BOOLEAN_.nxor (<<is_file_to_file_executable,
  48. is_file_to_directory_executable, is_fileset_to_directory_executable>>)
  49. ensure then
  50. exclusive: Result implies BOOLEAN_.nxor (<<is_file_to_file_executable,
  51. is_file_to_directory_executable, is_fileset_to_directory_executable>>)
  52. end
  53. feature -- Access
  54. file: detachable STRING
  55. -- Name of source file to copy
  56. to_file: detachable STRING
  57. -- Name of destination file
  58. to_directory: detachable STRING
  59. -- Name of destination directory
  60. fileset: detachable GEANT_FILESET
  61. -- Fileset for current command
  62. force: BOOLEAN
  63. -- Should source files be copied over target files,
  64. -- provided the target files exist, even when target files
  65. -- are newer than their corresponding source files?
  66. feature -- Setting
  67. set_file (a_file: like file)
  68. -- Set `file' to `a_file'.
  69. require
  70. a_file_not_void: a_file /= Void
  71. a_file_not_empty: a_file.count > 0
  72. do
  73. file := a_file
  74. ensure
  75. file_set: file = a_file
  76. end
  77. set_to_file (a_to_file: like to_file)
  78. -- Set `to_file' to `a_to_file'.
  79. require
  80. a_to_file_not_void: a_to_file /= Void
  81. a_to_file_not_empty: a_to_file.count > 0
  82. do
  83. to_file := a_to_file
  84. ensure
  85. to_file_set: to_file = a_to_file
  86. end
  87. set_to_directory (a_to_directory: like to_directory)
  88. -- Set `to_directory' to `a_to_directory'.
  89. require
  90. a_to_directory_not_void: a_to_directory /= Void
  91. a_to_directory_not_empty: a_to_directory.count > 0
  92. do
  93. to_directory := a_to_directory
  94. ensure
  95. to_directory_set: to_directory = a_to_directory
  96. end
  97. set_fileset (a_fileset: like fileset)
  98. -- Set `fileset' to `a_fileset'.
  99. require
  100. a_fileset_not_void: a_fileset /= Void
  101. do
  102. fileset := a_fileset
  103. ensure
  104. fileset_set: fileset = a_fileset
  105. end
  106. set_force (b: BOOLEAN)
  107. -- Set `force' to `b'.
  108. do
  109. force := b
  110. ensure
  111. force_set: force = b
  112. end
  113. feature -- Execution
  114. execute
  115. -- Execute command.
  116. local
  117. a_from_file: STRING
  118. a_to_file: STRING
  119. a_basename: STRING
  120. do
  121. exit_code := 0
  122. if is_file_to_directory_executable and then attached file as l_file and then attached to_directory as l_to_directory then
  123. -- Make sure directory named `to_directory' exists:
  124. create_directory (l_to_directory)
  125. if exit_code = 0 then
  126. a_basename := unix_file_system.basename (l_file)
  127. a_to_file := unix_file_system.pathname (l_to_directory, a_basename)
  128. copy_file (l_file, a_to_file)
  129. end
  130. elseif is_file_to_file_executable and then attached file as l_file and then attached to_file as l_to_file then
  131. copy_file (l_file, l_to_file)
  132. else
  133. check is_fileset_to_directory_executable: is_fileset_to_directory_executable and then attached fileset as l_fileset and then attached to_directory as l_to_directory then
  134. if not l_fileset.is_executable then
  135. project.log (<<" [copy] error: fileset definition wrong">>)
  136. exit_code := 1
  137. end
  138. if exit_code = 0 then
  139. l_fileset.execute
  140. from
  141. l_fileset.start
  142. until
  143. l_fileset.after or else exit_code /= 0
  144. loop
  145. if l_fileset.is_in_gobo_31_format and then attached l_fileset.directory_name as l_fileset_directory_name then
  146. a_from_file := unix_file_system.pathname (l_fileset_directory_name, l_fileset.item_filename)
  147. else
  148. a_from_file := l_fileset.item_filename
  149. end
  150. a_to_file := unix_file_system.pathname (l_to_directory, l_fileset.item_mapped_filename)
  151. -- Create target directory if necessary:
  152. create_directory_for_pathname (a_to_file)
  153. copy_file (a_from_file, a_to_file)
  154. l_fileset.forth
  155. end
  156. end
  157. end
  158. end
  159. end
  160. feature {NONE} -- Implementation
  161. copy_file (a_source_file, a_target_file: STRING)
  162. -- Copy `a_source_file' to `a_target_file;
  163. -- Set `exit_code' in case `a_source_file' does
  164. -- not exist or could not be copied.
  165. require
  166. a_source_file_not_void: a_source_file /= Void
  167. a_source_file_not_empty: a_source_file.count > 0
  168. a_target_file_not_void: a_target_file /= Void
  169. a_target_file_not_empty: a_target_file.count > 0
  170. local
  171. new_name, old_name: STRING
  172. do
  173. old_name := file_system.pathname_from_file_system (a_source_file, unix_file_system)
  174. new_name := file_system.pathname_from_file_system (a_target_file, unix_file_system)
  175. if not file_system.file_exists (old_name) then
  176. -- Check that source file exists:
  177. project.trace (<<" [copy] ", old_name, " to ", new_name>>)
  178. project.log (<<" [copy] error: cannot find file '", old_name, "%'">>)
  179. exit_code := 1
  180. else
  181. -- Copy file if target is out of date:
  182. if force or else is_file_outofdate (old_name, new_name) then
  183. project.trace (<<" [copy] ", old_name, " to ", new_name>>)
  184. if not project.options.no_exec then
  185. file_system.copy_file (old_name, new_name)
  186. if not file_system.file_exists (new_name) then
  187. project.log (<<" [copy] error: cannot copy file '", old_name, "' to file '", new_name, "%'">>)
  188. exit_code := 1
  189. end
  190. end
  191. else
  192. project.trace_debug (<<" [*copy] not necessary to copy ", old_name, " to ", new_name>>)
  193. end
  194. end
  195. end
  196. end