targets/toolchain_gcc.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 20 Jun 2017 17:01:19 +0300
changeset 1699 65ce8afe4b8f
parent 1681 21f40ed5238f
child 1731 6ebd9c40b2be
permissions -rwxr-xr-x
enable non-latin variable descriptions in CodeFileEditor

fix following backtrace:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-7: ordinal not in range(128)
Traceback (most recent call last):
File "beremiz/editors/CodeFileEditor.py", line 610, in GetValue
return str(self.data[row].get(self.GetColLabelValue(col, False), ""))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-7: ordinal not in range(128)
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
     1
#!/usr/bin/env python
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
     2
# -*- coding: utf-8 -*-
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
     3
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
     6
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
1681
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
     8
# Copyright (C) 2017: Paul Beltyukov
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
     9
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    10
# See COPYING file for copyrights details.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    11
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    12
# This program is free software; you can redistribute it and/or
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    13
# modify it under the terms of the GNU General Public License
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    14
# as published by the Free Software Foundation; either version 2
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    15
# of the License, or (at your option) any later version.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    16
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    17
# This program is distributed in the hope that it will be useful,
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    20
# GNU General Public License for more details.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    21
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    22
# You should have received a copy of the GNU General Public License
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    23
# along with this program; if not, write to the Free Software
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    25
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    26
import os, re, operator
726
ae63ccc29444 refactoring
Edouard Tisserant
parents: 725
diff changeset
    27
from util.ProcessLogger import ProcessLogger
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    28
import hashlib
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    29
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    30
includes_re =  re.compile('\s*#include\s*["<]([^">]*)[">].*')
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    31
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    32
class toolchain_gcc():
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    33
    """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    34
    This abstract class contains GCC specific code.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    35
    It cannot be used as this and should be inherited in a target specific
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    36
    class such as target_linux or target_win32
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    37
    """
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    38
    def __init__(self, CTRInstance):
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    39
        self.CTRInstance = CTRInstance
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    40
        self.buildpath = None
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    41
        self.SetBuildPath(self.CTRInstance._getBuildPath())
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 427
diff changeset
    42
    
297
8fca8b555808 Fixed typo in (LD/C)FLAGS hendling in toolchain_gcc.py
etisserant
parents: 290
diff changeset
    43
    def getBuilderCFLAGS(self):
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    44
        """
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    45
        Returns list of builder specific CFLAGS
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    46
        """
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1023
diff changeset
    47
        return [self.CTRInstance.GetTarget().getcontent().getCFLAGS()]
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    48
297
8fca8b555808 Fixed typo in (LD/C)FLAGS hendling in toolchain_gcc.py
etisserant
parents: 290
diff changeset
    49
    def getBuilderLDFLAGS(self):
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    50
        """
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    51
        Returns list of builder specific LDFLAGS
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    52
        """
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    53
        return self.CTRInstance.LDFLAGS + \
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1023
diff changeset
    54
               [self.CTRInstance.GetTarget().getcontent().getLDFLAGS()]
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    55
1681
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    56
    def getCompiler(self):
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    57
        """
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    58
        Returns compiler
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    59
        """
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    60
        return self.CTRInstance.GetTarget().getcontent().getCompiler()
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    61
      
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    62
    def getLinker(self):
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    63
        """
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    64
        Returns linker
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    65
        """
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    66
        return self.CTRInstance.GetTarget().getcontent().getLinker()
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
    67
               
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    68
    def GetBinaryCode(self):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    69
        try:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    70
            return open(self.exe_path, "rb").read()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    71
        except Exception, e:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    72
            return None
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    73
        
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    74
    def _GetMD5FileName(self):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    75
        return os.path.join(self.buildpath, "lastbuildPLC.md5")
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    76
677
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    77
    def ResetBinaryCodeMD5(self):
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    78
        self.md5key = None
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    79
        try:
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    80
            os.remove(self._GetMD5FileName())
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    81
        except Exception, e:
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    82
            pass
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    83
    
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    84
    def GetBinaryCodeMD5(self):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    85
        if self.md5key is not None:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    86
            return self.md5key
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    87
        else:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    88
            try:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    89
                return open(self._GetMD5FileName(), "r").read()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    90
            except Exception, e:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    91
                return None
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    92
    
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    93
    def SetBuildPath(self, buildpath):
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    94
        if self.buildpath != buildpath:
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    95
            self.buildpath = buildpath
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    96
            self.exe = self.CTRInstance.GetProjectName() + self.extension
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    97
            self.exe_path = os.path.join(self.buildpath, self.exe)
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    98
            self.md5key = None
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    99
            self.srcmd5 = {}
1681
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   100
            
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   101
    def append_cfile_deps(self, src, deps):
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   102
        for l in src.splitlines():
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   103
            res = includes_re.match(l)
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   104
            if res is not None:
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   105
                depfn = res.groups()[0]
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   106
                if os.path.exists(os.path.join(self.buildpath, depfn)):
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   107
                    deps.append(depfn)
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   108
                    
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   109
    def concat_deps(self, bn):
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   110
        # read source
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   111
        src = open(os.path.join(self.buildpath, bn),"r").read()
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   112
        # update direct dependencies
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   113
        deps = []
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   114
        self.append_cfile_deps(src, deps)
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   115
        # recurse through deps
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   116
        # TODO detect cicular deps.
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   117
        return reduce(operator.concat, map(self.concat_deps, deps), src)
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   118
        
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   119
    def check_and_update_hash_and_deps(self, bn):
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   120
        # Get latest computed hash and deps
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   121
        oldhash, deps = self.srcmd5.get(bn,(None,[]))
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   122
        # read source
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   123
        src = open(os.path.join(self.buildpath, bn)).read()
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   124
        # compute new hash
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   125
        newhash = hashlib.md5(src).hexdigest()
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   126
        # compare
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   127
        match = (oldhash == newhash)
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   128
        if not match:
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   129
            # file have changed
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   130
            # update direct dependencies
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   131
            deps = []
