Skip to content

Commit 38d8bb6

Browse files
committed
Migrate old memap file handling into toolchains
### Description This PR moves the old memap file handling required for differential memap from within memap to the toolchain object. This has the advantage that we can do the `mv <app>.map <app>.map.old` the moment before it is overwritten by the linker. This should allow multiple reruns of memap without modifying your build directory. ### Pull request type [ ] Fix [x] Refactor [ ] Target update [ ] Functionality change [ ] Docs update [ ] Test update [ ] Breaking change
1 parent fdca1e3 commit 38d8bb6

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

tools/memap.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
from abc import abstractmethod, ABCMeta
77
from sys import stdout, exit, argv, path
8-
from os import sep, rename, remove
8+
from os import sep
99
from os.path import (basename, dirname, join, relpath, abspath, commonprefix,
10-
splitext, exists)
10+
splitext)
1111

1212
# Be sure that the tools directory is in the search path
1313
ROOT = abspath(join(dirname(__file__), ".."))
@@ -25,7 +25,6 @@
2525

2626
from tools.utils import (argparse_filestring_type, argparse_lowercase_hyphen_type,
2727
argparse_uppercase_type)
28-
from tools.settings import COMPARE_FIXED
2928

3029

3130
class _Parser(object):
@@ -831,11 +830,6 @@ def parse(self, mapfile, toolchain):
831830
self.old_modules = parser().parse_mapfile(old_input)
832831
except IOError:
833832
self.old_modules = None
834-
if not COMPARE_FIXED:
835-
old_mapfile = "%s.old" % mapfile
836-
if exists(old_mapfile):
837-
remove(old_mapfile)
838-
rename(mapfile, old_mapfile)
839833
return True
840834

841835
except IOError as error:

tools/toolchains/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import re
2020
import sys
2121
import json
22-
from os import stat, walk, getcwd, sep, remove, getenv
22+
from os import stat, walk, getcwd, sep, remove, getenv, rename, remove
2323
from copy import copy
2424
from time import time, sleep
2525
from shutil import copyfile
@@ -41,6 +41,7 @@
4141
from ..resources import FileType
4242
from ..memap import MemapParser
4343
from ..config import (ConfigException, RAM_ALL_MEMORIES, ROM_ALL_MEMORIES)
44+
from ..settings import COMPARE_FIXED
4445

4546

4647
#Disables multiprocessing if set to higher number than the host machine CPUs
@@ -617,7 +618,7 @@ def link_program(self, r, tmp_path, name):
617618
full_path = join(tmp_path, filename)
618619
elf = join(tmp_path, name + '.elf')
619620
bin = None if ext == 'elf' else full_path
620-
map = join(tmp_path, name + '.map')
621+
mapfile = join(tmp_path, name + '.map')
621622

622623
objects = sorted(set(r.get_file_paths(FileType.OBJECT)))
623624
config_file = ([self.config.app_config_location]
@@ -634,6 +635,11 @@ def link_program(self, r, tmp_path, name):
634635
dependencies = objects + libraries + [linker_script] + config_file + hex_files
635636
dependencies.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-ld"))
636637
if self.need_update(elf, dependencies):
638+
if not COMPARE_FIXED and exists(mapfile):
639+
old_mapfile = "%s.old" % mapfile
640+
if exists(old_mapfile):
641+
remove(old_mapfile)
642+
rename(mapfile, old_mapfile)
637643
needed_update = True
638644
self.progress("link", name)
639645
self.link(elf, objects, libraries, lib_dirs, linker_script)
@@ -644,7 +650,7 @@ def link_program(self, r, tmp_path, name):
644650
self.binary(r, elf, bin)
645651

646652
# Initialize memap and process map file. This doesn't generate output.
647-
self.mem_stats(map)
653+
self.mem_stats(mapfile)
648654

649655
self.notify.var("compile_succeded", True)
650656
self.notify.var("binary", filename)

0 commit comments

Comments
 (0)