22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/cmaker.rb', line 22
def self.create_project(project_name)
if project_name == nil
puts GemStrings.no_project_name_error()
return
end
project_dir_path = project_name
if Dir.exists?(project_dir_path)
puts "Can't create project. There's already a directory with the name \'#{project_name}\'."
return
end
puts "Creating project \'#{project_name}\'..."
temp_dir_path = "#{project_name}/.tmp"
executable_name = "run#{project_name}"
test_executable_name = "run#{project_name}Tests"
code_dir_name = project_name
code_dir_path = "#{project_name}/#{code_dir_name}"
test_dir_name = "#{project_name}Tests"
test_dir_path = "#{project_name}/#{test_dir_name}"
main_file_path = "#{project_dir_path}/main.cpp"
test_lib_dir_path = "#{test_dir_path}/lib"
gtest_dir_name = "lib/#{GOOGLE_TEST_DIR_NAME}"
gtest_dir_path = "#{test_dir_path}/#{gtest_dir_name}"
unit_test_dir_name = "tests"
unit_test_dir_path = "#{test_dir_path}/#{unit_test_dir_name}"
empty_test_file_name = "empty_test.cpp"
empty_test_file_path = "#{test_dir_path}/#{unit_test_dir_name}/#{empty_test_file_name}"
= "#{project_name}.h"
= "#{code_dir_path}/#{}"
empty_cpp_name = "#{project_name}.cpp"
empty_cpp_file_path = "#{code_dir_path}/#{empty_cpp_name}"
project_cmake = GemStrings.project_dir_cmake_content(project_name, executable_name, code_dir_name, test_dir_name)
code_make = GemStrings.code_dir_cmake_content(code_dir_name, , empty_cpp_name)
test_cmake = GemStrings.test_dir_cmake_content(test_dir_name, gtest_dir_name, unit_test_dir_name)
tests_cmake = GemStrings.tests_dir_cmake_content(test_executable_name, empty_test_file_name, code_dir_name)
FileHelpers.create_directory(temp_dir_path, nil)
FileHelpers.create_directory(project_dir_path, project_cmake)
FileHelpers.create_directory(code_dir_path, code_make)
FileHelpers.create_directory(test_dir_path, test_cmake)
FileHelpers.create_directory(gtest_dir_path, nil)
FileHelpers.create_directory(unit_test_dir_path, tests_cmake)
FileHelpers.write_string_to_file(GemStrings.main_file_content(), main_file_path)
FileHelpers.write_string_to_file(GemStrings.empty_test_file_content(), empty_test_file_path)
FileHelpers.write_string_to_file(GemStrings.(), )
FileHelpers.write_string_to_file(GemStrings.empty_cpp_contents(), empty_cpp_file_path)
puts "Adding \'Google Test\'..."
begin
self.add_google_test(test_lib_dir_path, temp_dir_path)
rescue
puts "Google Test installation failed, unable to create project"
self.handle_fatal_error(project_dir_path)
return
end
FileHelpers.delete_directory(temp_dir_path)
puts "Finished successfully"
end
|