Rework escaping and fix ESP build.

This commit is contained in:
Scott Shawcroft 2018-08-09 15:58:45 -07:00
parent 1835f1ab14
commit 24e53ad591
No known key found for this signature in database
GPG Key ID: FD0EDC4B6C53CA59
6 changed files with 30 additions and 10 deletions

View File

@ -1,7 +1,3 @@
# Set default python interpreters
PYTHON2 ?= $(which python2 || which python2.7)
PYTHON3 ?= python3
# Select the board to build for. # Select the board to build for.
ifeq ($(BOARD),) ifeq ($(BOARD),)
$(error You must provide a BOARD parameter) $(error You must provide a BOARD parameter)

View File

@ -89,6 +89,7 @@ SECTIONS
*common-hal/*.o*(.literal* .text*) *common-hal/*.o*(.literal* .text*)
*shared-bindings/*.o*(.literal* .text*) *shared-bindings/*.o*(.literal* .text*)
*shared-module/*.o*(.literal* .text*) *shared-module/*.o*(.literal* .text*)
*supervisor/*.o*(.literal* .text*)
*py/argcheck.o*(.literal* .text*) *py/argcheck.o*(.literal* .text*)
*py/asm*.o*(.literal* .text*) *py/asm*.o*(.literal* .text*)

View File

@ -54,6 +54,18 @@ codepoint2name[ord('^')] = 'caret'
codepoint2name[ord('|')] = 'pipe' codepoint2name[ord('|')] = 'pipe'
codepoint2name[ord('~')] = 'tilde' codepoint2name[ord('~')] = 'tilde'
C_ESCAPES = {
"\a": "\\a",
"\b": "\\b",
"\f": "\\f",
"\n": "\\r",
"\r": "\\r",
"\t": "\\t",
"\v": "\\v",
"\'": "\\'",
"\"": "\\\""
}
# this must match the equivalent function in qstr.c # this must match the equivalent function in qstr.c
def compute_hash(qstr, bytes_hash): def compute_hash(qstr, bytes_hash):
hash = 5381 hash = 5381
@ -66,7 +78,13 @@ def translate(translation_file, i18ns):
with open(translation_file, "rb") as f: with open(translation_file, "rb") as f:
table = gettext.GNUTranslations(f) table = gettext.GNUTranslations(f)
return [(x, table.gettext(x.decode('string_escape'))) for x in i18ns] translations = []
for original in i18ns:
unescaped = original
for s in C_ESCAPES:
unescaped = unescaped.replace(C_ESCAPES[s], s)
translations.append((original, table.gettext(unescaped)))
return translations
def qstr_escape(qst): def qstr_escape(qst):
def esc_char(m): def esc_char(m):
@ -182,7 +200,9 @@ def print_qstr_data(qcfgs, qstrs, i18ns):
total_text_size = 0 total_text_size = 0
for original, translation in i18ns: for original, translation in i18ns:
# Add in carriage returns to work in terminals # Add in carriage returns to work in terminals
translation = translation.replace("\n", "\\r\\n") translation = translation.replace("\n", "\r\n")
for s in C_ESCAPES:
translation = translation.replace(s, C_ESCAPES[s])
print("TRANSLATION(\"{}\", \"{}\")".format(original, translation)) print("TRANSLATION(\"{}\", \"{}\")".format(original, translation))
total_text_size += len(translation) total_text_size += len(translation)

View File

@ -49,6 +49,9 @@ CP = cp
FIND = find FIND = find
MKDIR = mkdir MKDIR = mkdir
PYTHON = python PYTHON = python
# Set default python interpreters
PYTHON2 ?= $(which python2 || which python2.7)
PYTHON3 ?= python3
RM = rm RM = rm
RSYNC = rsync RSYNC = rsync
SED = sed SED = sed

View File

@ -83,12 +83,12 @@ $(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) $(SRC_QSTR_PREPROCESSOR) $(QSTR_GLOBAL_
$(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last $(PY_SRC)/makeqstrdefs.py $(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last $(PY_SRC)/makeqstrdefs.py
$(STEPECHO) "GEN $@" $(STEPECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED) $(Q)$(PYTHON3) $(PY_SRC)/makeqstrdefs.py split $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
$(Q)touch $@ $(Q)touch $@
$(QSTR_DEFS_COLLECTED): $(HEADER_BUILD)/qstr.split $(PY_SRC)/makeqstrdefs.py $(QSTR_DEFS_COLLECTED): $(HEADER_BUILD)/qstr.split $(PY_SRC)/makeqstrdefs.py
$(STEPECHO) "GEN $@" $(STEPECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED) $(Q)$(PYTHON3) $(PY_SRC)/makeqstrdefs.py cat $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
# $(sort $(var)) removes duplicates # $(sort $(var)) removes duplicates
# #

View File

@ -307,7 +307,7 @@ $(HEADER_BUILD)/qstrdefs.preprocessed.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(QSTR_DEF
# qstr data # qstr data
$(HEADER_BUILD)/qstrdefs.enum.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h $(HEADER_BUILD)/qstrdefs.enum.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h
$(STEPECHO) "GEN $@" $(STEPECHO) "GEN $@"
$(PYTHON) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ $(PYTHON3) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@
# Adding an order only dependency on $(HEADER_BUILD) causes $(HEADER_BUILD) to get # Adding an order only dependency on $(HEADER_BUILD) causes $(HEADER_BUILD) to get
# created before we run the script to generate the .h # created before we run the script to generate the .h
@ -315,7 +315,7 @@ $(HEADER_BUILD)/qstrdefs.enum.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrd
# the lines in "" and then unwrap after the preprocessor is finished. # the lines in "" and then unwrap after the preprocessor is finished.
$(HEADER_BUILD)/qstrdefs.generated.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h $(HEADER_BUILD)/qstrdefs.generated.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h
$(STEPECHO) "GEN $@" $(STEPECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py --translation $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ $(PYTHON3) $(PY_SRC)/makeqstrdata.py --translation $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@
$(PY_BUILD)/qstr.o: $(HEADER_BUILD)/qstrdefs.generated.h $(PY_BUILD)/qstr.o: $(HEADER_BUILD)/qstrdefs.generated.h