Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit71a51b1

Browse files
authored
Resolve Windows path problems (esp8266#8860)
Moved up os.makedirs for ./core/ directory.Strange problem creating files with file paths with spaces.Strange that "create file" would work when the path did not contain spaces and the last folder of the path hadn't been created.Added try/except on main to commit print buffer on traceback for context.Additional issues with diacritics and locale character encoding for shell vs source code.build.opt is written with the same encoding as the shell; however, the data read from the Sketch.ino.global.h is UTF-8.Tested on Windows 10 (en-US) with Arduino IDE 2.0.3 Under anaccount with a diacritic character in the user ID path.Needs testing on Japanese Windows
1 parentd7cd4be commit71a51b1

File tree

2 files changed

+92
-12
lines changed

2 files changed

+92
-12
lines changed

‎tools/mkbuildoptglobals.py‎

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@
187187
importglob
188188
importos
189189
importplatform
190+
importtraceback
190191
importsys
191192
importtextwrap
192193
importtime
193194

195+
importlocale
196+
194197
# Need to work on signature line used for match to avoid conflicts with
195198
# existing embedded documentation methods.
196199
build_opt_signature="/*@create-file:build.opt@"
@@ -201,6 +204,7 @@
201204
err_print_flag=False
202205
msg_print_buf=""
203206
debug_enabled=False
207+
default_encoding=None
204208

205209
# Issues trying to address through buffered printing
206210
# 1. Arduino IDE 2.0 RC5 does not show stderr text in color. Text printed does
@@ -295,16 +299,16 @@ def copy_create_build_file(source_fqfn, build_target_fqfn):
295299
pass
296300
returnTrue# file changed
297301

298-
299302
defadd_include_line(build_opt_fqfn,include_fqfn):
303+
globaldefault_encoding
300304
ifnotos.path.exists(include_fqfn):
301305
# If file is missing, we need an place holder
302-
withopen(include_fqfn,'w',encoding="utf-8"):
306+
withopen(include_fqfn,'w',encoding=default_encoding):
303307
pass
304-
print("add_include_line: Created "+include_fqfn)
305-
withopen(build_opt_fqfn,'a',encoding="utf-8")asbuild_opt:
306-
build_opt.write('-include "'+include_fqfn.replace('\\','\\\\')+'"\n')
308+
print_msg("add_include_line: Created "+include_fqfn)
307309

310+
withopen(build_opt_fqfn,'a',encoding=default_encoding)asbuild_opt:
311+
build_opt.write('-include "'+include_fqfn.replace('\\','\\\\')+'"\n')
308312

309313
defextract_create_build_opt_file(globals_h_fqfn,file_name,build_opt_fqfn):
310314
"""
@@ -313,8 +317,9 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
313317
copy of Sketch.ino.globals.h.
314318
"""
315319
globalbuild_opt_signature
320+
globaldefault_encoding
316321

317-
build_opt=open(build_opt_fqfn,'w',encoding="utf-8")
322+
build_opt=open(build_opt_fqfn,'w',encoding=default_encoding)
318323
ifnotos.path.exists(globals_h_fqfn)or (0==os.path.getsize(globals_h_fqfn)):
319324
build_opt.close()
320325
returnFalse
@@ -605,12 +610,63 @@ def parse_args():
605610
# ref nargs='*'', https://stackoverflow.com/a/4480202
606611
# ref no '--n' parameter, https://stackoverflow.com/a/21998252
607612

613+
614+
# retrieve *system* encoding, not the one used by python internally
615+
ifsys.version_info>= (3,11):
616+
defget_encoding():
617+
returnlocale.getencoding()
618+
else:
619+
defget_encoding():
620+
returnlocale.getdefaultlocale()[1]
621+
622+
623+
defshow_value(desc,value):
624+
print_dbg(f'{desc:<40}{value}')
625+
return
626+
627+
deflocale_dbg():
628+
show_value("get_encoding()",get_encoding())
629+
show_value("locale.getdefaultlocale()",locale.getdefaultlocale())
630+
show_value('sys.getfilesystemencoding()',sys.getfilesystemencoding())
631+
show_value("sys.getdefaultencoding()",sys.getdefaultencoding())
632+
show_value("locale.getpreferredencoding(False)",locale.getpreferredencoding(False))
633+
try:
634+
show_value("locale.getpreferredencoding()",locale.getpreferredencoding())
635+
except:
636+
pass
637+
show_value("sys.stdout.encoding",sys.stdout.encoding)
638+
639+
# use current setting
640+
show_value("locale.setlocale(locale.LC_ALL, None)",locale.setlocale(locale.LC_ALL,None))
641+
try:
642+
show_value("locale.getencoding()",locale.getencoding())
643+
except:
644+
pass
645+
show_value("locale.getlocale()",locale.getlocale())
646+
647+
# use user setting
648+
show_value("locale.setlocale(locale.LC_ALL, '')",locale.setlocale(locale.LC_ALL,''))
649+
# show_value("locale.getencoding()", locale.getencoding())
650+
show_value("locale.getlocale()",locale.getlocale())
651+
return
652+
653+
608654
defmain():
609655
globalbuild_opt_signature
610656
globaldocs_url
611657
globaldebug_enabled
658+
globaldefault_encoding
612659
num_include_lines=1
613660

661+
# Given that GCC will handle lines from an @file as if they were on
662+
# the command line. I assume that the contents of @file need to be encoded
663+
# to match that of the shell running GCC runs. I am not 100% sure this API
664+
# gives me that, but it appears to work.
665+
#
666+
# However, elsewhere when dealing with source code we continue to use 'utf-8',
667+
# ref. https://gcc.gnu.org/onlinedocs/cpp/Character-sets.html
668+
default_encoding=get_encoding()
669+
614670
args=parse_args()
615671
debug_enabled=args.debug
616672
runtime_ide_path=os.path.normpath(args.runtime_ide_path)
@@ -623,6 +679,13 @@ def main():
623679
build_path_core,build_opt_name=os.path.split(build_opt_fqfn)
624680
globals_h_fqfn=os.path.join(build_path_core,globals_name)
625681

682+
ifdebug_enabled:
683+
locale_dbg()
684+
685+
default_locale=locale.getdefaultlocale()
686+
print_msg(f'default locale:{default_locale}')
687+
print_msg(f'default_encoding:{default_encoding}')
688+
626689
print_dbg(f"runtime_ide_path:{runtime_ide_path}")
627690
print_dbg(f"runtime_ide_version:{args.runtime_ide_version}")
628691
print_dbg(f"build_path:{build_path}")
@@ -655,6 +718,10 @@ def main():
655718
print_dbg(f"first_time:{first_time}")
656719
print_dbg(f"use_aggressive_caching_workaround:{use_aggressive_caching_workaround}")
657720

721+
ifnotos.path.exists(build_path_core):
722+
os.makedirs(build_path_core)
723+
print_msg("Clean build, created dir "+build_path_core)
724+
658725
iffirst_timeor \
659726
notuse_aggressive_caching_workaroundor \
660727
notos.path.exists(commonhfile_fqfn):
@@ -667,10 +734,6 @@ def main():
667734
touch(commonhfile_fqfn)
668735
print_err(f"Neutralized future timestamp on build file:{commonhfile_fqfn}")
669736

670-
ifnotos.path.exists(build_path_core):
671-
os.makedirs(build_path_core)
672-
print_msg("Clean build, created dir "+build_path_core)
673-
674737
ifos.path.exists(source_globals_h_fqfn):
675738
print_msg("Using global include from "+source_globals_h_fqfn)
676739

@@ -750,4 +813,10 @@ def main():
750813
handle_error(0)# commit print buffer
751814

752815
if__name__=='__main__':
753-
sys.exit(main())
816+
rc=1
817+
try:
818+
rc=main()
819+
except:
820+
print_err(traceback.format_exc())
821+
handle_error(0)
822+
sys.exit(rc)

‎tools/sizes.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@
2121
importos
2222
importsubprocess
2323
importsys
24+
importlocale
2425

2526
sys.stdout=sys.stderr
2627

28+
29+
# retrieve *system* encoding, not the one used by python internally
30+
ifsys.version_info>= (3,11):
31+
defget_encoding():
32+
returnlocale.getencoding()
33+
else:
34+
defget_encoding():
35+
returnlocale.getdefaultlocale()[1]
36+
37+
2738
defget_segment_sizes(elf,path,mmu):
2839
iram_size=0
2940
iheap_size=0
@@ -73,7 +84,7 @@ def get_segment_sizes(elf, path, mmu):
7384
)
7485

7586
cmd= [os.path.join(path,"xtensa-lx106-elf-size"),"-A",elf]
76-
withsubprocess.Popen(cmd,stdout=subprocess.PIPE,universal_newlines=True)asproc:
87+
withsubprocess.Popen(cmd,stdout=subprocess.PIPE,universal_newlines=True,encoding=get_encoding())asproc:
7788
lines=proc.stdout.readlines()
7889
forlineinlines:
7990
words=line.split()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp