targets/toolchain_gcc.py
author v.petrov <v.petrov@k-soft-spb.ru>
Wed, 31 Aug 2022 12:04:51 +0500
changeset 3605 7aa4209c2b2d
parent 3571 fdd4b171ac6c
child 3739 99263915a91d
permissions -rw-r--r--
update installation instructions
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
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
    27
from __future__ import absolute_import
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
2456
7373e3048167 python3 support: pylint,W1610 # (reduce-builtin) reduce built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2439
diff changeset
    32
from functools import reduce
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    33
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
    34
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    35
2439
f0a040f1de1b Fix pep8 warning: W605 invalid escape sequence ?x?
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2168
diff changeset
    36
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
    37
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    38
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
    39
class toolchain_gcc(object):
1731
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
    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
    42
    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
    43
    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
    44
    """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    45
    def __init__(self, CTRInstance):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    46
        self.CTRInstance = CTRInstance
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    47
        self.buildpath = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    48
        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
    49
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    50
    def getBuilderCFLAGS(self):
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
        Returns list of builder specific CFLAGS
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    53
        """
3571
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    54
        cflags = [self.CTRInstance.GetTarget().getcontent().getCFLAGS()]
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    55
        if os.environ.has_key("CFLAGS"):
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    56
            cflags.append(os.environ["CFLAGS"])
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    57
        if os.environ.has_key("SYSROOT"):
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    58
            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
    59
        return cflags
1731
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
    def getBuilderLDFLAGS(self):
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
        Returns list of builder specific LDFLAGS
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    64
        """
3571
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    65
        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
    66
            [self.CTRInstance.GetTarget().getcontent().getLDFLAGS()]
3571
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    67
        if os.environ.has_key("LDLAGS"):
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    68
            ldflags.append(os.environ["LDLAGS"])
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    69
        if os.environ.has_key("SYSROOT"):
fdd4b171ac6c toolchain: GCC: use CFLAGS, LDFLAGS and SYSROOT given in environment
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2463
diff changeset
    70
            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
    71
        return ldflags
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    72
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    73
    def getCompiler(self):
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
        Returns compiler
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
        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
    78
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    79
    def getLinker(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    80
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    81
        Returns linker
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    82
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    83
        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
    84
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
    85
    def GetBinaryPath(self):
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
    86
        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
    87
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    88
    def _GetMD5FileName(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    89
        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
    90
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
    91
    def ResetBinaryMD5(self):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    92
        self.md5key = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    93
        try:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    94
            os.remove(self._GetMD5FileName())
1846
14b40afccd69 remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    95
        except Exception:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    96
            pass
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    97
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
    98
    def GetBinaryMD5(self):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
    99
        if self.md5key is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   100
            return self.md5key
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   101
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   102
            try:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   103
                return open(self._GetMD5FileName(), "r").read()
1846
14b40afccd69 remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   104
            except Exception:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   105
                return None
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   106
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   107
    def SetBuildPath(self, buildpath):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   108
        if self.buildpath != buildpath:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   109
            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
   110
            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
   111
            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
   112
            self.md5key = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   113
            self.srcmd5 = {}
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   114
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   115
    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
   116
        for l in src.splitlines():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   117
            res = includes_re.match(l)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   118
            if res is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   119
                depfn = res.groups()[0]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   120
                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
   121
                    deps.append(depfn)
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   122
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   123
    def concat_deps(self, bn):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   124
        # read source
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   125
        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
   126
        # update direct dependencies
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   127
        deps = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   128
        self.append_cfile_deps(src, deps)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   129
        # recurse through deps
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   130
        # TODO detect cicular deps.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   131
        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
   132
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   133
    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
   134
        # 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
   135
        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
   136
        # read source
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   137
        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
   138
        # compute new hash
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   139
        newhash = hashlib.md5(src).hexdigest()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   140
        # compare
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   141
        match = (oldhash == newhash)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   142
        if not match:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   143
            # file have changed
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   144
            # update direct dependencies
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   145
            deps = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   146
            self.append_cfile_deps(src, deps)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   147
            # store that hashand deps
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   148
            self.srcmd5[bn] = (newhash, deps)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   149
        # recurse through deps
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   150
        # TODO detect cicular deps.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   151
        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
   152
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   153
    def calc_source_md5(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   154
        wholesrcdata = ""
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   155
        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
   156
            # 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
   157
            for CFile, _CFLAGS in CFilesAndCFLAGS:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   158
                CFileName = os.path.basename(CFile)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   159
                wholesrcdata += self.concat_deps(CFileName)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   160
        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
   161
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   162
    def build(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   163
        # Retrieve compiler and linker
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   164
        self.compiler = self.getCompiler()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   165
        self.linker = self.getLinker()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   166
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   167
        Builder_CFLAGS = ' '.join(self.getBuilderCFLAGS())
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   168
1753
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   169
        # ----------------- GENERATE OBJECT FILES ------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   170
        obns = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   171
        objs = []
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   172
        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
   173
        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
   174
            if CFilesAndCFLAGS:
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   175
                if Location:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   176
                    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
   177
                else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   178
                    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
   179
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   180
            for CFile, CFLAGS in CFilesAndCFLAGS:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   181
                if CFile.endswith(".c"):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   182
                    bn = os.path.basename(CFile)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   183
                    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
   184
                    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
   185
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   186
                    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
   187
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   188
                    if match:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   189
                        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
   190
                    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   191
                        relink = True
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   192
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   193
                        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
   194
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   195
                        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
   196
                            self.CTRInstance.logger,
2168
a66062a205ae Build by default with optimization level -O2 for GCC
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1881
diff changeset
   197
                            "\"%s\" -c \"%s\" -o \"%s\" -O2 %s %s" %
1777
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   198
                            (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
   199
                        ).spin()
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   200
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   201
                        if status:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   202
                            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
   203
                            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
   204
                            return False
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   205
                    obns.append(obn)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   206
                    objs.append(objectfilename)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   207
                elif CFile.endswith(".o"):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   208
                    obns.append(os.path.basename(CFile))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   209
                    objs.append(CFile)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   210
1753
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   211
        # ---------------- GENERATE OUTPUT FILE --------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   212
        # 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
   213
        self.CTRInstance.logger.write(_("Linking :\n"))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   214
        if relink:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   215
            # Generate list .o files
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   216
            listobjstring = '"' + '"  "'.join(objs) + '"'
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   217
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   218
            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
   219
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   220
            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
   221
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   222
            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
   223
                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
   224
                "\"%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
   225
                (self.linker,
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   226
                 listobjstring,
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   227
                 self.bin_path,
1777
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   228
                 ALLldflags)
c46ec818bdd7 clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   229
            ).spin()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   230
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   231
            if status:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   232
                return False
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   233
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   234
        else:
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   235
            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
   236
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   237
        # Calculate md5 key and get data for the new created PLC
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2456
diff changeset
   238
        self.md5key = hashlib.md5(open(self.bin_path, "rb").read()).hexdigest()
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   239
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   240
        # 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
   241
        f = open(self._GetMD5FileName(), "w")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   242
        f.write(self.md5key)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   243
        f.close()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   244
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1681
diff changeset
   245
        return True