targets/toolchain_gcc.py
author Edouard Tisserant <edouard@beremiz.fr>
Mon, 22 Jul 2024 12:12:33 +0200
changeset 3994 c399fe412dbd
parent 3982 69d161fc2e08
child 4012 6337c9c2c379
permissions -rw-r--r--
MQTT: WIP, prevent crash after disconnect. Disable auto-reconnect on connection lost callback.
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
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
    26
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3739
diff changeset
    27
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
    28
import os
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
    29
import re
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
    30
import operator
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1831
diff changeset
    31
import hashlib
3893
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
    32
import subprocess
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
    33
import shlex
2456
7373e3048167 python3 support: pylint,W1610 # (reduce-builtin) reduce built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2439
diff changeset
    34
from functools import reduce
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    35
from util.ProcessLogger import ProcessLogger
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1831
diff changeset
    36
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    37
2439
f0a040f1de1b Fix pep8 warning: W605 invalid escape sequence ?x?
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2168
diff changeset
    38
includes_re = re.compile(r'\s*#include\s*["<]([^">]*)[">].*')
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    39
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    40
3982
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    41
def compute_file_md5(filetocheck):
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    42
    hasher = hashlib.md5()
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    43
    with open(filetocheck, 'rb') as afile:
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    44
        while True:
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    45
            buf = afile.read(65536)
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    46
            if len(buf) > 0:
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    47
                hasher.update(buf)
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    48
            else:
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    49
                break
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    50
    return hasher.hexdigest()
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    51
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
    52
1831
56b48961cc68 fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1777
diff changeset
    53
