Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utf8 support #468

Merged
merged 23 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ test_script:
$filename = $_.filename
Update-AppveyorTest -Name $testname -Framework "xmake-test" -FileName $filename -Outcome Running
$time = Measure-Command {
$results = xmake lua --verbose --diagnosis runner.lua $_.fullname
xmake lua --verbose --diagnosis runner.lua $_.fullname >stdout_file 2>stderr_file
$outcome = if ($?) { "Passed" } else { $all_success = $false; "Failed" }
$stdout = [string]::Join("`n", $results)
}
Update-AppveyorTest -Name $testname -Framework "xmake-test" -FileName $filename -Outcome $outcome -Duration $time.TotalMilliseconds -StdOut $stdout
Update-AppveyorTest -Name $testname -Framework "xmake-test" -FileName $filename -Outcome $outcome -Duration $time.TotalMilliseconds -StdOut (Get-Content -Raw stdout_file) -StdErr (Get-Content -Raw stderr_file)
}
- ps: Pop-Location
- ps: if ($all_success) { Write-Host "All tests passed!" } else { Write-Error "Some tests failed!" }
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## master (unreleased)

### New features

* Add protobuf c/c++ rules
* [#468](https://github.com/xmake-io/xmake/pull/468): Add utf-8 support for windows

## v2.2.7

### New features
Expand Down Expand Up @@ -603,6 +608,11 @@

## master (开发中)

### 新特性

* 添加protobuf c/c++构建规则
* [#468](https://github.com/xmake-io/xmake/pull/468): 添加对 Windows 的 UTF-8 支持

## v2.2.7

### 新特性
Expand Down
115 changes: 115 additions & 0 deletions core/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
RawStringFormats:
- Delimiter: pb
Language: TextProto
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...

4 changes: 2 additions & 2 deletions core/src/demo/xmake.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
*/
#include "xmake/xmake.h"

/* //////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -12,7 +12,7 @@ tb_int_t main(tb_int_t argc, tb_char_t** argv)
tb_int_t ok = -1;

// init xmake
if (xm_init())
if (xm_init())
{
// init machine
xm_machine_ref_t machine = xm_machine_init();
Expand Down
6 changes: 3 additions & 3 deletions core/src/demo/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ target("demo")
-- add deps
add_deps("xmake")

-- make as a binary
-- make as a binary
set_kind("binary")

-- set basename of target file
Expand All @@ -28,8 +28,8 @@ target("demo")
end

-- add links
if is_plat("windows") then
add_links("ws2_32", "advapi32")
if is_plat("windows") then
add_links("ws2_32", "advapi32", "shell32")
elseif is_plat("android") then
add_links("m", "c")
elseif is_plat("macosx") then
Expand Down
1 change: 1 addition & 0 deletions core/src/tbox/inc/linux/tbox.config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define _REENTRANT 1
#define TB_CONFIG_SMALL 1
#define TB_CONFIG_TYPE_HAVE_FLOAT 1
#define TB_CONFIG_FORCE_UTF8 1
#define TB_CONFIG_MODULE_HAVE_HASH 1
#define TB_CONFIG_LIBC_HAVE_MEMCPY 1
#define TB_CONFIG_LIBC_HAVE_MEMSET 1
Expand Down
1 change: 1 addition & 0 deletions core/src/tbox/inc/macosx/tbox.config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define _REENTRANT 1
#define TB_CONFIG_SMALL 1
#define TB_CONFIG_TYPE_HAVE_FLOAT 1
#define TB_CONFIG_FORCE_UTF8 1
#define TB_CONFIG_MODULE_HAVE_HASH 1
#define TB_CONFIG_LIBC_HAVE_MEMCPY 1
#define TB_CONFIG_LIBC_HAVE_MEMSET 1
Expand Down
1 change: 1 addition & 0 deletions core/src/tbox/inc/windows/tbox.config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define _REENTRANT 1
#define TB_CONFIG_SMALL 1
#define TB_CONFIG_TYPE_HAVE_FLOAT 1
#define TB_CONFIG_FORCE_UTF8 1
#define TB_CONFIG_MODULE_HAVE_HASH 1
#define TB_CONFIG_LIBC_HAVE_MEMCPY 1
#define TB_CONFIG_LIBC_HAVE_MEMSET 1
Expand Down
2 changes: 1 addition & 1 deletion core/src/tbox/tbox
Submodule tbox updated 38 files
+1 −1 src/demo/demo.c
+1 −1 src/demo/demo.h
+14 −1 src/demo/libc/mbstowcs.c
+13 −1 src/demo/libc/wcstombs.c
+0 −14 src/demo/platform/processor.c
+50 −0 src/demo/platform/sched.c
+75 −15 src/demo/platform/thread.c
+2 −0 src/demo/xmake.lua
+1 −0 src/tbox/charset/charset.h
+1 −0 src/tbox/charset/ucs2.c
+1 −1 src/tbox/charset/ucs4.c
+5 −4 src/tbox/charset/utf32.c
+11 −0 src/tbox/libc/stdio/vsnprintf.c
+11 −0 src/tbox/libc/stdio/vswprintf.c
+46 −21 src/tbox/libc/stdlib/mbstowcs.c
+70 −0 src/tbox/libc/stdlib/setlocale.h
+44 −17 src/tbox/libc/stdlib/wcstombs.c
+37 −0 src/tbox/platform/mach/processor.m
+177 −0 src/tbox/platform/mach/sched_affinity.c
+73 −0 src/tbox/platform/mach/thread_affinity.c
+0 −3 src/tbox/platform/posix/processor.c
+68 −0 src/tbox/platform/posix/sched_affinity.c
+1 −1 src/tbox/platform/posix/sched_yield.c
+11 −0 src/tbox/platform/posix/thread.c
+75 −0 src/tbox/platform/posix/thread_affinity.c
+1 −1 src/tbox/platform/processor.c
+28 −2 src/tbox/platform/sched.c
+192 −2 src/tbox/platform/sched.h
+40 −8 src/tbox/platform/thread.c
+19 −0 src/tbox/platform/thread.h
+26 −7 src/tbox/platform/windows/print.c
+40 −0 src/tbox/platform/windows/sched_affinity.c
+1 −1 src/tbox/platform/windows/sched_yield.c
+11 −0 src/tbox/platform/windows/thread.c
+62 −0 src/tbox/platform/windows/thread_affinity.c
+3 −0 src/tbox/tbox.config.h.in
+4 −4 src/tbox/xmake.lua
+18 −3 src/xmake.lua
4 changes: 2 additions & 2 deletions core/src/tbox/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
includes("tbox")

-- enable hash, charset modules
for _, name in ipairs({"hash", "charset"}) do
-- enable hash, charset, utf8 modules
for _, name in ipairs({ "hash", "charset", "force-utf8" }) do
option(name)
set_default(true)
after_check(function (option)
Expand Down
129 changes: 129 additions & 0 deletions core/src/xmake/io/file.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*!A cross-platform build utility based on Lua
*
* 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.
*
* Copyright (C) 2015 - 2019, TBOOX Open Source Group.
*
* @author OpportunityLiu
* @file file.h
*
*/
#ifndef XM_IO_FILE_H
#define XM_IO_FILE_H

/* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "prefix.h"

/* //////////////////////////////////////////////////////////////////////////////////////
* types
*/
typedef enum __xm_io_file_type_e
OpportunityLiu marked this conversation as resolved.
Show resolved Hide resolved
{
XM_IO_FILE_TYPE_FILE = 0, //!< disk file

XM_IO_FILE_TYPE_STDIN = 1,
XM_IO_FILE_TYPE_STDOUT = 2,
XM_IO_FILE_TYPE_STDERR = 3,

XM_IO_FILE_FLAG_TTY = 0x10, //!< mark tty std stream
} xm_io_file_type_e;

// use negetive numbers for this enum, its a extension for tb_charset_type_e
// before adding new values, make sure they have not conflicts with values in tb_charset_type_e
typedef enum __xm_io_file_encoding_e
{
XM_IO_FILE_ENCODING_BINARY = -1,
XM_IO_FILE_ENCODING_UNKNOWN = -2,
#ifdef TB_CONFIG_OS_WINDOWS
XM_IO_FILE_ENCODING_ANSI = -3,
#endif
OpportunityLiu marked this conversation as resolved.
Show resolved Hide resolved
} xm_io_file_encoding_e;

typedef struct __xm_io_file
{
union
{
tb_file_ref_t file_ref; // valid if type == XM_IO_FILE_TYPE_FILE
FILE* std_ref; // valid otherwise
};

tb_size_t mode; // tb_file_mode_t
tb_size_t type; // xm_io_file_type_e
tb_size_t encoding; // value of xm_io_file_encoding_e or tb_charset_type_e
tb_char_t name[64];
tb_char_t const* path;
} xm_io_file;

/* //////////////////////////////////////////////////////////////////////////////////////
* macros
*/
#define xm_io_file_is_file(fileref) (fileref->type == XM_IO_FILE_TYPE_FILE)
#define xm_io_file_is_std(fileref) (fileref->type != XM_IO_FILE_TYPE_FILE)

#define xm_io_file_is_closed_file(fileref) (fileref->type == XM_IO_FILE_TYPE_FILE && !(fileref->file_ref))
#define xm_io_file_is_closed_std(fileref) (fileref->type != XM_IO_FILE_TYPE_FILE && !(fileref->file_ref))

#define xm_io_file_is_tty(fileref) (!!(fileref->type & XM_IO_FILE_FLAG_TTY))
#define xm_io_file_is_closed(fileref) (xm_io_file_is_closed_file(fileref) || xm_io_file_is_closed_std(fileref))

#define xm_io_file_udata "XM_IO_FILE*"

#define xm_io_file_success() \
do \
{ \
return 1; \
} while (0)

#define xm_io_file_error(lua, file, reason) \
do \
{ \
lua_pushnil(lua); \
lua_pushfstring(lua, "error: %s (%s)", reason, file->name); \
return 2; \
} while (0)

#define xm_io_file_error_closed(lua) \
do \
{ \
lua_pushnil(lua); \
lua_pushliteral(lua, "error: file has been closed"); \
return 2; \
} while (0)

/* //////////////////////////////////////////////////////////////////////////////////////
* interfaces
*/
static inline xm_io_file* xm_io_newfile(lua_State* lua)
{
tb_assert_and_check_return_val(lua, tb_null);

xm_io_file* file = (xm_io_file*)lua_newuserdata(lua, sizeof(xm_io_file));
OpportunityLiu marked this conversation as resolved.
Show resolved Hide resolved
tb_assert(file);
luaL_getmetatable(lua, xm_io_file_udata);
lua_setmetatable(lua, -2);
tb_memset(file, 0, sizeof(xm_io_file));
return file;
}

static inline xm_io_file* xm_io_getfile(lua_State* lua)
{
tb_assert_and_check_return_val(lua, tb_null);

xm_io_file* file = (xm_io_file*)luaL_checkudata(lua, 1, xm_io_file_udata);
tb_assert(file);
return file;
}

#endif
Loading