1681
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   132
            self.append_cfile_deps(src, deps)
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   133
            # store that hashand deps
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   134
            self.srcmd5[bn] = (newhash, deps)
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   135
        # recurse through deps
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   136
        # TODO detect cicular deps.
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   137
        return reduce(operator.and_, map(self.check_and_update_hash_and_deps, deps), match)
1681
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   138
        
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   139
    def calc_source_md5(self):
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   140
        wholesrcdata = ""
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   141
        for Location, CFilesAndCFLAGS, DoCalls in self.CTRInstance.LocationCFilesAndCFLAGS:
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   142
            # Get CFiles list to give it to makefile
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   143
            for CFile, CFLAGS in CFilesAndCFLAGS:
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   144
                CFileName = os.path.basename(CFile)
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   145
                wholesrcdata += self.concat_deps(CFileName)
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   146
        return hashlib.md5(wholesrcdata).hexdigest()
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   147
    
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   148
    def calc_md5(self):
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   149
        return hashlib.md5(self.GetBinaryCode()).hexdigest()
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   150
    
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   151
    def build(self):
1681
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   152
        # Retrieve compiler and linker
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   153
        self.compiler = self.getCompiler()
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   154
        self.linker = self.getLinker()
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
   155
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
   156
        Builder_CFLAGS = ' '.join(self.getBuilderCFLAGS())
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   157
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   158
        ######### GENERATE OBJECT FILES ########################################
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   159
        obns = []
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   160
        objs = []
1023
93022adef055 Fix bug when linking failed and trying to rebuild
Laurent Bessard
parents: 728
diff changeset
   161
        relink = self.GetBinaryCode() is None
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   162
        for Location, CFilesAndCFLAGS, DoCalls in self.CTRInstance.LocationCFilesAndCFLAGS:
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 726
diff changeset
   163
            if CFilesAndCFLAGS:
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 726
diff changeset
   164
                if Location :
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 726
diff changeset
   165
                    self.CTRInstance.logger.write(".".join(map(str,Location))+" :\n")
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 726
diff changeset
   166
                else:
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 726
diff changeset
   167
                    self.CTRInstance.logger.write(_("PLC :\n"))
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   168
                
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   169
            for CFile, CFLAGS in CFilesAndCFLAGS:
693
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   170
                if CFile.endswith(".c"):
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   171
                    bn = os.path.basename(CFile)
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   172
                    obn = os.path.splitext(bn)[0]+".o"
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   173
                    objectfilename = os.path.splitext(CFile)[0]+".o"
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   174
693
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   175
                    match = self.check_and_update_hash_and_deps(bn)
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   176
                    
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   177
                    if match:
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   178
                        self.CTRInstance.logger.write("   [pass]  "+bn+" -> "+obn+"\n")
693
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   179
                    else:
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   180
                        relink = True
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   181
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   182
                        self.CTRInstance.logger.write("   [CC]  "+bn+" -> "+obn+"\n")
693
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   183
                        
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   184
                        status, result, err_result = ProcessLogger(
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   185
                               self.CTRInstance.logger,
693
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   186
                               "\"%s\" -c \"%s\" -o \"%s\" %s %s"%
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   187
                                   (self.compiler, CFile, objectfilename, Builder_CFLAGS, CFLAGS)
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   188
                               ).spin()
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   189
693
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   190
                        if status :
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   191
                            self.srcmd5.pop(bn)
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   192
                            self.CTRInstance.logger.write_error(_("C compilation of %s failed.\n")%bn)
693
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   193
                            return False
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   194
                    obns.append(obn)
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   195
                    objs.append(objectfilename)
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   196
                elif CFile.endswith(".o"):
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   197
                    obns.append(os.path.basename(CFile))
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   198
                    objs.append(CFile)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   199
1681
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   200
        ######### GENERATE OUTPUT FILE ########################################
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   201
        # Link all the object files into one binary file
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   202
        self.CTRInstance.logger.write(_("Linking :\n"))
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   203
        if relink:
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   204
            objstring = []
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   205
    
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   206
            # Generate list .o files
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   207
            listobjstring = '"' + '"  "'.join(objs) + '"'
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   208
    
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
   209
            ALLldflags = ' '.join(self.getBuilderLDFLAGS())
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   210
    
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   211
            self.CTRInstance.logger.write("   [CC]  " + ' '.join(obns)+" -> " + self.exe + "\n")
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   212
    
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   213
            status, result, err_result = ProcessLogger(
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   214
                   self.CTRInstance.logger,
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   215
                   "\"%s\" %s -o \"%s\" %s"%
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   216
                       (self.linker,
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   217
                        listobjstring,
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   218
                        self.exe_path,
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   219
                        ALLldflags)
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   220
                   ).spin()
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   221
            
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   222
            if status :
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   223
                return False
677
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   224
                
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   225
        else:
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   226
            self.CTRInstance.logger.write("   [pass]  " + ' '.join(obns)+" -> " + self.exe + "\n")
677
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   227
        
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   228
        # Calculate md5 key and get data for the new created PLC
1681
21f40ed5238f add getCompiler and getLinker methods, to abstract from XSD.
Paul Beltyukov <beltyukov.p.a@gmail.com>
parents: 1511
diff changeset
   229
        self.md5key = self.calc_md5()
677
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   230
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   231
        # Store new PLC filename based on md5 key
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   232
        f = open(self._GetMD5FileName(), "w")
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   233
        f.write(self.md5key)
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   234
        f.close()
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   235
        
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   236
        return True
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   237