From 7bdb082c91727b8ba90981051a81228db83bc20d Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 22 Sep 2013 06:59:52 +0800 Subject: [PATCH 01/11] Delete SConscript --- libcpu/arm/am335x/SConscript | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 libcpu/arm/am335x/SConscript diff --git a/libcpu/arm/am335x/SConscript b/libcpu/arm/am335x/SConscript deleted file mode 100644 index 2ad51b573e..0000000000 --- a/libcpu/arm/am335x/SConscript +++ /dev/null @@ -1,17 +0,0 @@ -Import('rtconfig') -from building import * - -cwd = GetCurrentDir() -src = Glob('*.c') -CPPPATH = [cwd] - -if rtconfig.PLATFORM == 'iar': - src += Glob('*_iar.S') -elif rtconfig.PLATFORM == 'gcc': - src += Glob('*_gcc.S') -elif rtconfig.PLATFORM == 'armcc': - src += Glob('*_rvds.S') - -group = DefineGroup('AM1808', src, depend = [''], CPPPATH = CPPPATH) - -Return('group') From 6d2df9bf9400acd6716a2a3c0b5c02f7973cc43c Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sun, 22 Sep 2013 22:12:04 +0800 Subject: [PATCH 02/11] finsh: unregister rx_indicate when closing the device Because the device could still remain opened when closed by finsh, the old rx_indicate is useless for finsh. Some buggy driver will still generate rx_indicate even after the device has been closed. So FinSh should unregister the rx_indicate when releasing the old device. --- components/finsh/shell.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 19dd93691e..8ff0e89e44 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -131,6 +131,7 @@ void finsh_set_device(const char* device_name) { /* close old finsh device */ rt_device_close(shell->device); + rt_device_set_rx_indicate(dev, RT_NULL); } shell->device = dev; From 7b0a3afdf90e85cabe3e39f49a5c2aa22e3e3e8d Mon Sep 17 00:00:00 2001 From: Grissiom Date: Mon, 23 Sep 2013 11:27:48 +0800 Subject: [PATCH 03/11] kservice: export vsnprintf as rt_vsnprintf vsnprintf is a common string function that could be used in many places. Using both vsnprintf in libc and vsnprintf in the RTT could make a bigger image. Moreover, if newlib is not enabled when compiling with GCC, referencing vsnprintf will lead to link error: .../arm-none-eabi/lib/armv7-ar/thumb/softfp/libc.a(lib_a-sbrkr.o): In function `_sbrk_r': sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk' collect2: error: ld returned 1 exit status Using rt_vsnprintf could avoid such problem. --- include/rtthread.h | 1 + src/kservice.c | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/rtthread.h b/include/rtthread.h index 28c0192291..b68a301a5c 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -469,6 +469,7 @@ int rt_system_module_init(void); void rt_kprintf(const char *fmt, ...); #endif rt_int32_t rt_vsprintf(char *dest, const char *format, va_list arg_ptr); +rt_int32_t rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args); rt_int32_t rt_sprintf(char *buf ,const char *format, ...); rt_int32_t rt_snprintf(char *buf, rt_size_t size, const char *format, ...); diff --git a/src/kservice.c b/src/kservice.c index ff5ff9de2a..c2fa43ba73 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -718,10 +718,10 @@ static char *print_number(char *buf, return buf; } -static rt_int32_t vsnprintf(char *buf, - rt_size_t size, - const char *fmt, - va_list args) +rt_int32_t rt_vsnprintf(char *buf, + rt_size_t size, + const char *fmt, + va_list args) { #ifdef RT_PRINTF_LONGLONG unsigned long long num; @@ -976,6 +976,7 @@ static rt_int32_t vsnprintf(char *buf, */ return str - buf; } +RTM_EXPORT(rt_vsnprintf); /** * This function will fill a formatted string to buffer @@ -990,7 +991,7 @@ rt_int32_t rt_snprintf(char *buf, rt_size_t size, const char *fmt, ...) va_list args; va_start(args, fmt); - n = vsnprintf(buf, size, fmt, args); + n = rt_vsnprintf(buf, size, fmt, args); va_end(args); return n; @@ -1006,7 +1007,7 @@ RTM_EXPORT(rt_snprintf); */ rt_int32_t rt_vsprintf(char *buf, const char *format, va_list arg_ptr) { - return vsnprintf(buf, (rt_size_t) -1, format, arg_ptr); + return rt_vsnprintf(buf, (rt_size_t) -1, format, arg_ptr); } RTM_EXPORT(rt_vsprintf); @@ -1114,7 +1115,7 @@ void rt_kprintf(const char *fmt, ...) * large excluding the terminating null byte. If the output string * would be larger than the rt_log_buf, we have to adjust the output * length. */ - length = vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args); + length = rt_vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args); if (length > RT_CONSOLEBUF_SIZE - 1) length = RT_CONSOLEBUF_SIZE - 1; #ifdef RT_USING_DEVICE From 783a6a67176e5594bed0cbba82cb9f0ef70e3863 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Mon, 23 Sep 2013 13:13:03 +0800 Subject: [PATCH 04/11] logtrace: cleanup code and fix compiling warnings --- components/utilities/logtrace/log_trace.c | 4 ++-- components/utilities/logtrace/log_trace.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/utilities/logtrace/log_trace.c b/components/utilities/logtrace/log_trace.c index 79d5a21884..cc55b1dd44 100644 --- a/components/utilities/logtrace/log_trace.c +++ b/components/utilities/logtrace/log_trace.c @@ -41,7 +41,7 @@ static struct rt_device _log_device; static rt_device_t _traceout_device = RT_NULL; /* define a default lg session. The name is empty. */ -static struct log_trace_session _def_session = {{0}, LOG_TRACE_LEVEL_INFO}; +static struct log_trace_session _def_session = {{"\0"}, LOG_TRACE_LEVEL_INFO}; static struct log_trace_session *_the_sessions[LOG_TRACE_MAX_SESSION] = {&_def_session}; /* there is a default session at least */ static rt_uint16_t _the_sess_nr = 1; @@ -272,7 +272,7 @@ static void _lg_fmtout( _trace_buf[0] = ']'; ptr = &_trace_buf[1]; - length = vsnprintf(ptr, LOG_TRACE_BUFSZ, fmt, argptr); + length = rt_vsnprintf(ptr, LOG_TRACE_BUFSZ, fmt, argptr); if (length >= LOG_TRACE_BUFSZ) length = LOG_TRACE_BUFSZ - 1; diff --git a/components/utilities/logtrace/log_trace.h b/components/utilities/logtrace/log_trace.h index d5a028f553..42240858fb 100644 --- a/components/utilities/logtrace/log_trace.h +++ b/components/utilities/logtrace/log_trace.h @@ -140,12 +140,12 @@ rt_err_t log_trace_set_device(const char *device_name); void log_trace_flush(void); +#ifdef RT_USING_DFS /** set the backend to file */ void log_trace_set_file(const char *filename); -/* log trace for NAND Flash */ -void log_trace_nand_init(const char *nand_device); void log_trace_file_init(const char *filename); +#endif /* RT_USING_DFS */ #endif From 519982fa7411a71d1494855e945196c33c793aee Mon Sep 17 00:00:00 2001 From: Grissiom Date: Mon, 23 Sep 2013 15:10:02 +0800 Subject: [PATCH 05/11] logtrace: add LOG_TRACE_VERBOSE log level --- components/utilities/logtrace/log_trace.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/utilities/logtrace/log_trace.h b/components/utilities/logtrace/log_trace.h index 42240858fb..68442dd2f8 100644 --- a/components/utilities/logtrace/log_trace.h +++ b/components/utilities/logtrace/log_trace.h @@ -33,7 +33,8 @@ #define LOG_TRACE_LEVEL_ERROR 0x01 #define LOG_TRACE_LEVEL_WARNING 0x02 #define LOG_TRACE_LEVEL_INFO 0x03 -#define LOG_TRACE_LEVEL_DEBUG 0x04 +#define LOG_TRACE_LEVEL_VERBOSE 0x04 +#define LOG_TRACE_LEVEL_DEBUG 0x05 #define LOG_TRACE_LEVEL_ALL 0x0f #ifndef LOG_TRACE_LEVEL_DEFAULT @@ -43,7 +44,8 @@ #define LOG_TRACE_ERROR "<1>" #define LOG_TRACE_WARNING "<2>" #define LOG_TRACE_INFO "<3>" -#define LOG_TRACE_DEBUG "<4>" +#define LOG_TRACE_VERBOSE "<4>" +#define LOG_TRACE_DEBUG "<5>" #define LOG_TRACE_OPT_NOTS 0x10 /* no timestamp */ #define LOG_TRACE_OPT_LN 0x20 /* terminate the current line */ From 2a203377073573ac1a3191fc6cc8f71e308ab123 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Mon, 23 Sep 2013 15:13:45 +0800 Subject: [PATCH 06/11] logtrace: adjust the log values logtrace only use odd number of log levels. So the use could set some custom level amount them. --- components/utilities/logtrace/log_trace.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/components/utilities/logtrace/log_trace.h b/components/utilities/logtrace/log_trace.h index 68442dd2f8..77e1f08b6c 100644 --- a/components/utilities/logtrace/log_trace.h +++ b/components/utilities/logtrace/log_trace.h @@ -31,10 +31,10 @@ #define LOG_TRACE_LEVEL_MASK 0x0f #define LOG_TRACE_LEVEL_NOTRACE 0x00 #define LOG_TRACE_LEVEL_ERROR 0x01 -#define LOG_TRACE_LEVEL_WARNING 0x02 -#define LOG_TRACE_LEVEL_INFO 0x03 -#define LOG_TRACE_LEVEL_VERBOSE 0x04 -#define LOG_TRACE_LEVEL_DEBUG 0x05 +#define LOG_TRACE_LEVEL_WARNING 0x03 +#define LOG_TRACE_LEVEL_INFO 0x05 +#define LOG_TRACE_LEVEL_VERBOSE 0x07 +#define LOG_TRACE_LEVEL_DEBUG 0x09 #define LOG_TRACE_LEVEL_ALL 0x0f #ifndef LOG_TRACE_LEVEL_DEFAULT @@ -42,10 +42,10 @@ #endif #define LOG_TRACE_ERROR "<1>" -#define LOG_TRACE_WARNING "<2>" -#define LOG_TRACE_INFO "<3>" -#define LOG_TRACE_VERBOSE "<4>" -#define LOG_TRACE_DEBUG "<5>" +#define LOG_TRACE_WARNING "<3>" +#define LOG_TRACE_INFO "<5>" +#define LOG_TRACE_VERBOSE "<7>" +#define LOG_TRACE_DEBUG "<9>" #define LOG_TRACE_OPT_NOTS 0x10 /* no timestamp */ #define LOG_TRACE_OPT_LN 0x20 /* terminate the current line */ From 05651e7c662139a1d56c6ee0d859ae190346b314 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Thu, 26 Sep 2013 11:49:33 +0800 Subject: [PATCH 07/11] logtrace: only export cmd when finsh is enabled --- components/utilities/logtrace/log_file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/utilities/logtrace/log_file.c b/components/utilities/logtrace/log_file.c index 72e4724b63..2f4a28b63c 100644 --- a/components/utilities/logtrace/log_file.c +++ b/components/utilities/logtrace/log_file.c @@ -121,6 +121,9 @@ void log_trace_set_file(const char *filename) log_trace_file_init(filename); log_trace_set_device("logfile"); } +#ifdef RT_USING_FINSH +#include FINSH_FUNCTION_EXPORT_ALIAS(log_trace_set_file, log_file, set output filename of log trace); +#endif #endif /* RT_USING_DFS */ From df4e8ff060fc2d3f6092df0e9ba75ffba0650a1e Mon Sep 17 00:00:00 2001 From: Grissiom Date: Thu, 26 Sep 2013 11:50:28 +0800 Subject: [PATCH 08/11] msh: only export cd/pwd when DFS_USING_WORKDIR is set --- components/finsh/msh_cmd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/finsh/msh_cmd.c b/components/finsh/msh_cmd.c index fac90479c8..cffb374c2e 100644 --- a/components/finsh/msh_cmd.c +++ b/components/finsh/msh_cmd.c @@ -136,6 +136,7 @@ int cmd_rm(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_rm, __cmd_rm, "Remove (unlink) the FILE(s)."); +#ifdef DFS_USING_WORKDIR int cmd_cd(int argc, char** argv) { if (argc == 1) @@ -157,6 +158,7 @@ int cmd_pwd(int argc, char** argv) return 0; } FINSH_FUNCTION_EXPORT_ALIAS(cmd_pwd, __cmd_pwd, Print the name of the current working directory.); +#endif int cmd_mkdir(int argc, char** argv) { From 12a636621771a838f808acd25758dd061a686993 Mon Sep 17 00:00:00 2001 From: prife Date: Sat, 28 Sep 2013 14:43:00 +0800 Subject: [PATCH 09/11] DFS/jffs2: fix file mode init bug in jffs2_open/opendir found by haitao52198 URL:http://www.rt-thread.org/phpBB3/viewtopic.php?f=3&t=3112&p=17153#p17153 --- components/dfs/filesystems/jffs2/src/fs-ecos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/dfs/filesystems/jffs2/src/fs-ecos.c b/components/dfs/filesystems/jffs2/src/fs-ecos.c index 5f3b5d607c..814d2e3010 100644 --- a/components/dfs/filesystems/jffs2/src/fs-ecos.c +++ b/components/dfs/filesystems/jffs2/src/fs-ecos.c @@ -747,7 +747,7 @@ int jffs2_open(cyg_mtab_entry * mte, cyg_dir dir, const char *name, } // Initialise the file object - file->f_flag |= mode & CYG_FILE_MODE_MASK; + file->f_flag = mode & CYG_FILE_MODE_MASK; file->f_type = CYG_FILE_TYPE_FILE; file->f_ops = &jffs2_fileops; file->f_offset = (mode & O_APPEND) ? node->i_size : 0; @@ -1065,6 +1065,7 @@ static int jffs2_opendir(cyg_mtab_entry * mte, cyg_dir dir, const char *name, // Initialize the file object, setting the f_ops field to a // special set of file ops. + file->f_flag = 0; file->f_type = CYG_FILE_TYPE_FILE; file->f_ops = &jffs2_dirops; file->f_offset = 0; From f71f0595d68b42709f93c524a9d2ad4a85c75489 Mon Sep 17 00:00:00 2001 From: prife Date: Sat, 28 Sep 2013 14:57:05 +0800 Subject: [PATCH 10/11] DFS/jffs2: fix bug when umount jffs2 found by haitao5198 clear mount parition device talbe when jffs2 mount falied --- components/dfs/filesystems/jffs2/dfs_jffs2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/dfs/filesystems/jffs2/dfs_jffs2.c b/components/dfs/filesystems/jffs2/dfs_jffs2.c index 3b96295c76..6516797544 100644 --- a/components/dfs/filesystems/jffs2/dfs_jffs2.c +++ b/components/dfs/filesystems/jffs2/dfs_jffs2.c @@ -178,6 +178,7 @@ static int dfs_jffs2_mount(struct dfs_filesystem* fs, result = jffs2_mount(NULL, mte); if (result != 0) { + device_partition[index].dev = NULL; return jffs2_result_to_dfs(result); } /* save this pointer */ From 821ab3b9aadb6d612e9505306990fc81ac663a4a Mon Sep 17 00:00:00 2001 From: prife Date: Mon, 30 Sep 2013 00:09:06 +0800 Subject: [PATCH 11/11] scons script: support to generate vs2012 project xml rename template.vcproj to template_vs2005.vcproj add template_vs2012.vcxproj NOTE: the vs2012.py is ugly, just can work. --- ...template.vcproj => template_vs2005.vcproj} | 0 bsp/simulator/template_vs2012.vcxproj | 61 ++++++ tools/building.py | 6 + tools/vs.py | 2 +- tools/vs2012.py | 190 ++++++++++++++++++ 5 files changed, 258 insertions(+), 1 deletion(-) rename bsp/simulator/{template.vcproj => template_vs2005.vcproj} (100%) create mode 100644 bsp/simulator/template_vs2012.vcxproj create mode 100644 tools/vs2012.py diff --git a/bsp/simulator/template.vcproj b/bsp/simulator/template_vs2005.vcproj similarity index 100% rename from bsp/simulator/template.vcproj rename to bsp/simulator/template_vs2005.vcproj diff --git a/bsp/simulator/template_vs2012.vcxproj b/bsp/simulator/template_vs2012.vcxproj new file mode 100644 index 0000000000..85e625e1ba --- /dev/null +++ b/bsp/simulator/template_vs2012.vcxproj @@ -0,0 +1,61 @@ + + + + + Debug + Win32 + + + + vs + {4A6BF1B1-C645-4BAD-A9B7-7B6E3DB67B2C} + vs2008 + Win32Proj + + + + Application + v110 + NotSet + + + + + + + + + + <_ProjectFileVersion>11.0.50727.1 + + + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + true + + + + Disabled + .\;..\..\include;..\..\bsp\vs2008;..\..\components\finsh;..\..\components\dfs\include;..\..\components\dfs\filesystems\uffs\src\inc\;..\..\components\dfs\filesystems\uffs;..\..\components\drivers\include;..\..\components\dfs\filesystems\jffs2\src;..\..\components\dfs\filesystems\jffs2\kernel;..\..\components\dfs\filesystems\jffs2\include;..\..\components\dfs\filesystems\jffs2\;..\..\components\dfs\filesystems\jffs2\cyg\compress;..\..\components\init;.\drivers;..\..\components\net\lwip\src\include\;..\..\components\net\lwip\src;..\..\components\net\lwip\src\arch\include;..\..\components\net\lwip\src\include\ipv4;.\pcap\Include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;MSVC;_TIME_T_DEFINED;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + Level3 + EditAndContinue + + + winmm.lib;Packet.lib;wpcap.lib;%(AdditionalDependencies) + .\pcap\Lib;%(AdditionalLibraryDirectories) + true + Console + MachineX86 + + + + + + + + \ No newline at end of file diff --git a/tools/building.py b/tools/building.py index 65bd14d882..acc3a8a213 100644 --- a/tools/building.py +++ b/tools/building.py @@ -139,6 +139,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ 'mdk4':('keil', 'armcc'), 'iar':('iar', 'iar'), 'vs':('msvc', 'cl'), + 'vs2012':('msvc', 'cl'), 'cb':('keil', 'armcc')} tgt_name = GetOption('target') if tgt_name: @@ -347,12 +348,14 @@ def DoBuilding(target, objects): EndBuilding(target, program) + def EndBuilding(target, program = None): import rtconfig from keil import MDKProject from keil import MDK4Project from iar import IARProject from vs import VSProject + from vs2012 import VS2012Project from codeblocks import CBProject Env.AddPostAction(target, rtconfig.POST_ACTION) @@ -377,6 +380,9 @@ def EndBuilding(target, program = None): if GetOption('target') == 'vs': VSProject('project.vcproj', Projects, program) + if GetOption('target') == 'vs2012': + VS2012Project('project.vcxproj', Projects, program) + if GetOption('target') == 'cb': CBProject('project.cbp', Projects, program) diff --git a/tools/vs.py b/tools/vs.py index 1cb0f1a809..1dce0ddaa7 100644 --- a/tools/vs.py +++ b/tools/vs.py @@ -40,7 +40,7 @@ def VS_AddHeadFilesGroup(program, elem, project_path): def VSProject(target, script, program): project_path = os.path.dirname(os.path.abspath(target)) - tree = etree.parse('template.vcproj') + tree = etree.parse('template_vs2005.vcproj') root = tree.getroot() out = file(target, 'wb') diff --git a/tools/vs2012.py b/tools/vs2012.py new file mode 100644 index 0000000000..3e751e940e --- /dev/null +++ b/tools/vs2012.py @@ -0,0 +1,190 @@ +import os +import sys +import string +import building +import uuid + +import xml.etree.ElementTree as etree +from xml.etree.ElementTree import SubElement +from utils import _make_path_relative +from utils import xml_indent +fs_encoding = sys.getfilesystemencoding() + +#reference +# http://woodpecker.org.cn/diveintopython3/xml.html +# https://pycoders-weekly-chinese.readthedocs.org/en/latest/issue6/processing-xml-in-python-with-element-tree.html +# http://www.cnblogs.com/ifantastic/archive/2013/04/12/3017110.html + +filter_project = etree.Element('Project', attrib={'ToolsVersion':'4.0'}) +def get_uuid(): + id = uuid.uuid1() # UUID('3e5526c0-2841-11e3-a376-20cf3048bcb3') + idstr = id.get_urn()[9:] #'urn:uuid:3e5526c0-2841-11e3-a376-20cf3048bcb3'[9:] + return '{'+idstr+'}' + +def VS2012_AddGroup(parent, group_name, files, project_path): + for f in files: + fn = f.rfile() + name = fn.name + path = os.path.dirname(fn.abspath) + + path = _make_path_relative(project_path, path) + path = os.path.join(path, name) + + ClCompile = SubElement(parent, 'ClCompile') + ClCompile.set('Include', path.decode(fs_encoding)) + + Filter = SubElement(ClCompile, 'Filter') + Filter.text='Source Files\\'+group_name + +def VS2012_CreateFilter(script, project_path): + c_ItemGroup = SubElement(filter_project, 'ItemGroup') + filter_ItemGroup = SubElement(filter_project, 'ItemGroup') + + Filter = SubElement(filter_ItemGroup, 'Filter') + Filter.set('Include', 'Source Files') + UniqueIdentifier = SubElement(Filter, 'UniqueIdentifier') + UniqueIdentifier.text = get_uuid() + Extensions = SubElement(Filter, 'Extensions') + Extensions.text = 'cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx' + + Filter = SubElement(filter_ItemGroup, 'Filter') + Filter.set('Include', 'Header Files') + UniqueIdentifier = SubElement(Filter, 'UniqueIdentifier') + UniqueIdentifier.text = get_uuid() + Extensions = SubElement(Filter, 'Extensions') + Extensions.text = 'h;hpp;hxx;hm;inl;inc;xsd' + for group in script: + VS2012_AddGroup(c_ItemGroup, group['name'], group['src'], project_path) + Filter = SubElement(filter_ItemGroup, 'Filter') + Filter.set('Include', 'Source Files\\'+group['name']) + UniqueIdentifier = SubElement(Filter, 'UniqueIdentifier') + UniqueIdentifier.text = get_uuid() + +#program: object from scons +# parent: xml node +# file_type: C or H +# files: c/h list +# project_path +def VS_add_ItemGroup(parent, file_type, files, project_path): + file_dict = {'C':"ClCompile", 'H':'ClInclude'} + item_tag = file_dict[file_type] + + ItemGroup = SubElement(parent, 'ItemGroup') + for f in files: + fn = f.rfile() + name = fn.name + path = os.path.dirname(fn.abspath) + + path = _make_path_relative(project_path, path) + path = os.path.join(path, name) + + File = SubElement(ItemGroup, item_tag) + File.set('Include', path.decode(fs_encoding)) + +def VS_add_HeadFiles(program, elem, project_path): + building.source_ext = [] + building.source_ext = ["h"] + for item in program: + building.walk_children(item) + building.source_list.sort() + # print building.source_list + ItemGroup = SubElement(elem, 'ItemGroup') + + filter_h_ItemGroup = SubElement(filter_project, 'ItemGroup') + for f in building.source_list: + path = _make_path_relative(project_path, f) + File = SubElement(ItemGroup, 'ClInclude') + File.set('Include', path.decode(fs_encoding)) + + # add project.vcxproj.filter + ClInclude = SubElement(filter_h_ItemGroup, 'ClInclude') + ClInclude.set('Include', path.decode(fs_encoding)) + Filter = SubElement(ClInclude, 'Filter') + Filter.text='Header Files' + +def VS2012Project(target, script, program): + project_path = os.path.dirname(os.path.abspath(target)) + + tree = etree.parse('template_vs2012.vcxproj') + root = tree.getroot() + elem = root + + out = file(target, 'wb') + out.write('\r\n') + + ProjectFiles = [] + + # add "*.c or *.h" files + + VS2012_CreateFilter(script, project_path) + # add "*.c" files + for group in script: + VS_add_ItemGroup(elem, 'C', group['src'], project_path) + + # add "*.h" files + VS_add_HeadFiles(program, elem, project_path) + + # write head include path + if building.Env.has_key('CPPPATH'): + cpp_path = building.Env['CPPPATH'] + paths = set() + for path in cpp_path: + inc = _make_path_relative(project_path, os.path.normpath(path)) + paths.add(inc) #.replace('\\', '/') + + paths = [i for i in paths] + paths.sort() + cpp_path = ';'.join(paths) + ';%(AdditionalIncludeDirectories)' + + # write include path + for elem in tree.iter(tag='AdditionalIncludeDirectories'): + elem.text = cpp_path + break + + # write cppdefinitons flags + if building.Env.has_key('CPPDEFINES'): + for elem in tree.iter(tag='PreprocessorDefinitions'): + definitions = ';'.join(building.Env['CPPDEFINES']) + ';%(PreprocessorDefinitions)' + elem.text = definitions + break + # write link flags + + # write lib dependence (Link) + if building.Env.has_key('LIBS'): + for elem in tree.iter(tag='AdditionalDependencies'): + libs_with_extention = [i+'.lib' for i in building.Env['LIBS']] + libs = ';'.join(libs_with_extention) + ';%(AdditionalDependencies)' + elem.text = libs + break + + # write lib include path + if building.Env.has_key('LIBPATH'): + lib_path = building.Env['LIBPATH'] + paths = set() + for path in lib_path: + inc = _make_path_relative(project_path, os.path.normpath(path)) + paths.add(inc) + + paths = [i for i in paths] + paths.sort() + lib_paths = ';'.join(paths) + ';%(AdditionalLibraryDirectories)' + for elem in tree.iter(tag='AdditionalLibraryDirectories'): + elem.text = lib_paths + break + + xml_indent(root) + vcxproj_string = etree.tostring(root, encoding='utf-8') + root_node=r'' + out.write(r'') + out.write(vcxproj_string[len(root_node):]) + out.close() + + xml_indent(filter_project) + filter_string = etree.tostring(filter_project, encoding='utf-8') + out = file('project.vcxproj.filters', 'wb') + out.write('\r\n') + root_node=r'' + out.write(r'') + out.write(filter_string[len(root_node):]) + out.close() +