Skip to content

Commit

Permalink
Create project skeleton generator. It might even work :)
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.code.sf.net/p/segs/code2@142 a19be42f-918d-4297-8077-ab25d1e4f51f
  • Loading branch information
nemerle committed Sep 30, 2009
1 parent af536aa commit 1953d30
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 44 deletions.
52 changes: 52 additions & 0 deletions Utilities/CMakeCreator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env ruby
require 'pp'
class CMakeFile
attr_reader :current_path
def initialize(path,parent=nil)
@parent=parent
@current_path=path
if(path[0]!='.' && parent!=nil) # path relative to parent
@current_path = File.join(parent.current_path,path)
end
end
def create_component(name)
p @current_path
raise "CMakeLists.txt already exists" if File::exists?(File.join(@current_path,"CMakeLists.txt"))
fp = File.open(File.join(@current_path,"CMakeLists.txt"),"w")
fp<<'# $Id:$
SET(target_CPP
)
SET(target_INCLUDE
)
SET(target_INCLUDE_DIR "")
# add components here
# end of additional components
INCLUDE_DIRECTORIES(${target_INCLUDE_DIR})
SET (target_SOURCES
${target_CPP}
${target_INCLUDE}
)
'
fp<<"#ADD_LIBRARY(#{name} STATIC ${target_SOURCES})\n"
fp<<"SEGS_REGISTER_COMPONENT(#{name} ${target_INCLUDE_DIR} ${target_CPP} ${target_INCLUDE} )\n"
fp.close()
end
def parent_dir(path) # returns absolute path of given path
File.expand_path((File.join(path,"..")))
end
# name is the same as the subdir name is the same as the component name
def add_subdir(name,prefix="",optional=false)
build_name = name
build_name = prefix+"_"+name if !prefix.nil?
fp = File.open(File.join(@current_path,"CMakeLists.txt"),"a+")
fp <<"\n"
if(optional)
# add option
fp << "SET(BUILD_#{build_name} TRUE CACHE BOOL \"Build #{name}?\")\n"
end
fp<<"IF(BUILD_#{build_name})\n\t" if(optional)
fp<<"ADD_SUBDIRECTORY(#{name})\n"
fp<<"ENDIF(BUILD_#{build_name})" if(optional)
end
end
57 changes: 13 additions & 44 deletions Utilities/CreateComponent.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,11 @@
#!/usr/bin/env ruby
require 'pp'
require 'CMakeCreator.rb'
def show_usage()
print("usage:\nCreateComponent component_type component_name\n")
print("\tWhere component_type is one of SERVER|CLIENT|COMMON\n")

end
class Dir
def Dir.mkdir_optional(name)
if(File.exist?(name))
print("Warning: directory #{name} already exists\n")
return 0
end
Dir.mkdir(name)
0
end
end
def create_cmakefiles(path,name)
fp = File.open(File.join(path,"CMakeLists.txt"),"w")
fp<<'
# $Id:$
SET(target_CPP
)
SET(target_INCLUDE
)
SET(target_INCLUDE_DIR "")
# add components here
# end of additional components
INCLUDE_DIRECTORIES(${target_INCLUDE_DIR})
SET (target_SOURCES
${target_CPP}
${target_INCLUDE}
)
#ADD_LIBRARY('+name+' STATIC ${target_SOURCES})
SEGS_REGISTER_COMPONENT('+name+' "${target_INCLUDE_DIR}" "${target_CPP}" "${target_INCLUDE}" )'
fp.close()
end
def update_parent_cmakefile(sub_dir,name)
fp = File.open(File.join(sub_dir,"CMakeLists.txt"),"a+")
fp<<"\nADD_SUBDIRECTORY(#{name})\n"
end
def create_component(type,name)
sub_dir=""
case(type.upcase)
Expand All @@ -50,19 +16,22 @@ def create_component(type,name)
when "CLIENT"
sub_dir="Client"
end
Dir.mkdir_optional(File.join(sub_dir,name))
Dir.mkdir_optional(File.join(sub_dir,name,"src"))
Dir.mkdir_optional(File.join(sub_dir,name,"include"))
Dir.mkdir_optional(File.join(sub_dir,name,"Docs"))
update_parent_cmakefile(sub_dir,name)
create_cmakefiles(File.join(sub_dir,name),name)
root_cmake = CMakeFile.new(sub_dir)
component_path = File.join(sub_dir,name)
Dir.mkdir_optional(component_path)
Dir.mkdir_optional(File.join(component_path,"src"))
Dir.mkdir_optional(File.join(component_path,"include"))
Dir.mkdir_optional(File.join(component_path,"docs"))

