Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
9b052ace
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9b052ace
编写于
9月 08, 2018
作者:
B
Bert Belder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tools/setup: replace generated args.gn unless handcrafted
上级
30b268dd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
125 addition
and
16 deletion
+125
-16
tools/setup.py
tools/setup.py
+62
-16
tools/setup_test.py
tools/setup_test.py
+61
-0
tools/test.py
tools/test.py
+2
-0
未找到文件。
tools/setup.py
浏览文件 @
9b052ace
...
...
@@ -2,6 +2,7 @@
import
third_party
from
util
import
run
,
root_path
,
build_path
,
build_mode
import
os
import
re
import
sys
from
distutils.spawn
import
find_executable
...
...
@@ -44,15 +45,55 @@ def write_lastchange():
# ])
def
get_gn_args
():
# If this text is found in args.gn, we assume it hasn't been hand edited.
gn_args_header
=
[
"# This file is automatically generated by tools/setup.py."
,
"# REMOVE THIS LINE to preserve any changes you make."
,
""
]
def
gn_args_are_generated
(
lines
):
for
line
in
lines
:
if
re
.
match
(
"^\s*#.*REMOVE THIS LINE"
,
line
):
return
True
return
False
def
read_gn_args
(
args_filename
):
if
not
os
.
path
.
exists
(
args_filename
):
return
(
None
,
False
)
# No content, not hand edited.
with
open
(
args_filename
)
as
f
:
lines
=
f
.
read
().
splitlines
()
args
=
[
l
.
strip
()
for
l
in
lines
if
not
re
.
match
(
"^\s*(#|$)"
,
l
)]
hand_edited
=
not
gn_args_are_generated
(
lines
)
return
(
args
,
hand_edited
)
def
write_gn_args
(
args_filename
,
args
):
assert
not
gn_args_are_generated
(
args
)
# No header -> hand crafted.
lines
=
gn_args_header
+
args
assert
gn_args_are_generated
(
lines
)
# With header -> generated.
# Ensure the directory where args.gn goes exists.
dir
=
os
.
path
.
dirname
(
args_filename
)
if
not
os
.
path
.
isdir
(
dir
):
os
.
makedirs
(
dir
)
with
open
(
args_filename
,
"w"
)
as
f
:
f
.
write
(
"
\n
"
.
join
(
lines
)
+
"
\n
"
)
def
generate_gn_args
(
mode
):
out
=
[]
if
build_mode
()
==
"release"
:
if
mode
==
"release"
:
out
+=
[
"is_official_build=true"
]
elif
build_mode
()
==
"debug"
:
elif
mode
==
"debug"
:
pass
else
:
print
"Bad mode {}. Use 'release' or 'debug' (default)"
%
build_mode
()
print
"Bad mode {}. Use 'release' or 'debug' (default)"
%
mode
sys
.
exit
(
1
)
if
"DENO_BUILD_ARGS"
in
os
.
environ
:
out
+=
os
.
environ
[
"DENO_BUILD_ARGS"
].
split
()
...
...
@@ -67,8 +108,6 @@ def get_gn_args():
tc
=
"//build_extra/toolchain/win:win_clang_x64"
out
+=
[
'custom_toolchain="%s"'
%
tc
,
'host_toolchain="%s"'
%
tc
]
print
"DENO_BUILD_ARGS:"
,
out
return
out
...
...
@@ -76,20 +115,27 @@ def get_gn_args():
def
gn_gen
(
mode
):
os
.
environ
[
"DENO_BUILD_MODE"
]
=
mode
# mkdir $build_path(). We do this so we can write args.gn before running gn gen.
if
not
os
.
path
.
isdir
(
build_path
()):
os
.
makedirs
(
build_path
())
# Rather than using gn gen --args we manually write the args.gn override file.
# Rather than using gn gen --args we write directly to the args.gn file.
# This is to avoid quoting/escaping complications when passing overrides as
# command-line arguments.
args_filename
=
os
.
path
.
join
(
build_path
(),
"args.gn"
)
if
os
.
path
.
exists
(
args_filename
):
print
"Skip writing args file: '%s' already exists."
%
args_filename
# Check if args.gn exists, and if it was auto-generated or handcrafted.
existing_gn_args
,
hand_edited
=
read_gn_args
(
args_filename
)
# If args.gn wasn't handcrafted, regenerate it.
if
hand_edited
:
print
"%s: Using gn options from hand edited '%s'."
%
(
mode
,
args_filename
)
gn_args
=
existing_gn_args
else
:
gn_args
=
get_gn_args
()
with
open
(
args_filename
,
"w+"
)
as
f
:
f
.
write
(
"
\n
"
.
join
(
gn_args
)
+
"
\n
"
)
print
"%s: Writing gn options to '%s'."
%
(
mode
,
args_filename
)
gn_args
=
generate_gn_args
(
mode
)
if
gn_args
!=
existing_gn_args
:
write_gn_args
(
args_filename
,
gn_args
)
for
line
in
gn_args
:
print
" "
+
line
run
([
third_party
.
gn_path
,
"gen"
,
build_path
()],
env
=
third_party
.
google_env
())
...
...
tools/setup_test.py
0 → 100644
浏览文件 @
9b052ace
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
import
os
from
setup
import
read_gn_args
,
write_gn_args
from
shutil
import
rmtree
from
tempfile
import
mktemp
def
read_gn_args_test
():
# Args file doesn't exist.
(
args
,
hand_edited
)
=
read_gn_args
(
"/baddir/hopefully/nonexistent/args.gn"
)
assert
args
is
None
assert
hand_edited
==
False
# Handwritten empty args file.
filename
=
mktemp
()
with
open
(
filename
,
"w"
):
pass
(
args
,
hand_edited
)
=
read_gn_args
(
filename
)
os
.
remove
(
filename
)
assert
args
==
[]
assert
hand_edited
==
True
# Handwritten non-empty args file.
expect_args
=
[
'some_number=2'
,
'another_string="ran/dom#yes"'
]
filename
=
mktemp
()
with
open
(
filename
,
"w"
)
as
f
:
f
.
write
(
"
\n
"
.
join
(
expect_args
+
[
""
,
"# A comment to be ignored"
]))
(
args
,
hand_edited
)
=
read_gn_args
(
filename
)
os
.
remove
(
filename
)
assert
args
==
expect_args
assert
hand_edited
==
True
def
write_gn_args_test
():
# Build a nonexistent path; write_gn_args() should call mkdir as needed.
dir
=
mktemp
()
filename
=
os
.
path
.
join
(
dir
,
"args.gn"
)
assert
not
os
.
path
.
exists
(
dir
)
assert
not
os
.
path
.
exists
(
filename
)
# Write some args.
args
=
[
'lalala=42'
,
'foo_bar_baz="lorem ipsum dolor#amet"'
]
write_gn_args
(
filename
,
args
)
# Directory and args file should now be created.
assert
os
.
path
.
isdir
(
dir
)
assert
os
.
path
.
isfile
(
filename
)
# Validate that the right contents were written.
(
check_args
,
hand_edited
)
=
read_gn_args
(
filename
)
assert
check_args
==
args
assert
hand_edited
==
False
# Clean up.
rmtree
(
dir
)
def
setup_test
():
read_gn_args_test
()
write_gn_args_test
()
if
__name__
==
'__main__'
:
setup_test
()
tools/test.py
浏览文件 @
9b052ace
...
...
@@ -4,6 +4,7 @@
import
os
import
sys
from
check_output_test
import
check_output_test
from
setup_test
import
setup_test
from
util
import
executable_suffix
,
run
,
build_path
from
unit_tests
import
unit_tests
from
util_test
import
util_test
...
...
@@ -30,6 +31,7 @@ def main(argv):
http_server
.
spawn
()
# Internal tools testing
setup_test
()
util_test
()
test_cc
=
os
.
path
.
join
(
build_dir
,
"test_cc"
+
executable_suffix
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录