targets/toolchain_gcc.py
author Sergey Surkov <surkovsv93@gmail.com>
Mon, 12 Dec 2016 14:29:40 +0300
changeset 1600 481a71c864d4
parent 1511 91538d0c242c
child 1681 21f40ed5238f
permissions -rwxr-xr-x
fix list of recent projects in File menu, add path to current project after Save As
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
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
     8
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
     9
# 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
    10
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    11
# 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
    12
# 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
    13
# 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
    14
# 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
    15
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    16
# 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
    17
# 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
    18
# 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
    19
# 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
    20
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1315
diff changeset
    21
# 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
    22
# 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
    23
# 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
    24
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    25
import os, re, operator
726
ae63ccc29444 refactoring
Edouard Tisserant
parents: 725
diff changeset
    26
from util.ProcessLogger import ProcessLogger
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    27
import hashlib
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    28
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    29
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
    30
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    31
class toolchain_gcc():
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    32
    """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    33
    This abstract class contains GCC specific code.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    34
    It cannot be used as this and should be inherited in a target specific
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    35
    class such as target_linux or target_win32
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    36
    """
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    37
    def __init__(self, CTRInstance):
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    38
        self.CTRInstance = CTRInstance
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    39
        self.buildpath = None
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    40
        self.SetBuildPath(self.CTRInstance._getBuildPath())
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 427
diff changeset
    41
    
297
8fca8b555808 Fixed typo in (LD/C)FLAGS hendling in toolchain_gcc.py
etisserant
parents: 290
diff changeset
    42
    def getBuilderCFLAGS(self):
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    43
        """
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    44
        Returns list of builder specific CFLAGS
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    45
        """
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1023
diff changeset
    46
        return [self.CTRInstance.GetTarget().getcontent().getCFLAGS()]
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    47
297
8fca8b555808 Fixed typo in (LD/C)FLAGS hendling in toolchain_gcc.py
etisserant
parents: 290
diff changeset
    48
    def getBuilderLDFLAGS(self):
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    49
        """
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    50
        Returns list of builder specific LDFLAGS
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    51
        """
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    52
        return self.CTRInstance.LDFLAGS + \
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1023
diff changeset
    53
               [self.CTRInstance.GetTarget().getcontent().getLDFLAGS()]
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
    54
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    55
    def GetBinaryCode(self):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    56
        try:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    57
            return open(self.exe_path, "rb").read()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    58
        except Exception, e:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    59
            return None
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    60
        
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    61
    def _GetMD5FileName(self):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    62
        return os.path.join(self.buildpath, "lastbuildPLC.md5")
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    63
677
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    64
    def ResetBinaryCodeMD5(self):
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    65
        self.md5key = None
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    66
        try:
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    67
            os.remove(self._GetMD5FileName())
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    68
        except Exception, e:
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    69
            pass
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
    70
    
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    71
    def GetBinaryCodeMD5(self):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    72
        if self.md5key is not None:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    73
            return self.md5key
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    74
        else:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    75
            try:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    76
                return open(self._GetMD5FileName(), "r").read()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    77
            except Exception, e:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    78
                return None
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    79
    
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    80
    def SetBuildPath(self, buildpath):
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    81
        if self.buildpath != buildpath:
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    82
            self.buildpath = buildpath
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
    83
            self.exe = self.CTRInstance.GetProjectName() + self.extension
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    84
            self.exe_path = os.path.join(self.buildpath, self.exe)
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    85
            self.md5key = None
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    86
            self.srcmd5 = {}
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 421
diff changeset
    87
    
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    88
    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
    89
        # Get latest computed hash and deps
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    90
        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
    91
        # read source
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    92
        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
    93
        # compute new hash
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    94
        newhash = hashlib.md5(src).hexdigest()
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    95
        # compare
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    96
        match = (oldhash == newhash)
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    97
        if not match:
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    98
            # file have changed
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
    99
            # update direct dependencies
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   100
            deps = []
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   101
            for l in src.splitlines():
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   102
                res = includes_re.match(l)
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   103
                if res is not None:
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   104
                    depfn = res.groups()[0]
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   105
                    if os.path.exists(os.path.join(self.buildpath, depfn)):
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   106
                        #print bn + " depends on "+depfn
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   107
                        deps.append(depfn)
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   108
            # store that hashand deps
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   109
            self.srcmd5[bn] = (newhash, deps)
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   110
        # recurse through deps
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   111
        # TODO detect cicular deps.
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   112
        return reduce(operator.and_, map(self.check_and_update_hash_and_deps, deps), match)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   113
                
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   114
    def build(self):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   115
        # Retrieve toolchain user parameters