root_cmake.add_subdir(name)

cm = CMakeFile.new(component_path,root_cmake)
cm.create_component(name)
end
if(ARGV.size()!=2)
show_usage()
else
Dir.chdir("../Components")
create_component(ARGV[0],ARGV[1])
Dir.chdir("../Utilities")
end
end
107 changes: 107 additions & 0 deletions Utilities/CreateProject.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env ruby
require 'pp'
require 'CMakeCreator.rb'
require 'SegsUtil.rb'
def show_usage()
print("usage:\nCreateProject name\n")
print("\tThis utility will create skeleton for the named project \n")
end
class Servers_Creator
def initialize(parent_cmake,prefix,*servers)
@prefix=prefix
@servers_arr=servers
Dir.mkdir_optional(File.join(parent_cmake.current_path,"Servers")) if @servers_arr.size>0
parent_cmake.add_subdir("Servers")
@cmake = CMakeFile.new("Servers",parent_cmake)
end
def create()
@servers_arr.each {|serv| create_server(serv) }
end
def create_server(serv)
@cmake.add_subdir(serv,@prefix,true)
serv_path = File.join(@cmake.current_path,serv)
Dir.mkdir_optional(serv_path)
Dir.mkdir_optional(File.join(serv_path,"src"))
Dir.mkdir_optional(File.join(serv_path,"include"))
Dir.mkdir_optional(File.join(serv_path,"docs"))
CMakeFile.new(serv,@cmake).create_component(@prefix+"_"+serv)
end
end
class Clients_Creator
def initialize(parent_cmake,prefix,*clients)
@prefix=prefix
@clients=clients
parent_cmake.add_subdir("Clients")
Dir.mkdir_optional(File.join(parent_cmake.current_path,"Clients")) if @clients.size>0
@cmake = CMakeFile.new("Clients",parent_cmake)
end
def create()
sub_dir = @cmake.current_path
@clients.each {|client| create_client(client) }
end
def create_client(name)
@cmake.add_subdir(name,@prefix,true)
path = File.join(@cmake.current_path,name)
Dir.mkdir_optional(path)
Dir.mkdir_optional(File.join(path,"src"))
Dir.mkdir_optional(File.join(path,"include"))
Dir.mkdir_optional(File.join(path,"docs"))
CMakeFile.new(name,@cmake).create_component(@prefix+"_"+name)
end
end
class Common_Creator
def initialize(parent_cmake,prefix,topname,*subs)
@prefix=prefix
@subs=subs
parent_cmake.add_subdir(topname)
Dir.mkdir_optional(File.join(parent_cmake.current_path,topname))
@cmake = CMakeFile.new(topname,parent_cmake)
end
def create()
sub_dir = @cmake.current_path
@subs.each {|sub| create_sub(sub) }
end
def create_sub(name)
@cmake.add_subdir(name,@prefix,true)
path = File.join(@cmake.current_path,name)
Dir.mkdir_optional(path)
Dir.mkdir_optional(File.join(path,"src"))
Dir.mkdir_optional(File.join(path,"include"))
Dir.mkdir_optional(File.join(path,"docs"))
CMakeFile.new(name,@cmake).create_component(@prefix+"_"+name)
end
end
class Data_Creator
def initialize(cmake,*servers)
@servers_arr=servers
@cmake = cmake
end
end
class Docs_Creator
def initialize(cmake,*servers)
@servers_arr=servers
@cmake = cmake
end
end

if(ARGV.size()!=1)
show_usage()
else
Dir.chdir("../Projects")
root_cmake = CMakeFile.new(".") # Top dir in Projects
project_dir = File.join(root_cmake.current_path,ARGV[0])
Dir.mkdir_optional(project_dir)

project_root = CMakeFile.new(project_dir,root_cmake)
root_cmake.add_subdir(ARGV[0],"",true)
sc = Servers_Creator.new(project_root,ARGV[0],"TestServer","LoginServer")
sc.create()
cc = Clients_Creator.new(project_root,ARGV[0],"CliClient","GuiClient")
cc.create()
Common_Creator.new(project_root,ARGV[0],"Common").create()
Common_Creator.new(project_root,ARGV[0],"Utilities").create()
Common_Creator.new(project_root,ARGV[0],"Data").create()
Common_Creator.new(project_root,ARGV[0],"Docs").create()
end


11 changes: 11 additions & 0 deletions Utilities/SegsUtil.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
class Dir
def Dir.mkdir_optional(name)
if(File.exist?(name))
print("Warning: directory #{name} already exists\n")
return 0
end
Dir.mkdir(name)
0
end
end

0 comments on commit 1953d30

Please sign in to comment.