Skip to content

Commit d2d30df

Browse files
authored
Revise tools scripts to be python3 compatible on win32 (#4856)
We introduce setup_stdio function to setup stdout/stderr properly. For python <-> python pipe, we always use 'utf8'/'ignore' encoding for not lost characters. For tty <-> python, we using native encoding with xmlcharrefreplace to encode, to preserve maximal information. For python <-> native program, we use naive encoding with 'ignore' to not cause error update_exclude_list with binary mode so that on win32 would not generate \r\n run-test-suite.py: Handling skiplist properly on win32 Fixes #4854 Fixes test262-harness.py complain cannot use a string pattern on a bytes-like object with running test262 with python3 For reading/writing to file, we use 'utf8' /'ignore' encoding for not lost characters. For decoding from process stdout, using native encoding with decoding error ignored for not lost data. Execute commands also ignore errors Fixes #4853 Fixes running test262-esnext failed with installed python3.9 on win32 with space in path Fixes #4852 support both / \ in --test262-test-list arg On win32. python tools/run-tests.py --test262-es2015=update --test262-test-list=built-ins/decodeURI/ python tools/run-tests.py --test262-es2015=update --test262-test-list=built-ins\decodeURI\ should be both valid, currently only --test262-test-list=built-ins\decodeURI\ are valid. Support snapshot-tests-skiplist.txt on win32 by use os.path.normpath Guard run-tests.py with timer. All run-tests.py are finished in 30 minutes in normal situation. May change the timeout by command line option Move Windows CI to github actions Define TERM colors for win32 properly flush stderr.write stdout.write On CI, the stderr are redirect to stdout, and if we don't flush stderr and stdout, The output from stderr/stdout would out of sync. `Testing new Date(-8640000000000000) and fixes date for win32` So that the CI can passed if sys.version_info.major >= 3: remove, as we do not support python2 anymore Fixes compiling warnings/errors for mingw/gcc JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent a1e4bd8 commit d2d30df

17 files changed

+188
-118
lines changed

.github/workflows/gh-actions.yml

+48
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,54 @@ jobs:
5656
- run: $RUNNER -q --jerry-tests --buildoptions=--compile-flag=-m32,--cpointer-32bit=on
5757
- run: $RUNNER -q --jerry-tests --buildoptions=--compile-flag=-m32,--cpointer-32bit=on --build-debug
5858

59+
Win_x86-64_Conformance_Tests_ESNext:
60+
runs-on: windows-latest
61+
steps:
62+
- uses: actions/checkout@v2
63+
- run: python $env:RUNNER --test262 update
64+
65+
Win_x86-64_Conformance_Tests_ESNext_Debug:
66+
runs-on: windows-latest
67+
steps:
68+
- uses: actions/checkout@v2
69+
- run: python $env:RUNNER --test262 update --build-debug
70+
71+
Win_x86-64_Tests-MINGW:
72+
runs-on: windows-latest
73+
defaults:
74+
run:
75+
shell: msys2 {0}
76+
steps:
77+
- uses: actions/checkout@v4
78+
- uses: msys2/setup-msys2@v2
79+
with:
80+
msystem: MINGW64
81+
update: true
82+
install: >-
83+
mingw-w64-x86_64-python
84+
mingw-w64-x86_64-cmake
85+
mingw-w64-x86_64-make
86+
mingw-w64-x86_64-toolchain
87+
- run: python $RUNNER -q --jerry-tests
88+
- run: python $RUNNER -q --unittests --build-config=''
89+
# FIXME: enable it with upgrade valgrind - run: python $RUNNER -q --buildoption-test
90+
91+
Win_x86-64_Tests:
92+
runs-on: windows-latest
93+
steps:
94+
- uses: actions/checkout@v2
95+
- run: python $env:RUNNER -q --jerry-tests
96+
- run: python $env:RUNNER -q --unittests
97+
- run: python $env:RUNNER -q --buildoption-test
98+
99+
Win_x86-64_Tests_Debug:
100+
runs-on: windows-latest
101+
steps:
102+
- uses: actions/checkout@v2
103+
- run: python $env:RUNNER -q --jerry-tests --build-debug
104+
- run: python $env:RUNNER -q --unittests --build-debug
105+
- run: python $env:RUNNER -q --buildoption-test --build-debug
106+
59107
OSX_x86-64_Build_Correctness_Unit_Tests:
60108
runs-on: macos-13
61109
steps:

CMakeLists.txt

+7-6
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@ set(PLATFORM "${CMAKE_SYSTEM_NAME}")
2828
string(TOUPPER "${PLATFORM}" PLATFORM)
2929

3030
# Determining compiler
31+
if(MSVC)
32+
set(USING_MSVC 1)
33+
endif()
34+
3135
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
3236
set(USING_GCC 1)
3337
endif()
3438

35-
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
39+
# Clang may support for MSVC
40+
if(NOT USING_MSVC AND CMAKE_C_COMPILER_ID MATCHES "Clang")
3641
set(USING_CLANG 1)
3742
endif()
3843

3944
if(CMAKE_C_COMPILER_ID MATCHES "TI")
4045
set(USING_TI 1)
4146
endif()
4247

43-
if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
44-
set(USING_MSVC 1)
45-
endif()
46-
4748
# Determining build type
4849
if(NOT CMAKE_BUILD_TYPE)
4950
set(CMAKE_BUILD_TYPE "MinSizeRel")
@@ -68,7 +69,7 @@ set(ENABLE_STRIP ON CACHE BOOL "Enable stripping all symbols from
6869
set(ENABLE_COMPILE_COMMANDS ON CACHE BOOL "Enable generating compile_commands.json?")
6970

7071
if(USING_MSVC)
71-
set(ENABLE_STATIC_CRT OFF CACHE BOOL "Enable MSVC static CRT?")
72+
set(ENABLE_STATIC_CRT OFF CACHE BOOL "Enable MSVC static CRT?")
7273
endif()
7374

7475
# Option overrides

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# JerryScript: JavaScript engine for the Internet of Things
33
[![License](https://img.shields.io/badge/licence-Apache%202.0-brightgreen.svg?style=flat)](LICENSE)
44
[![GitHub Actions Status](https://github.com/jerryscript-project/jerryscript/workflows/JerryScript%20CI/badge.svg)](https://github.com/jerryscript-project/jerryscript/actions)
5-
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/ct8reap35u2vooa5/branch/master?svg=true)](https://ci.appveyor.com/project/jerryscript-project/jerryscript/branch/master)
65
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fjerryscript-project%2Fjerryscript.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fjerryscript-project%2Fjerryscript?ref=badge_shield)
76
[![IRC Channel](https://img.shields.io/badge/chat-on%20freenode-brightgreen.svg)](https://kiwiirc.com/client/irc.freenode.net/#jerryscript)
87

appveyor.yml

-27
This file was deleted.

jerry-core/CMakeLists.txt

+7-7
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ set(INCLUDE_CORE_PRIVATE
123123
"${CMAKE_CURRENT_SOURCE_DIR}/parser/regexp"
124124
"${CMAKE_CURRENT_SOURCE_DIR}/vm")
125125

126+
# Third-party
127+
# Valgrind
128+
set(INCLUDE_THIRD_PARTY_VALGRIND "${CMAKE_SOURCE_DIR}/third-party/valgrind")
129+
if(JERRY_VALGRIND)
130+
set(INCLUDE_CORE_PRIVATE ${INCLUDE_CORE_PRIVATE} ${INCLUDE_THIRD_PARTY_VALGRIND})
131+
endif()
132+
126133
set(INCLUDE_CORE_PUBLIC ${INCLUDE_CORE_PUBLIC} PARENT_SCOPE) # for jerry-port
127134
set(INCLUDE_CORE_PRIVATE ${INCLUDE_CORE_PRIVATE} PARENT_SCOPE) # for tests/unit-core
128135

@@ -533,10 +540,6 @@ if(ENABLE_AMALGAM)
533540
set(INCLUDE_CORE_PRIVATE PARENT_SCOPE)
534541
endif()
535542

536-
# Third-party
537-
# Valgrind
538-
set(INCLUDE_THIRD_PARTY_VALGRIND "${CMAKE_SOURCE_DIR}/third-party/valgrind")
539-
540543
# build mode specific compile/link flags
541544
set(DEFINES_JERRY ${DEFINES_JERRY} $<$<NOT:$<CONFIG:Debug>>:JERRY_NDEBUG>)
542545

@@ -641,9 +644,6 @@ jerry_add_define01(JERRY_SYSTEM_ALLOCATOR)
641644

642645
# Valgrind
643646
jerry_add_define01(JERRY_VALGRIND)
644-
if(JERRY_VALGRIND)
645-
set(INCLUDE_CORE_PRIVATE ${INCLUDE_CORE_PRIVATE} ${INCLUDE_THIRD_PARTY_VALGRIND})
646-
endif()
647647

648648
# Enable VM execution stop callback
649649
jerry_add_define01(JERRY_VM_HALT)

jerry-core/ecma/base/ecma-helpers-string.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,8 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /**< ecma-st
15991599
const ecma_string_t *string2_p) /**< ecma-string */
16001600
{
16011601
const lit_utf8_byte_t *utf8_string1_p, *utf8_string2_p;
1602-
lit_utf8_size_t string1_size_and_length[2], string2_size_and_length[2];
1602+
lit_utf8_size_t string1_size_and_length[2] = { 0 };
1603+
lit_utf8_size_t string2_size_and_length[2] = { 0 };
16031604

16041605
utf8_string1_p = ecma_compare_get_string_chars (string1_p, string1_size_and_length);
16051606
utf8_string2_p = ecma_compare_get_string_chars (string2_p, string2_size_and_length);

jerry-core/include/jerryscript-compiler.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ JERRY_C_API_BEGIN
3030
* @{
3131
*/
3232

33+
/*
34+
* Compiler-specific macros relevant for Win32.
35+
*/
36+
#ifdef _WIN32
37+
/**
38+
* Both MINGW/MSVC do not support for declare a function a weak symbol.
39+
*/
40+
#define JERRY_ATTR_WEAK
41+
#endif /* _WIN32 */
42+
3343
#ifdef __GNUC__
3444

3545
/*
@@ -45,9 +55,10 @@ JERRY_C_API_BEGIN
4555
#define JERRY_ATTR_NORETURN __attribute__ ((noreturn))
4656
#define JERRY_ATTR_PURE __attribute__ ((pure))
4757
#define JERRY_ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
48-
#define JERRY_ATTR_WEAK __attribute__ ((weak))
4958

50-
#define JERRY_WEAK_SYMBOL_SUPPORT
59+
#ifndef JERRY_ATTR_WEAK
60+
#define JERRY_ATTR_WEAK __attribute__ ((weak))
61+
#endif /* !JERRY_ATTR_WEAK*/
5162

5263
#ifndef JERRY_LIKELY
5364
#define JERRY_LIKELY(x) __builtin_expect (!!(x), 1)

jerry-port/common/jerry-port-fs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jerry_port_source_free (uint8_t *buffer_p)
9797
* These functions provide generic implementation for paths and are only enabled when the compiler support weak symbols,
9898
* and we are not building for a platform that has platform specific versions.
9999
*/
100-
#if defined(JERRY_WEAK_SYMBOL_SUPPORT) && !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32))
100+
#if !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32))
101101

102102
jerry_char_t *JERRY_ATTR_WEAK
103103
jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size)
@@ -134,4 +134,4 @@ jerry_port_path_base (const jerry_char_t *path_p)
134134
return (jerry_size_t) (basename_p - path_p);
135135
} /* jerry_port_path_base */
136136

137-
#endif /* defined(JERRY_WEAK_SYMBOL_SUPPORT) && !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32)) */
137+
#endif /* !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32)) */

jerry-port/win/jerry-port-win-date.c

+17-20
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include <winbase.h>
2424
#include <winnt.h>
2525

26-
#define UNIX_EPOCH_IN_TICKS 116444736000000000ull /* difference between 1970 and 1601 */
27-
#define TICKS_PER_MS 10000ull /* 1 tick is 100 nanoseconds */
26+
#define UNIX_EPOCH_IN_TICKS 116444736000000000LL /* difference between 1970 and 1601 */
27+
#define TICKS_PER_MS 10000LL /* 1 tick is 100 nanoseconds */
2828

2929
/*
3030
* If you take the limit of SYSTEMTIME (last millisecond in 30827) then you end up with
@@ -44,15 +44,9 @@
4444
* https://support.microsoft.com/en-us/help/167296/how-to-convert-a-unix-time-t-to-a-win32-filetime-or-systemtime
4545
*/
4646
static void
47-
unix_time_to_filetime (double t, LPFILETIME ft_p)
47+
unix_time_to_filetime (LONGLONG t, LPFILETIME ft_p)
4848
{
49-
LONGLONG ll = (LONGLONG) t * TICKS_PER_MS + UNIX_EPOCH_IN_TICKS;
50-
51-
/* FILETIME values before the epoch are invalid. */
52-
if (ll < 0)
53-
{
54-
ll = 0;
55-
}
49+
LONGLONG ll = t * TICKS_PER_MS + UNIX_EPOCH_IN_TICKS;
5650

5751
ft_p->dwLowDateTime = (DWORD) ll;
5852
ft_p->dwHighDateTime = (DWORD) (ll >> 32);
@@ -63,13 +57,15 @@ unix_time_to_filetime (double t, LPFILETIME ft_p)
6357
*
6458
* @return unix time
6559
*/
66-
static double
60+
static LONGLONG
6761
filetime_to_unix_time (LPFILETIME ft_p)
6862
{
6963
ULARGE_INTEGER date;
64+
LONGLONG ll;
7065
date.HighPart = ft_p->dwHighDateTime;
7166
date.LowPart = ft_p->dwLowDateTime;
72-
return (double) (((LONGLONG) date.QuadPart - UNIX_EPOCH_IN_TICKS) / TICKS_PER_MS);
67+
ll = (LONGLONG) date.QuadPart - UNIX_EPOCH_IN_TICKS;
68+
return ll / TICKS_PER_MS;
7369
} /* filetime_to_unix_time */
7470

7571
int32_t
@@ -79,6 +75,7 @@ jerry_port_local_tza (double unix_ms)
7975
FILETIME local;
8076
SYSTEMTIME utc_sys;
8177
SYSTEMTIME local_sys;
78+
LONGLONG t = (LONGLONG) (unix_ms);
8279

8380
/*
8481
* If the time is earlier than the date 1601-01-02, then always using date 1601-01-02 to
@@ -87,23 +84,23 @@ jerry_port_local_tza (double unix_ms)
8784
* after converting between local time and utc time, the time may be earlier than 1601-01-01
8885
* in UTC time, that exceeds the FILETIME representation range.
8986
*/
90-
if (unix_ms < (double) UNIX_EPOCH_DATE_1601_01_02)
87+
if (t < UNIX_EPOCH_DATE_1601_01_02)
9188
{
92-
unix_ms = (double) UNIX_EPOCH_DATE_1601_01_02;
89+
t = UNIX_EPOCH_DATE_1601_01_02;
9390
}
9491

9592
/* Like above, do not use the last supported day */
96-
if (unix_ms > (double) UNIX_EPOCH_DATE_30827_12_29)
93+
if (t > UNIX_EPOCH_DATE_30827_12_29)
9794
{
98-
unix_ms = (double) UNIX_EPOCH_DATE_30827_12_29;
95+
t = UNIX_EPOCH_DATE_30827_12_29;
9996
}
100-
unix_time_to_filetime (unix_ms, &utc);
97+
unix_time_to_filetime (t, &utc);
10198

10299
if (FileTimeToSystemTime (&utc, &utc_sys) && SystemTimeToTzSpecificLocalTime (NULL, &utc_sys, &local_sys)
103100
&& SystemTimeToFileTime (&local_sys, &local))
104101
{
105-
double unix_local = filetime_to_unix_time (&local);
106-
return (int32_t) (unix_local - unix_ms);
102+
LONGLONG unix_local = filetime_to_unix_time (&local);
103+
return (int32_t) (unix_local - t);
107104
}
108105

109106
return 0;
@@ -114,7 +111,7 @@ jerry_port_current_time (void)
114111
{
115112
FILETIME ft;
116113
GetSystemTimeAsFileTime (&ft);
117-
return filetime_to_unix_time (&ft);
114+
return (double) filetime_to_unix_time (&ft);
118115
} /* jerry_port_current_time */
119116

120117
#endif /* defined(_WIN32) */

jerry-port/win/jerry-port-win-fs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size)
2525
{
2626
(void) path_size;
2727

28-
return (jerry_char_t *) _fullpath (NULL, path_p, _MAX_PATH);
28+
return (jerry_char_t *) _fullpath (NULL, (const char *) path_p, _MAX_PATH);
2929
} /* jerry_port_path_normalize */
3030

3131
void

tests/jerry/date-getters.js

+8
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,16 @@ assert (new Date(-1, -1, -1, -1, -1, -1, -1, -1).getMilliseconds() === 999);
110110
assert (isNaN(new Date(20000000, 0).getFullYear()));
111111
assert (new Date(0, 0).getFullYear() === 1900);
112112
assert (new Date(1.2, 0).getFullYear() === 1901);
113+
114+
/* 7. test case */
115+
/* A Number can exactly represent all integers from -9,007,199,254,740,992 to 9,007,199,254,740,992 (21.1.2.8 and 21.1.2.6).
116+
A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds. */
113117
assert((new Date(8640000000000000).getFullYear()) == 275760);
114118
assert(isNaN(new Date(8640000000000001).getFullYear()));
119+
assert((new Date(-8640000000000000).getFullYear()) == -271821);
120+
assert(isNaN(new Date(-8640000000000001).getFullYear()));
121+
122+
/* 8. test case */
115123
assert((new Date(-271821, 3, 21).getFullYear()) == -271821);
116124
assert(isNaN(new Date(1970, 0, -100000000).getFullYear()));
117125
assert(new Date(1970, 0, -100000000 + 1).getFullYear() == -271821);

0 commit comments

Comments
 (0)