From c6e81b58d9da3866287b02f48e231db7d272acd5 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Fri, 6 Sep 2013 21:32:27 +0800 Subject: [PATCH 01/10] simulator: move SDL setting staff into drivers/SConstruct This could not only make a cleaner SConstruct, but could also benefit RTGUI building. --- bsp/simulator/SConstruct | 7 ------- bsp/simulator/drivers/SConscript | 14 +++++++++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bsp/simulator/SConstruct b/bsp/simulator/SConstruct index af6534906b..b2e958e65b 100755 --- a/bsp/simulator/SConstruct +++ b/bsp/simulator/SConstruct @@ -84,13 +84,6 @@ else: objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False, remove_components=['rtgui']) if GetDepend('RT_USING_RTGUI'): - sdl_lib = ['SDL', 'SDLmain'] - sdl_lib_path = [os.path.abspath('SDL/lib/x86')] - sdl_include_path = [os.path.abspath('SDL/include')] - env.Append(LIBS=sdl_lib) - env.Append(LIBPATH=sdl_lib_path) - env.Append(CPPPATH=sdl_include_path) - if RTT_RTGUI: objs += SConscript(os.path.join(RTT_RTGUI, 'SConscript'), variant_dir='build/components/rtgui', diff --git a/bsp/simulator/drivers/SConscript b/bsp/simulator/drivers/SConscript index d939535da8..eb491b810e 100644 --- a/bsp/simulator/drivers/SConscript +++ b/bsp/simulator/drivers/SConscript @@ -3,10 +3,19 @@ from building import * cwd = GetCurrentDir() src = Glob('*.c') +LIBS = [] +LIBPATH = [] +CPPPATH = [cwd] # remove no need file. if GetDepend('RT_USING_RTGUI') == False: SrcRemove(src, 'sdl_fb.c') +else: + LIBS.append('SDL') + if sys.platform == 'win32': + LIBPATH.append(os.path.abspath(os.path.join(cwd, '../SDL/lib/x86'))) + CPPPATH.append(os.path.abspath(os.path.join(cwd, '../SDL/include'))) + if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_DFS_ELMFAT') == False: SrcRemove(src, 'sd_sim.c') if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_MTD_NAND') == False: @@ -20,8 +29,7 @@ if GetDepend('RT_USING_MODULE') == False: if sys.platform[0:5]=="linux": #check whether under linux SrcRemove(src, ['module_win32.c', 'dfs_win32.c']) -CPPPATH = [cwd] - -group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) +group = DefineGroup('Drivers', src, depend = [''], + CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH) Return('group') From 18692c29b8d8a24dcd6710c4bea4339789c21c17 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Fri, 6 Sep 2013 21:54:27 +0800 Subject: [PATCH 02/10] simulator: get CROSS_TOOL and EXEC_PATH from env Simulator get it's way to Travis CI ready. --- bsp/simulator/rtconfig.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bsp/simulator/rtconfig.py b/bsp/simulator/rtconfig.py index 7a42bddbcf..9328a087f8 100755 --- a/bsp/simulator/rtconfig.py +++ b/bsp/simulator/rtconfig.py @@ -1,3 +1,5 @@ +import os + # toolchains options ARCH='sim' #CROSS_TOOL='msvc' or 'gcc' or 'mingw' @@ -5,6 +7,9 @@ ARCH='sim' # 'gcc' is for linux CROSS_TOOL='msvc' +if os.getenv('RTT_CC'): + CROSS_TOOL = os.getenv('RTT_CC') + # cross_tool provides the cross compiler # EXEC_PATH is the compiler execute path if CROSS_TOOL == 'gcc': @@ -26,6 +31,9 @@ else : print "bad CROSS TOOL!" exit(1) +if os.getenv('RTT_EXEC_PATH'): + EXEC_PATH = os.getenv('RTT_EXEC_PATH') + BUILD = 'debug' #BUILD = '' From 3b4f3f5931185ea3224e16430b75ae32ed1718b1 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sat, 7 Sep 2013 12:06:04 +0800 Subject: [PATCH 03/10] Scons: run `clang -Wall -fsyntax-only` in clang-analyze The `clang -fsyntax-only` will give us additional warning messages in the console. --- tools/building.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/building.py b/tools/building.py index 56b4ebdc8d..65bd14d882 100644 --- a/tools/building.py +++ b/tools/building.py @@ -113,8 +113,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ AS = 'true',) env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_")) # only check, don't compile. ccc-analyzer use CCC_CC as the CC. - env['ENV']['CCC_CC'] = 'true' - env['ENV']['CCC_CXX'] = 'true' + # fsyntax-only will give us some additional warning messages + env['ENV']['CCC_CC'] = 'clang' + env.Append(CFLAGS=['-fsyntax-only', '-Wall', '-Wno-invalid-source-encoding']) + env['ENV']['CCC_CXX'] = 'clang++' + env.Append(CXXFLAGS=['-fsyntax-only', '-Wall', '-Wno-invalid-source-encoding']) # remove the POST_ACTION as it will cause meaningless errors(file not # found or something like that). rtconfig.POST_ACTION = '' From c289aa9fc1955910af3c8fd4086c35e762b8368b Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sat, 7 Sep 2013 14:53:31 +0800 Subject: [PATCH 04/10] Scons: add a custom tool to do clang static analyze Bsps can use the clang analyzer as a tool: env = Environment(toolpath=[os.path.join(RTT_ROOT, 'tools', 'tools')], tools = ['clang-analyze']) When building the project, the static analyzer will be called to check all the C code. The warnings are print to stderr. --- tools/tools/clang-analyze.py | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tools/tools/clang-analyze.py diff --git a/tools/tools/clang-analyze.py b/tools/tools/clang-analyze.py new file mode 100644 index 0000000000..6008e684df --- /dev/null +++ b/tools/tools/clang-analyze.py @@ -0,0 +1,69 @@ +""" +Tool-specific initialization for Clang static analyzer + +There normally shouldn't be any need to import this module directly. +It will usually be imported through the generic SCons.Tool.Tool() +selection method. +""" + +__revision__ = "tools/clang-analyze.py 2013-09-06 grissiom" + +import os +import os.path + +import SCons.Action +import SCons.Builder +import SCons.Defaults +import SCons.Tool +import SCons.Util + +import rtconfig + +def generate(env): + assert(rtconfig.CROSS_TOOL == 'clang-analyze') + # let gnu_tools setup a basic env(learnt from SCons/Tools/mingw.py) + gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas', 'm4'] + for tool in gnu_tools: + SCons.Tool.Tool(tool)(env) + + # then we could stand on the shoulders of gaints + env['CC'] = 'ccc-analyzer' + env['CXX'] = 'c++-analyzer' + env['AS'] = 'true' + env['AR'] = 'true' + env['LINK'] = 'true' + + env['CFLAGS'] = ['-fsyntax-only', '-Wall', '-Wno-invalid-source-encoding'] + env['LINKFLAGS'] = '-Wl,--gc-sections' + env['ARFLAGS'] = '-rc' + + # only check, don't compile. ccc-analyzer use CCC_CC as the CC. + # fsyntax-only will give us some additional warning messages + env['ENV']['CCC_CC'] = 'clang' + env['ENV']['CCC_CXX'] = 'clang++' + + # setup the output dir and format + env['ENV']['CCC_ANALYZER_HTML'] = './build/' + env['ENV']['CCC_ANALYZER_OUTPUT_FORMAT'] = 'html' + + # Some setting from the platform also have to be overridden: + env['OBJSUFFIX'] = '.o' + env['LIBPREFIX'] = 'lib' + env['LIBSUFFIX'] = '.a' + + if rtconfig.EXEC_PATH: + if not os.path.exists(rtconfig.EXEC_PATH): + print + print 'warning: rtconfig.EXEC_PATH(%s) does not exists.' % rtconfig.EXEC_PATH + print + return + env.AppendENVPath('PATH', rtconfig.EXEC_PATH) + +def exists(env): + return env.Detect(['clang', 'clang++']) + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: From 35cac170fa0cf6829afda14ecc124b20bce2b061 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sat, 7 Sep 2013 15:01:28 +0800 Subject: [PATCH 05/10] simulator: add clang-analyze tool support When CROSS_TOOL or 'RTT_CC' env is setted to 'clang-analyze', it will use Clang to check the codes. --- bsp/simulator/SConstruct | 4 ++++ bsp/simulator/rtconfig.py | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bsp/simulator/SConstruct b/bsp/simulator/SConstruct index b2e958e65b..4db7328f2a 100755 --- a/bsp/simulator/SConstruct +++ b/bsp/simulator/SConstruct @@ -73,6 +73,10 @@ elif rtconfig.PLATFORM == 'mingw': LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS) env['LIBS']=libs env.PrependENVPath('PATH', rtconfig.EXEC_PATH) +elif rtconfig.CROSS_TOOL == 'clang-analyze': + TARGET = 'rtthread' + env = Environment(toolpath=[os.path.join(RTT_ROOT, 'tools', 'tools')], + tools = [rtconfig.CROSS_TOOL]) else: TARGET = 'rtthread' env['CC']=rtconfig.CC diff --git a/bsp/simulator/rtconfig.py b/bsp/simulator/rtconfig.py index 9328a087f8..d3ed2599d5 100755 --- a/bsp/simulator/rtconfig.py +++ b/bsp/simulator/rtconfig.py @@ -12,10 +12,10 @@ if os.getenv('RTT_CC'): # cross_tool provides the cross compiler # EXEC_PATH is the compiler execute path -if CROSS_TOOL == 'gcc': +if CROSS_TOOL == 'gcc' or CROSS_TOOL == 'clang-analyze': CPU = 'posix' PLATFORM = 'gcc' - EXEC_PATH = '/usr/bin/gcc' + EXEC_PATH = '' elif CROSS_TOOL == 'mingw': CPU = 'win32' @@ -26,8 +26,7 @@ elif CROSS_TOOL == 'msvc': CPU = 'win32' PLATFORM = 'cl' EXEC_PATH = '' - -else : +else: print "bad CROSS TOOL!" exit(1) From 0168048f27e9558b5367eac28a008dc3f91e114b Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sat, 7 Sep 2013 15:21:46 +0800 Subject: [PATCH 06/10] travis: auto build the simulator Building is only the first step. Correctness is what we need. There are already many GCC builds for other bsp so GCC building for simulator is not important. So I use clang-analyze to check all the source codes in simulator project. Hope it will help us. --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7b18fcd107..11b255954f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,13 +6,15 @@ notifications: before_script: # travis has changed to 64-bit and we require 32-bit compatibility libraries - sudo apt-get update - - "sudo apt-get -qq install libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386 || true" + - "sudo apt-get -qq install clang libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386 || true" - "[ $RTT_TOOL_CHAIN = 'sourcery-arm' ] && curl -s https://sourcery.mentor.com/public/gnu_toolchain/arm-none-eabi/arm-2012.09-63-arm-none-eabi-i686-pc-linux-gnu.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/arm-2012.09/bin && /opt/arm-2012.09/bin/arm-none-eabi-gcc --version || true" - "[ $RTT_TOOL_CHAIN = 'sourcery-mips' ] && curl -s https://sourcery.mentor.com/public/gnu_toolchain/mips-sde-elf/mips-2012.09-98-mips-sde-elf-i686-pc-linux-gnu.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/mips-2012.09/bin && /opt/mips-2012.09/bin/mips-sde-elf-gcc --version || true" - "[ $RTT_TOOL_CHAIN = 'sourcery-ppc' ] && curl -s https://sourcery.mentor.com/public/gnu_toolchain/powerpc-eabi/freescale-2011.03-39-powerpc-eabi-i686-pc-linux-gnu.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/freescale-2011.03/bin && /opt/freescale-2011.03/bin/powerpc-eabi-gcc --version || true" - "[ $RTT_TOOL_CHAIN = 'atmel-avr32' ] && curl -s http://www.atmel.com/images/avr32-gnu-toolchain-3.4.1.348-linux.any.x86.tar.gz | sudo tar xzf - -C /opt && export RTT_EXEC_PATH=/opt/avr32-gnu-toolchain-linux_x86/bin && /opt/avr32-gnu-toolchain-linux_x86/bin/avr32-gcc --version && curl -sO http://www.atmel.com/images/avr-headers-3.2.3.970.zip && unzip -qq avr-headers-3.2.3.970.zip -d bsp/$RTT_BSP || true" - export RTT_ROOT=`pwd` - export RTT_CC='gcc' + - git clone --depth 1 https://github.com/RT-Thread/RTGUI.git $HOME/RTGUI + - export RTT_RTGUI=$HOME/RTGUI/components/rtgui script: - scons -C bsp/$RTT_BSP @@ -57,3 +59,4 @@ env: # - RTT_BSP='wh44b0' # no scons # - RTT_BSP='x86' # x86 # - RTT_BSP='xplorer4330' # no scons + - RTT_BSP='simulator' RTT_CC='clang-analyze' From 5ab9943eb5468491352f32837fb8dbf13d5394f0 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sat, 7 Sep 2013 16:01:03 +0800 Subject: [PATCH 07/10] travis: try to fix the SDL building --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 11b255954f..b60854d93d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ notifications: before_script: # travis has changed to 64-bit and we require 32-bit compatibility libraries - sudo apt-get update - - "sudo apt-get -qq install clang libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386 || true" + - "sudo apt-get -qq install clang libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386 libsdl-dev || true" - "[ $RTT_TOOL_CHAIN = 'sourcery-arm' ] && curl -s https://sourcery.mentor.com/public/gnu_toolchain/arm-none-eabi/arm-2012.09-63-arm-none-eabi-i686-pc-linux-gnu.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/arm-2012.09/bin && /opt/arm-2012.09/bin/arm-none-eabi-gcc --version || true" - "[ $RTT_TOOL_CHAIN = 'sourcery-mips' ] && curl -s https://sourcery.mentor.com/public/gnu_toolchain/mips-sde-elf/mips-2012.09-98-mips-sde-elf-i686-pc-linux-gnu.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/mips-2012.09/bin && /opt/mips-2012.09/bin/mips-sde-elf-gcc --version || true" - "[ $RTT_TOOL_CHAIN = 'sourcery-ppc' ] && curl -s https://sourcery.mentor.com/public/gnu_toolchain/powerpc-eabi/freescale-2011.03-39-powerpc-eabi-i686-pc-linux-gnu.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/freescale-2011.03/bin && /opt/freescale-2011.03/bin/powerpc-eabi-gcc --version || true" @@ -17,7 +17,7 @@ before_script: - export RTT_RTGUI=$HOME/RTGUI/components/rtgui script: - - scons -C bsp/$RTT_BSP + - scons -C bsp/$RTT_BSP --verbose env: - RTT_BSP='at91sam9260' RTT_TOOL_CHAIN='sourcery-arm' From eae89b95764a4929fab6c8c2bfe94a0562e40c24 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sat, 7 Sep 2013 16:15:43 +0800 Subject: [PATCH 08/10] travis: install the gcc-multilib to get the 32bit build OK --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b60854d93d..28413ac218 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ notifications: before_script: # travis has changed to 64-bit and we require 32-bit compatibility libraries - sudo apt-get update - - "sudo apt-get -qq install clang libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386 libsdl-dev || true" + - "sudo apt-get -qq install clang gcc-multilib libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386 libsdl-dev || true" - "[ $RTT_TOOL_CHAIN = 'sourcery-arm' ] && curl -s https://sourcery.mentor.com/public/gnu_toolchain/arm-none-eabi/arm-2012.09-63-arm-none-eabi-i686-pc-linux-gnu.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/arm-2012.09/bin && /opt/arm-2012.09/bin/arm-none-eabi-gcc --version || true" - "[ $RTT_TOOL_CHAIN = 'sourcery-mips' ] && curl -s https://sourcery.mentor.com/public/gnu_toolchain/mips-sde-elf/mips-2012.09-98-mips-sde-elf-i686-pc-linux-gnu.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/mips-2012.09/bin && /opt/mips-2012.09/bin/mips-sde-elf-gcc --version || true" - "[ $RTT_TOOL_CHAIN = 'sourcery-ppc' ] && curl -s https://sourcery.mentor.com/public/gnu_toolchain/powerpc-eabi/freescale-2011.03-39-powerpc-eabi-i686-pc-linux-gnu.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/freescale-2011.03/bin && /opt/freescale-2011.03/bin/powerpc-eabi-gcc --version || true" From 4240ebd73f05cb3501037962d6410a917d438c79 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sat, 7 Sep 2013 16:32:50 +0800 Subject: [PATCH 09/10] travis: don't export RTT_CC in before_script if it's been set This gives ways for bsp to set it's own RTT_CC. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 28413ac218..5619d65627 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ before_script: - "[ $RTT_TOOL_CHAIN = 'sourcery-ppc' ] && curl -s https://sourcery.mentor.com/public/gnu_toolchain/powerpc-eabi/freescale-2011.03-39-powerpc-eabi-i686-pc-linux-gnu.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/freescale-2011.03/bin && /opt/freescale-2011.03/bin/powerpc-eabi-gcc --version || true" - "[ $RTT_TOOL_CHAIN = 'atmel-avr32' ] && curl -s http://www.atmel.com/images/avr32-gnu-toolchain-3.4.1.348-linux.any.x86.tar.gz | sudo tar xzf - -C /opt && export RTT_EXEC_PATH=/opt/avr32-gnu-toolchain-linux_x86/bin && /opt/avr32-gnu-toolchain-linux_x86/bin/avr32-gcc --version && curl -sO http://www.atmel.com/images/avr-headers-3.2.3.970.zip && unzip -qq avr-headers-3.2.3.970.zip -d bsp/$RTT_BSP || true" - export RTT_ROOT=`pwd` - - export RTT_CC='gcc' + - "[ x$RTT_CC == x ] && export RTT_CC='gcc' || true" - git clone --depth 1 https://github.com/RT-Thread/RTGUI.git $HOME/RTGUI - export RTT_RTGUI=$HOME/RTGUI/components/rtgui @@ -20,6 +20,7 @@ script: - scons -C bsp/$RTT_BSP --verbose env: + - RTT_BSP='simulator' RTT_CC='clang-analyze' - RTT_BSP='at91sam9260' RTT_TOOL_CHAIN='sourcery-arm' - RTT_BSP='avr32uc3b0' RTT_TOOL_CHAIN='atmel-avr32' # - RTT_BSP='bf533' # no scons @@ -59,4 +60,3 @@ env: # - RTT_BSP='wh44b0' # no scons # - RTT_BSP='x86' # x86 # - RTT_BSP='xplorer4330' # no scons - - RTT_BSP='simulator' RTT_CC='clang-analyze' From dacd2cb9a9d9563b1986e6cef856d8f5017fe4ff Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sat, 7 Sep 2013 17:22:45 +0800 Subject: [PATCH 10/10] travis: add scan-build in PATH --- .travis.yml | 4 ++-- tools/tools/clang-analyze.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5619d65627..67dd2defcb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,10 +17,10 @@ before_script: - export RTT_RTGUI=$HOME/RTGUI/components/rtgui script: - - scons -C bsp/$RTT_BSP --verbose + - scons -C bsp/$RTT_BSP env: - - RTT_BSP='simulator' RTT_CC='clang-analyze' + - RTT_BSP='simulator' RTT_CC='clang-analyze' RTT_EXEC_PATH=/usr/share/clang/scan-build - RTT_BSP='at91sam9260' RTT_TOOL_CHAIN='sourcery-arm' - RTT_BSP='avr32uc3b0' RTT_TOOL_CHAIN='atmel-avr32' # - RTT_BSP='bf533' # no scons diff --git a/tools/tools/clang-analyze.py b/tools/tools/clang-analyze.py index 6008e684df..a966a7b56a 100644 --- a/tools/tools/clang-analyze.py +++ b/tools/tools/clang-analyze.py @@ -60,7 +60,7 @@ def generate(env): env.AppendENVPath('PATH', rtconfig.EXEC_PATH) def exists(env): - return env.Detect(['clang', 'clang++']) + return env.Detect(['ccc-analyzer', 'c++-analyzer']) # Local Variables: # tab-width:4