1315
ff14a66bbd12 Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents: 1023
diff changeset
   116
        toolchain_params = self.CTRInstance.GetTarget().getcontent()
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   117
        self.compiler = toolchain_params.getCompiler()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   118
        self.linker = toolchain_params.getLinker()
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
   119
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
   120
        Builder_CFLAGS = ' '.join(self.getBuilderCFLAGS())
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   121
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   122
        ######### GENERATE OBJECT FILES ########################################
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   123
        obns = []
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   124
        objs = []
1023
93022adef055 Fix bug when linking failed and trying to rebuild
Laurent Bessard
parents: 728
diff changeset
   125
        relink = self.GetBinaryCode() is None
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   126
        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
   127
            if CFilesAndCFLAGS:
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 726
diff changeset
   128
                if Location :
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 726
diff changeset
   129
                    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
   130
                else:
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 726
diff changeset
   131
                    self.CTRInstance.logger.write(_("PLC :\n"))
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   132
                
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   133
            for CFile, CFLAGS in CFilesAndCFLAGS:
693
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   134
                if CFile.endswith(".c"):
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   135
                    bn = os.path.basename(CFile)
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   136
                    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
   137
                    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
   138
693
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   139
                    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
   140
                    
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   141
                    if match:
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   142
                        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
   143
                    else:
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   144
                        relink = True
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   145
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   146
                        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
   147
                        
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   148
                        status, result, err_result = ProcessLogger(
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   149
                               self.CTRInstance.logger,
693
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   150
                               "\"%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
   151
                                   (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
   152
                               ).spin()
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   153
693
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   154
                        if status :
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   155
                            self.srcmd5.pop(bn)
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   156
                            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
   157
                            return False
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   158
                    obns.append(obn)
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   159
                    objs.append(objectfilename)
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   160
                elif CFile.endswith(".o"):
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   161
                    obns.append(os.path.basename(CFile))
96fcadb6a7a0 Added support for object files as a result of PlugGenerate_C
Edouard Tisserant
parents: 677
diff changeset
   162
                    objs.append(CFile)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   163
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   164
        ######### GENERATE library FILE ########################################
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   165
        # Link all the object files into one binary file
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   166
        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
   167
        if relink:
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   168
            objstring = []
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   169
    
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   170
            # Generate list .o files
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   171
            listobjstring = '"' + '"  "'.join(objs) + '"'
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   172
    
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 285
diff changeset
   173
            ALLldflags = ' '.join(self.getBuilderLDFLAGS())
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   174
    
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   175
            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
   176
    
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   177
            status, result, err_result = ProcessLogger(
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   178
                   self.CTRInstance.logger,
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   179
                   "\"%s\" %s -o \"%s\" %s"%
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   180
                       (self.linker,
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   181
                        listobjstring,
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   182
                        self.exe_path,
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   183
                        ALLldflags)
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   184
                   ).spin()
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   185
            
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   186
            if status :
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   187
                return False
677
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   188
                
285
e5782a52dcea Added local C dependency dicovery and changes checking, to speed up build.
etisserant
parents: 203
diff changeset
   189
        else:
725
31dade089db5 refactoring
Edouard Tisserant
parents: 722
diff changeset
   190
            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
   191
        
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   192
        # Calculate md5 key and get data for the new created PLC
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   193
        data=self.GetBinaryCode()
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   194
        self.md5key = hashlib.md5(data).hexdigest()
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   195
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   196
        # Store new PLC filename based on md5 key
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   197
        f = open(self._GetMD5FileName(), "w")
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   198
        f.write(self.md5key)
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 510
diff changeset
   199
        f.close()
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   200
        
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   201
        return True
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   202