class toolchain_gcc(object):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    54
    """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    55
    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
    56
    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
    57
    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
    58
    """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    59
    def __init__(self, CTRInstance):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    60
        self.CTRInstance = CTRInstance
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    61
        self.buildpath = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    62
        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
    63
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    64
    def getBuilderCFLAGS(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    65
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    66
        Returns list of builder specific CFLAGS
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    67
        """
3571
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    68
        cflags = [self.CTRInstance.GetTarget().getcontent().getCFLAGS()]
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3739
diff changeset
    69
        if "CFLAGS" in os.environ:
3571
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    70
            cflags.append(os.environ["CFLAGS"])
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3739
diff changeset
    71
        if "SYSROOT" in os.environ:
3571
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    72
            cflags.append("--sysroot="+os.environ["SYSROOT"])
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    73
        return cflags
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    74
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    75
    def getBuilderLDFLAGS(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    76
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    77
        Returns list of builder specific LDFLAGS
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    78
        """
3571
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    79
        ldflags = 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
    80
            [self.CTRInstance.GetTarget().getcontent().getLDFLAGS()]
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3739
diff changeset
    81
        if "LDLAGS" in os.environ:
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3739
diff changeset
    82
            ldflags.append(os.environ["LDLAGS"])
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3739
diff changeset
    83
        if "SYSROOT" in os.environ:
3571
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    84
            ldflags.append("--sysroot="+os.environ["SYSROOT"])
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    85
        return ldflags
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    86
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    87
    def getCompiler(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    88
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    89
        Returns compiler
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    90
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    91
        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
    92
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    93
    def getLinker(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    94
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    95
        Returns linker
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    96
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    97
        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
    98
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
    99
    def GetBinaryPath(self):
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   100
        return self.bin_path
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   101
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   102
    def _GetMD5FileName(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   103
        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
   104
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   105
    def ResetBinaryMD5(self):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   106
        self.md5key = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   107
        try:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   108
            os.remove(self._GetMD5FileName())
1846
14b40afccd69 remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   109
        except Exception:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   110
            pass
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   111
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   112
    def GetBinaryMD5(self):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   113
        if self.md5key is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   114
            return self.md5key
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   115
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   116
            try:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   117
                return open(self._GetMD5FileName(), "r").read()
1846
14b40afccd69 remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   118
            except Exception:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   119
                return None
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   120
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   121
    def SetBuildPath(self, buildpath):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   122
        if self.buildpath != buildpath:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   123
            self.buildpath = buildpath
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   124
            self.bin = self.CTRInstance.GetProjectName() + self.extension
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   125
            self.bin_path = os.path.join(self.buildpath, self.bin)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   126
            self.md5key = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   127
            self.srcmd5 = {}
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   128
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   129
    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
   130
        for l in src.splitlines():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   131
            res = includes_re.match(l)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   132
            if res is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   133
                depfn = res.groups()[0]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   134
                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
   135
                    deps.append(depfn)
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   136
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   137
    def concat_deps(self, bn):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   138
        # read source
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   139
        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
   140
        # update direct dependencies
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   141
        deps = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   142
        self.append_cfile_deps(src, deps)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   143
        # recurse through deps
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   144
        # TODO detect cicular deps.
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3739
diff changeset
   145
        return reduce(operator.concat, list(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
   146
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   147
    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
   148
        # 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
   149
        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
   150
        # read source
3982
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
   151
        src = os.path.join(self.buildpath, bn)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   152
        # compute new hash
3982
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
   153
        newhash = compute_file_md5(src)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   154
        # compare
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   155
        match = (oldhash == newhash)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   156
        if not match:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   157
            # file have changed
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   158
            # update direct dependencies
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   159
            deps = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   160
            self.append_cfile_deps(src, deps)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   161
            # store that hashand deps
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   162
            self.srcmd5[bn] = (newhash, deps)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   163
        # recurse through deps
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   164
        # TODO detect cicular deps.
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3739
diff changeset
   165
        return reduce(operator.and_, list(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
   166
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   167
    def calc_source_md5(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   168
        wholesrcdata = ""
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   169
        for _Location, CFilesAndCFLAGS, _DoCalls in self.CTRInstance.LocationCFilesAndCFLAGS:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   170
            # Get CFiles list to give it to makefile
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   171
            for CFile, _CFLAGS in CFilesAndCFLAGS:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   172
                CFileName = os.path.basename(CFile)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   173
                wholesrcdata += self.concat_deps(CFileName)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   174
        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
   175
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   176
    def build(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   177
        # Retrieve compiler and linker
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   178
        self.compiler = self.getCompiler()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   179
        self.linker = self.getLinker()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   180
3893
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   181
        Builder_CFLAGS_str = ' '.join(self.getBuilderCFLAGS())
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   182
        Builder_LDFLAGS_str = ' '.join(self.getBuilderLDFLAGS())
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   183
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   184
        Builder_CFLAGS = shlex.split(Builder_CFLAGS_str)
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   185
        Builder_LDFLAGS = shlex.split(Builder_LDFLAGS_str)
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   186
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   187
        pattern = "{SYSROOT}"
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   188
        if pattern in Builder_CFLAGS_str or pattern in Builder_LDFLAGS_str:
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   189
            try:
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   190
                sysrootb = subprocess.check_output(["arm-unknown-linux-gnueabihf-gcc","-print-sysroot"])
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   191
            except subprocess.CalledProcessError:
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   192
                self.CTRInstance.logger.write("GCC failed with -print-sysroot\n")
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   193
                return False
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   194
            except FileNotFoundError:
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   195
                self.CTRInstance.logger.write("GCC not found\n")
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   196
                return False
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   197
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   198
            sysroot = sysrootb.decode().strip()
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   199
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   200
            replace_sysroot = lambda l:list(map(lambda s:s.replace(pattern, sysroot), l))
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   201
            Builder_CFLAGS = replace_sysroot(Builder_CFLAGS)
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   202
            Builder_LDFLAGS = replace_sysroot(Builder_LDFLAGS)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   203
1753
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   204
        # ----------------- GENERATE OBJECT FILES ------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   205
        obns = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   206
        objs = []
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   207
        relink = not os.path.exists(self.bin_path)
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   208
        for Location, CFilesAndCFLAGS, _DoCalls in self.CTRInstance.LocationCFilesAndCFLAGS:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   209
            if CFilesAndCFLAGS:
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   210
                if Location:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   211
                    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
   212
                else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   213
                    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
   214
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   215
            for CFile, CFLAGS in CFilesAndCFLAGS:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   216
                if CFile.endswith(".c"):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   217
                    bn = os.path.basename(CFile)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   218
                    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
   219
                    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
   220
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   221
                    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
   222
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   223
                    if match:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   224
                        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
   225
                    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   226
                        relink = True
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   227
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   228
                        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
   229
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   230
                        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
   231
                            self.CTRInstance.logger,
3893
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   232
                            [self.compiler,
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   233
                             "-c", CFile,
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   234
                             "-o", objectfilename,
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   235
                             "-O2"]
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   236
                            + Builder_CFLAGS
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   237
                            + shlex.split(CFLAGS)
1777
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   238
                        ).spin()
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   239
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   240
                        if status:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   241
                            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
   242
                            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
   243
                            return False
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   244
                    obns.append(obn)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   245
                    objs.append(objectfilename)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   246
                elif CFile.endswith(".o"):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   247
                    obns.append(os.path.basename(CFile))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   248
                    objs.append(CFile)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   249
1753
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   250
        # ---------------- GENERATE OUTPUT FILE --------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   251
        # 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
   252
        self.CTRInstance.logger.write(_("Linking :\n"))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   253
        if relink:
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   254
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   255
            self.CTRInstance.logger.write("   [CC]  " + ' '.join(obns)+" -> " + self.bin + "\n")
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   256
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   257
            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
   258
                self.CTRInstance.logger,
3893
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   259
                [self.linker] + objs
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   260
                + ["-o", self.bin_path]
5b2f3a915a43 GCC toolchain: Add {SYSROOT} substitution with support for whitespaces
Edouard Tisserant <edouard@beremiz.fr>
parents: 3755
diff changeset
   261
                + Builder_LDFLAGS
1777
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   262
            ).spin()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   263
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   264
            if status:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   265
                return False
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   266
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   267
        else:
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   268
            self.CTRInstance.logger.write("   [pass]  " + ' '.join(obns)+" -> " + self.bin + "\n")
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   269
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   270
        # Calculate md5 key and get data for the new created PLC
3982
69d161fc2e08 GCC BUILD: Prevent Memory Error when compiling huge projects.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3893
diff changeset
   271
        self.md5key = compute_file_md5(self.bin_path)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   272
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   273
        # 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
   274
        f = open(self._GetMD5FileName(), "w")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   275
        f.write(self.md5key)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   276
        f.close()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   277
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   278
        return True