targets/toolchain_gcc.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 21 Sep 2017 15:02:36 +0300
changeset 1821 44a47d255d36
parent 1777 c46ec818bdd7
child 1831 56b48961cc68
permissions -rwxr-xr-x
fix problem if DataTypeEditor was imported before localization is
loaded

That doesn't affect systems with english locales.
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
     1
#!/usr/bin/env python
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
     2
# -*- coding: utf-8 -*-
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
     3
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
     6
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
     8
# Copyright (C) 2017: Paul Beltyukov
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
     9
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    10
# See COPYING file for copyrights details.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    11
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    12
# This program is free software; you can redistribute it and/or
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    13
# modify it under the terms of the GNU General Public License
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    14
# as published by the Free Software Foundation; either version 2
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    15
# of the License, or (at your option) any later version.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    16
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    17
# This program is distributed in the hope that it will be useful,
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    20
# GNU General Public License for more details.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    21
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    22
# You should have received a copy of the GNU General Public License
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    23
# along with this program; if not, write to the Free Software
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    25
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
    26
import os
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
    27
import re
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
    28
import operator
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    29
from util.ProcessLogger import ProcessLogger
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    30
import hashlib
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    31
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
    32
includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*')
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    33
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    34
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    35
class toolchain_gcc():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    36
    """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    37
    This abstract class contains GCC specific code.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    38
    It cannot be used as this and should be inherited in a target specific
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    39
    class such as target_linux or target_win32
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    40
    """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    41
    def __init__(self, CTRInstance):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    42
        self.CTRInstance = CTRInstance
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    43
        self.buildpath = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    44
        self.SetBuildPath(self.CTRInstance._getBuildPath())
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    45
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    46
    def getBuilderCFLAGS(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    47
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    48
        Returns list of builder specific CFLAGS
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    49
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    50
        return [self.CTRInstance.GetTarget().getcontent().getCFLAGS()]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    51
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    52
    def getBuilderLDFLAGS(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    53
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    54
        Returns list of builder specific LDFLAGS
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    55
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    56
        return self.CTRInstance.LDFLAGS + \
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
    57
            [self.CTRInstance.GetTarget().getcontent().getLDFLAGS()]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    58
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    59
    def getCompiler(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    60
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    61
        Returns compiler
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    62
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    63
        return self.CTRInstance.GetTarget().getcontent().getCompiler()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    64
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    65
    def getLinker(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    66
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    67
        Returns linker
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    68
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    69
        return self.CTRInstance.GetTarget().getcontent().getLinker()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    70
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    71
    def GetBinaryCode(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    72
        try:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    73
            return open(self.exe_path, "rb").read()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    74
        except Exception, e:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    75
            return None
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    76
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    77
    def _GetMD5FileName(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    78
        return os.path.join(self.buildpath, "lastbuildPLC.md5")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    79
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    80
    def ResetBinaryCodeMD5(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    81
        self.md5key = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    82
        try:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    83
            os.remove(self._GetMD5FileName())
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    84
        except Exception, e:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    85
            pass
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    86
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    87
    def GetBinaryCodeMD5(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    88
        if self.md5key is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    89
            return self.md5key
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    90
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    91
            try:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    92
                return open(self._GetMD5FileName(), "r").read()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    93
            except Exception, e:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    94
                return None
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    95
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    96
    def SetBuildPath(self, buildpath):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    97
        if self.buildpath != buildpath:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    98
            self.buildpath = buildpath
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    99
            self.exe = self.CTRInstance.GetProjectName() + self.extension
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   100
            self.exe_path = os.path.join(self.buildpath, self.exe)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   101
            self.md5key = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   102
            self.srcmd5 = {}
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   103
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   104
    def append_cfile_deps(self, src, deps):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   105
        for l in src.splitlines():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   106
            res = includes_re.match(l)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   107
            if res is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   108
                depfn = res.groups()[0]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   109
                if os.path.exists(os.path.join(self.buildpath, depfn)):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   110
                    deps.append(depfn)
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   111
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   112
    def concat_deps(self, bn):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   113
        # read source
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   114
        src = open(os.path.join(self.buildpath, bn), "r").read()
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   115
        # update direct dependencies
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   116
        deps = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   117
        self.append_cfile_deps(src, deps)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   118
        # recurse through deps
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   119
        # TODO detect cicular deps.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   120
        return reduce(operator.concat, map(self.concat_deps, deps), src)
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   121
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   122
    def check_and_update_hash_and_deps(self, bn):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   123
        # Get latest computed hash and deps
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   124
        oldhash, deps = self.srcmd5.get(bn, (None, []))
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   125
        # read source
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   126
        src = open(os.path.join(self.buildpath, bn)).read()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   127
        # compute new hash
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   128
        newhash = hashlib.md5(src).hexdigest()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   129
        # compare
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   130
        match = (oldhash == newhash)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   131
        if not match:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   132
            # file have changed
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   133
            # update direct dependencies
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   134
            deps = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   135
            self.append_cfile_deps(src, deps)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   136
            # store that hashand deps
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   137
            self.srcmd5[bn] = (newhash, deps)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   138
        # recurse through deps
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   139
        # TODO detect cicular deps.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   140
        return reduce(operator.and_, map(self.check_and_update_hash_and_deps, deps), match)
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   141
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   142
    def calc_source_md5(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   143
        wholesrcdata = ""
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   144
        for Location, CFilesAndCFLAGS, DoCalls in self.CTRInstance.LocationCFilesAndCFLAGS:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   145
            # Get CFiles list to give it to makefile
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   146
            for CFile, CFLAGS in CFilesAndCFLAGS:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   147
                CFileName = os.path.basename(CFile)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   148
                wholesrcdata += self.concat_deps(CFileName)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   149
        return hashlib.md5(wholesrcdata).hexdigest()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   150
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   151
    def calc_md5(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   152
        return hashlib.md5(self.GetBinaryCode()).hexdigest()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   153
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   154
    def build(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   155
        # Retrieve compiler and linker
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   156
        self.compiler = self.getCompiler()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   157
        self.linker = self.getLinker()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   158
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   159
        Builder_CFLAGS = ' '.join(self.getBuilderCFLAGS())
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   160
1753
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   161
        # ----------------- GENERATE OBJECT FILES ------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   162
        obns = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   163
        objs = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   164
        relink = self.GetBinaryCode() is None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   165
        for Location, CFilesAndCFLAGS, DoCalls in self.CTRInstance.LocationCFilesAndCFLAGS:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   166
            if CFilesAndCFLAGS:
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   167
                if Location:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   168
                    self.CTRInstance.logger.write(".".join(map(str, Location))+" :\n")
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   169
                else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   170
                    self.CTRInstance.logger.write(_("PLC :\n"))
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   171
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   172
            for CFile, CFLAGS in CFilesAndCFLAGS:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   173
                if CFile.endswith(".c"):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   174
                    bn = os.path.basename(CFile)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   175
                    obn = os.path.splitext(bn)[0]+".o"
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   176
                    objectfilename = os.path.splitext(CFile)[0]+".o"
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   177
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   178
                    match = self.check_and_update_hash_and_deps(bn)
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   179
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   180
                    if match:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   181
                        self.CTRInstance.logger.write("   [pass]  "+bn+" -> "+obn+"\n")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   182
                    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   183
                        relink = True
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   184
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   185
                        self.CTRInstance.logger.write("   [CC]  "+bn+" -> "+obn+"\n")
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   186
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   187
                        status, result, err_result = ProcessLogger(
1777
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   188
                            self.CTRInstance.logger,
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   189
                            "\"%s\" -c \"%s\" -o \"%s\" %s %s" %
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   190
                            (self.compiler, CFile, objectfilename, Builder_CFLAGS, CFLAGS)
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   191
                        ).spin()
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   192
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   193
                        if status:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   194
                            self.srcmd5.pop(bn)
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   195
                            self.CTRInstance.logger.write_error(_("C compilation of %s failed.\n") % bn)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   196
                            return False
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   197
                    obns.append(obn)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   198
                    objs.append(objectfilename)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   199
                elif CFile.endswith(".o"):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   200
                    obns.append(os.path.basename(CFile))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   201
                    objs.append(CFile)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   202
1753
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   203
        # ---------------- GENERATE OUTPUT FILE --------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   204
        # Link all the object files into one binary file
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   205
        self.CTRInstance.logger.write(_("Linking :\n"))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   206
        if relink:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   207
            objstring = []
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   208
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   209
            # Generate list .o files
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   210
            listobjstring = '"' + '"  "'.join(objs) + '"'
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   211
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   212
            ALLldflags = ' '.join(self.getBuilderLDFLAGS())
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   213
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   214
            self.CTRInstance.logger.write("   [CC]  " + ' '.join(obns)+" -> " + self.exe + "\n")
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   215
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   216
            status, result, err_result = ProcessLogger(
1777
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   217
                self.CTRInstance.logger,
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   218
                "\"%s\" %s -o \"%s\" %s" %
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   219
                (self.linker,
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   220
                 listobjstring,
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   221
                 self.exe_path,
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   222
                 ALLldflags)
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   223
            ).spin()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   224
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   225
            if status:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   226
                return False
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   227
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   228
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   229
            self.CTRInstance.logger.write("   [pass]  " + ' '.join(obns)+" -> " + self.exe + "\n")
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   230
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   231
        # Calculate md5 key and get data for the new created PLC
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   232
        self.md5key = self.calc_md5()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   233
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   234
        # Store new PLC filename based on md5 key
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   235
        f = open(self._GetMD5FileName(), "w")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   236
        f.write(self.md5key)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   237
        f.close()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   238
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   239
        return True