8000 Rework escaping and fix ESP build. · sparkfun/circuitpython@24e53ad · GitHub
[go: up one dir, main page]

Skip to content

Commit 24e53ad

Browse files
committed
Rework escaping and fix ESP build.
1 parent 1835f1a commit 24e53ad

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

ports/atmel-samd/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Set default python interpreters
2-
PYTHON2 ?= $(which python2 || which python2.7)
3-
PYTHON3 ?= python3
4-
51
# Select the board to build for.
62
ifeq ($(BOARD),)
73
$(error You must provide a BOARD parameter)

ports/esp8266/esp8266_common.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ SECTIONS
8989
*common-hal/*.o*(.literal* .text*)
9090
*shared-bindings/*.o*(.literal* .text*)
9191
*shared-module/*.o*(.literal* .text*)
92+
*supervisor/*.o*(.literal* .text*)
9293

9394
*py/argcheck.o*(.literal* .text*)
9495
*py/asm*.o*(.literal* .text*)

py/makeqstrdata.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@
5454
codepoint2name[ord('|')] = 'pipe'
5555
codepoint2name[ord('~')] = 'tilde'
5656

57+
C_ESCAPES = {
58+
"\a": "\\a",
59+
"\b": "\\b",
60+
"\f": "\\f",
61+
"\n": "\\r",
62+
"\r": "\\r",
63+
"\t": "\\t",
64+
"\v": "\\v",
65+
"\'": "\\'",
66+
"\"": "\\\""
67+
}
68+
5769
# this must match the equivalent function in qstr.c
5870
def compute_hash(qstr, bytes_hash):
5971
hash = 5381
@@ -66,7 +78,13 @@ def translate(translation_file, i18ns):
6678
with open(translation_file, "rb") as f:
6779
table = gettext.GNUTranslations(f)
6880

69-
return [(x, table.gettext(x.decode('string_escape'))) for x in i18ns]
81+
translations = []
82+
for original in i18ns:
83+
unescaped = original
84+
for s in C_ESCAPES:
85+
unescaped = unescaped.replace(C_ESCAPES[s], s)
86+
translations.append((original, table.gettext(unescaped)))
87+
return translations
7088

7189
def qstr_escape(qst):
7290
def esc_char(m):
@@ -182,7 +200,9 @@ def print_qstr_data(qcfgs, qstrs, i18ns):
182200
total_text_size = 0
183201
for original, translation in i18ns:
184202
# Add in carriage returns to work in terminals
185-
translation = translation.replace("\n", "\\r\\n")
203+
translation = translation.replace("\n", "\r\n")
204+
for s in C_ESCAPES:
205+
translation = translation.replace(s, C_ESCAPES[s])
186206
print("TRANSLATION(\"{}\", \"{}\")".format(original, translation))
187207
total_text_size += len(translation)
188208

py/mkenv.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ CP = cp
4949
FIND = find
5050
MKDIR = mkdir
5151
PYTHON = python
52+
# Set default python interpreters
53+
PYTHON2 ?= $(which python2 || which python2.7)
54+
PYTHON3 ?= python3
5255
RM = rm
5356
RSYNC = rsync
5457
SED = sed

py/mkrules.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ $(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) $(SRC_QSTR_PREPROCESSOR) $(QSTR_GLOBAL_
8383

8484
$(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last $(PY_SRC)/makeqstrdefs.py
8585
$(STEPECHO) "GEN $@"
86-
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
86+
$(Q)$(PYTHON3) $(PY_SRC)/makeqstrdefs.py split $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
8787
$(Q)touch $@
8888

8989
$(QSTR_DEFS_COLLECTED): $(HEADER_BUILD)/qstr.split $(PY_SRC)/makeqstrdefs.py
9090
$(STEPECHO) "GEN $@"
91-
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
91+
$(Q)$(PYTHON3) $(PY_SRC)/makeqstrdefs.py cat $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
9292

9393
# $(sort $(var)) removes duplicates
9494
#

py/py.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,15 @@ $(HEADER_BUILD)/qstrdefs.preprocessed.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(QSTR_DEF
307307
# qstr data
308308
$(HEADER_BUILD)/qstrdefs.enum.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h
309309
$(STEPECHO) "GEN $@"
310-
$(PYTHON) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@
310+
$(PYTHON3) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@
311311

312312
# Adding an order only dependency on $(HEADER_BUILD) causes $(HEADER_BUILD) to get
313313
# created before we run the script to generate the .h
314314
# Note: we need to protect the qstr names from the preprocessor, so we wrap
315315
# the lines in "" and then unwrap after the preprocessor is finished.
316316
$(HEADER_BUILD)/qstrdefs.generated.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h
317317
$(STEPECHO) "GEN $@"
318-
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py --translation $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@
318+
$(PYTHON3) $(PY_SRC)/makeqstrdata.py --translation $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@
319319

320320
$(PY_BUILD)/qstr.o: $(HEADER_BUILD)/qstrdefs.generated.h
321321

0 commit comments

Comments
 (0)
0