d2d30df420
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 luoyonggang@gmail.com
138 lines
3.7 KiB
C
138 lines
3.7 KiB
C
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "jerryscript-port.h"
|
|
|
|
#if defined(__GLIBC__) || defined(_WIN32)
|
|
#include <sys/stat.h>
|
|
|
|
#ifndef S_ISDIR
|
|
#define S_ISDIR(mode) (((mode) &S_IFMT) == S_IFDIR)
|
|
#endif /* !defined(S_ISDIR) */
|
|
#endif /* __GLIBC__ */
|
|
|
|
/**
|
|
* Determines the size of the given file.
|
|
* @return size of the file
|
|
*/
|
|
static jerry_size_t
|
|
jerry_port_get_file_size (FILE *file_p) /**< opened file */
|
|
{
|
|
fseek (file_p, 0, SEEK_END);
|
|
long size = ftell (file_p);
|
|
fseek (file_p, 0, SEEK_SET);
|
|
|
|
return (jerry_size_t) size;
|
|
} /* jerry_port_get_file_size */
|
|
|
|
jerry_char_t *JERRY_ATTR_WEAK
|
|
jerry_port_source_read (const char *file_name_p, jerry_size_t *out_size_p)
|
|
{
|
|
/* TODO(dbatyai): Temporary workaround for nuttx target
|
|
* The nuttx target builds and copies the jerryscript libraries as a separate build step, which causes linking issues
|
|
* later due to different libc libraries. It should incorporate the amalgam sources into the main nuttx build so that
|
|
* the correct libraries are used, then this guard should be removed from here and also from the includes. */
|
|
#if defined(__GLIBC__) || defined(_WIN32)
|
|
struct stat stat_buffer;
|
|
if (stat (file_name_p, &stat_buffer) == -1 || S_ISDIR (stat_buffer.st_mode))
|
|
{
|
|
return NULL;
|
|
}
|
|
#endif /* __GLIBC__ */
|
|
|
|
FILE *file_p = fopen (file_name_p, "rb");
|
|
|
|
if (file_p == NULL)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
jerry_size_t file_size = jerry_port_get_file_size (file_p);
|
|
jerry_char_t *buffer_p = (jerry_char_t *) malloc (file_size);
|
|
|
|
if (buffer_p == NULL)
|
|
{
|
|
fclose (file_p);
|
|
return NULL;
|
|
}
|
|
|
|
size_t bytes_read = fread (buffer_p, 1u, file_size, file_p);
|
|
|
|
if (bytes_read != file_size)
|
|
{
|
|
fclose (file_p);
|
|
free (buffer_p);
|
|
return NULL;
|
|
}
|
|
|
|
fclose (file_p);
|
|
*out_size_p = (jerry_size_t) bytes_read;
|
|
|
|
return buffer_p;
|
|
} /* jerry_port_source_read */
|
|
|
|
void JERRY_ATTR_WEAK
|
|
jerry_port_source_free (uint8_t *buffer_p)
|
|
{
|
|
free (buffer_p);
|
|
} /* jerry_port_source_free */
|
|
|
|
/**
|
|
* These functions provide generic implementation for paths and are only enabled when the compiler support weak symbols,
|
|
* and we are not building for a platform that has platform specific versions.
|
|
*/
|
|
#if !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32))
|
|
|
|
jerry_char_t *JERRY_ATTR_WEAK
|
|
jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size)
|
|
{
|
|
jerry_char_t *buffer_p = (jerry_char_t *) malloc (path_size + 1);
|
|
|
|
if (buffer_p == NULL)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
/* Also copy terminating zero byte. */
|
|
memcpy (buffer_p, path_p, path_size + 1);
|
|
|
|
return buffer_p;
|
|
} /* jerry_port_path_normalize */
|
|
|
|
void JERRY_ATTR_WEAK
|
|
jerry_port_path_free (jerry_char_t *path_p)
|
|
{
|
|
free (path_p);
|
|
} /* jerry_port_path_free */
|
|
|
|
jerry_size_t JERRY_ATTR_WEAK
|
|
jerry_port_path_base (const jerry_char_t *path_p)
|
|
{
|
|
const jerry_char_t *basename_p = (jerry_char_t *) strrchr ((char *) path_p, '/') + 1;
|
|
|
|
if (basename_p == NULL)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return (jerry_size_t) (basename_p - path_p);
|
|
} /* jerry_port_path_base */
|
|
|
|
#endif /* !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32)) */
|