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

Commit8c33dab

Browse files
author
Anton Pogonets
committed
Make tests compilable on macos
1 parent11e1a2b commit8c33dab

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
3+
from __future__importprint_function
4+
5+
importos
6+
importsubprocess
7+
importjson
8+
importglob
9+
importplatform
10+
11+
deftraverse(root_node,func):
12+
def_traverse(node,func,is_root=False):
13+
children=node["dependencies"]
14+
forsub_nodeinchildren:
15+
_traverse(sub_node,func)
16+
17+
ifnotis_root:
18+
func(node["path"])
19+
20+
_traverse(root_node,func,True)
21+
22+
defcopytree(src,dst,symlinks=False,ignore=None):
23+
print(subprocess.check_output(["rsync","-r"]+glob.glob(src)+ [dst]))
24+
25+
26+
defcopy_prebuilt(src,dst):
27+
copytree(os.path.join(src,"libs","*"),dst)
28+
copytree(os.path.join(src,"include","*"),dst)
29+
30+
31+
print(subprocess.check_output(['swift','package','resolve']))
32+
33+
json_output=subprocess.check_output(["swift","package","show-dependencies","--format","json"])
34+
root_node=json.loads(json_output)
35+
36+
root_path=root_node["path"]
37+
38+
ifplatform.system()=="Darwin":
39+
target="x86_64-apple-macosx10.10"
40+
else:
41+
target="x86_64-unknown-linux"
42+
43+
defcopy_prebuilt_task(module):
44+
dst=os.path.join(root_path,".build",target,"debug")
45+
46+
ifnotos.path.exists(dst):
47+
os.makedirs(dst)
48+
49+
copy_prebuilt(module,dst)
50+
51+
52+
traverse(root_node,copy_prebuilt_task)

‎src/main/scripts/create_scripts.sh

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77

88
SWIFT_INSTALL="$(dirname$PWD)"
9+
SRC_SCRIPTS_DIR="$(realpath$(dirname$0))"
910
ARCH=`uname`
1011

1112
SCRIPTS=~/.gradle/scripts
@@ -117,7 +118,8 @@ SWIFT_INSTALL="$SWIFT_INSTALL"
117118
export PATH="\$SWIFT_INSTALL/usr/bin:\$PATH"
118119
export SWIFT_EXEC=~/.gradle/scripts/swiftc-android.sh
119120
120-
swift build
121+
~/.gradle/scripts/collect-dependencies.py
122+
swift build "\$@"
121123
122124
SCRIPT
123125

@@ -127,6 +129,8 @@ cat <<SCRIPT >swiftc-android.sh &&
127129
# Substitutes in for swiftc to compile package and build Android sources
128130
#
129131
132+
PLATFORM=\$(uname)
133+
130134
SWIFT_INSTALL="$SWIFT_INSTALL"
131135
export PATH="\$SWIFT_INSTALL/usr/$ARCH:\$SWIFT_INSTALL/usr/bin:\$PATH"
132136
@@ -137,9 +141,32 @@ fi
137141
138142
ARGS=\$(echo "\$*" | sed -E "s@-target [^[:space:]]+ -sdk /[^[:space:]]* (-F /[^[:space:]]* )?@@")
139143
140-
if [[ "\$*" =~ " -emit-executable " ]]; then
141-
LINKER_ARGS="-Xlinker -shared -Xlinker -export-dynamic -tools-directory\$SWIFT_INSTALL/usr/$ARCH"
142-
fi
144+
if [[\$PLATFORM == "Darwin" ]]; then
145+
# xctest
146+
if [[ "\$*" =~ "-Xlinker -bundle" ]]; then
147+
xctest_bundle=\$(echo\$ARGS | grep -o\$(pwd)'[^[:space:]]*xctest')
148+
rm -rf\$xctest_bundle
149+
150+
modulemaps=\$(find .build/checkouts -name '*.modulemap' | sed 's@^@-I @' | sed 's@/module.modulemap\$@@')
151+
152+
build_dir=\$(echo "\$ARGS" | grep -o '\-L '\$(pwd)'/.build/[^[:space:]]*' | sed -E "s@-L @@")
153+
154+
ARGS=\$(echo "\$ARGS" | sed -E "s@-Xlinker -bundle@-emit-executable@")
155+
ARGS=\$(echo "\$ARGS" | sed -E "s@xctest[^[:space:]]*PackageTests@xctest@")
156+
157+
ARGS="\$ARGS\$modulemaps -I\$build_dir Tests/LinuxMain.swift"
158+
fi
159+
160+
# .dylib -> .so
161+
if [[ "\$ARGS" =~ "-emit-library" ]]; then
162+
ARGS=\$(echo "\$ARGS" | sed -E "s@\.dylib@\.so@")
163+
fi
164+
fi
165+
166+
# required since API21
167+
if [[ "\$ARGS" =~ "-emit-executable" ]]; then
168+
LINKER_ARGS="-Xlinker -pie"
169+
fi
143170
144171
swiftc -target armv7-none-linux-androideabi\\
145172
-sdk "\$SWIFT_INSTALL/ndk-android-21" -L "\$SWIFT_INSTALL/usr/$ARCH"\\
@@ -162,6 +189,7 @@ rm -f *Unittest*
162189
163190
SCRIPT
164191

192+
cp$SRC_SCRIPTS_DIR/collect-dependencies.py$SCRIPTS/&&
165193
chmod +x {generate-swift,swift-build,swiftc-android,copy-libraries}.sh&&
166194
echo Created:$SCRIPTS/{generate-swift,swift-build,swiftc-android,copy-libraries}.sh&&
167195
echo

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp