Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
958bfdf0
U
uni-app
项目概览
DCloud
/
uni-app
14 天 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
958bfdf0
编写于
11月 16, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): compiler
上级
1e5c4850
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
134 addition
and
58 deletion
+134
-58
packages/uni-uts-v1/__tests__/compiler.spec.ts
packages/uni-uts-v1/__tests__/compiler.spec.ts
+42
-0
packages/uni-uts-v1/__tests__/examples/demo/uni_modules/test-uts/utssdk/app-android/index.uts
...es/demo/uni_modules/test-uts/utssdk/app-android/index.uts
+1
-0
packages/uni-uts-v1/__tests__/examples/demo/uni_modules/test-uts/utssdk/app-ios/index.uts
...amples/demo/uni_modules/test-uts/utssdk/app-ios/index.uts
+1
-0
packages/uni-uts-v1/__tests__/examples/demo/unpackage/dist/dev/app-plus/uni_modules/test-uts/utssdk/app-android/index.kt
...app-plus/uni_modules/test-uts/utssdk/app-android/index.kt
+7
-0
packages/uni-uts-v1/__tests__/examples/demo/unpackage/dist/dev/app-plus/uni_modules/test-uts/utssdk/app-ios/index.swift
.../app-plus/uni_modules/test-uts/utssdk/app-ios/index.swift
+9
-0
packages/uni-uts-v1/src/index.ts
packages/uni-uts-v1/src/index.ts
+3
-0
packages/uni-uts-v1/src/kotlin.ts
packages/uni-uts-v1/src/kotlin.ts
+32
-29
packages/uni-uts-v1/src/swift.ts
packages/uni-uts-v1/src/swift.ts
+30
-28
packages/uni-uts-v1/src/utils.ts
packages/uni-uts-v1/src/utils.ts
+9
-1
packages/uts-darwin-arm64/uts.darwin-arm64.node
packages/uts-darwin-arm64/uts.darwin-arm64.node
+0
-0
packages/uts-darwin-x64/uts.darwin-x64.node
packages/uts-darwin-x64/uts.darwin-x64.node
+0
-0
packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node
packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node
+0
-0
packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node
packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node
+0
-0
未找到文件。
packages/uni-uts-v1/__tests__/compiler.spec.ts
0 → 100644
浏览文件 @
958bfdf0
import
{
existsSync
,
rmSync
}
from
'
fs
'
import
{
resolve
}
from
'
path
'
import
{
toKotlin
,
toSwift
}
from
'
../src/index
'
const
inputDir
=
resolve
(
__dirname
,
'
examples/demo
'
)
const
outputDir
=
resolve
(
__dirname
,
'
examples/demo/unpackage/dist/dev/app-plus
'
)
const
pluginDir
=
resolve
(
inputDir
,
'
uni_modules/test-uts
'
)
const
outputPluginDir
=
resolve
(
outputDir
,
'
uni_modules/test-uts
'
)
describe
(
'
compiler
'
,
()
=>
{
test
(
'
toKotlin
'
,
async
()
=>
{
const
relativeFile
=
'
utssdk/app-android/index
'
const
kotlinFile
=
resolve
(
outputPluginDir
,
relativeFile
+
'
.kt
'
)
if
(
existsSync
(
kotlinFile
))
{
rmSync
(
kotlinFile
)
}
await
toKotlin
(
resolve
(
pluginDir
,
relativeFile
+
'
.uts
'
),
{
inputDir
,
outputDir
,
sourceMap
:
false
,
})
expect
(
existsSync
(
kotlinFile
)).
toBeTruthy
()
})
test
(
'
toSwift
'
,
async
()
=>
{
const
relativeFile
=
'
utssdk/app-ios/index
'
const
swiftFile
=
resolve
(
outputPluginDir
,
relativeFile
+
'
.swift
'
)
if
(
existsSync
(
swiftFile
))
{
rmSync
(
swiftFile
)
}
await
toSwift
(
resolve
(
pluginDir
,
relativeFile
+
'
.uts
'
),
{
inputDir
,
outputDir
,
sourceMap
:
false
,
})
expect
(
existsSync
(
swiftFile
)).
toBeTruthy
()
})
})
packages/uni-uts-v1/__tests__/examples/demo/uni_modules/test-uts/utssdk/app-android/index.uts
0 → 100644
浏览文件 @
958bfdf0
export function test() { }
\ No newline at end of file
packages/uni-uts-v1/__tests__/examples/demo/uni_modules/test-uts/utssdk/app-ios/index.uts
0 → 100644
浏览文件 @
958bfdf0
export function test() { }
\ No newline at end of file
packages/uni-uts-v1/__tests__/examples/demo/unpackage/dist/dev/app-plus/uni_modules/test-uts/utssdk/app-android/index.kt
0 → 100644
浏览文件 @
958bfdf0
package
uts.sdk.modules.testUts;
import
kotlinx.coroutines.async;
import
kotlinx.coroutines.CoroutineScope;
import
kotlinx.coroutines.Deferred;
import
kotlinx.coroutines.Dispatchers;
import
io.dcloud.uts.*;
fun
test
()
{}
packages/uni-uts-v1/__tests__/examples/demo/unpackage/dist/dev/app-plus/uni_modules/test-uts/utssdk/app-ios/index.swift
0 → 100644
浏览文件 @
958bfdf0
import
DCUTSFoundation
;
func
test
()
{}
@objc
(
UTSSDKModulesTestUtsIndexSwift
)
@objcMembers
class
IndexSwift
:
NSObject
{
public
static
func
s_test
()
{
return
test
();
}
}
packages/uni-uts-v1/src/index.ts
浏览文件 @
958bfdf0
...
...
@@ -20,6 +20,9 @@ export const sourcemap = {
export
*
from
'
./sourceMap
'
export
{
compile
as
toKotlin
}
from
'
./kotlin
'
export
{
compile
as
toSwift
}
from
'
./swift
'
export
async
function
compile
(
module
:
string
)
{
const
pkg
=
resolvePackage
(
module
)
if
(
!
pkg
)
{
...
...
packages/uni-uts-v1/src/kotlin.ts
浏览文件 @
958bfdf0
...
...
@@ -4,6 +4,7 @@ import path from 'path'
import
AdmZip
from
'
adm-zip
'
import
{
sync
}
from
'
fast-glob
'
import
{
isArray
}
from
'
@vue/shared
'
import
type
{
UtsResult
}
from
'
@dcloudio/uts
'
import
{
isInHBuilderX
,
normalizePath
,
...
...
@@ -20,9 +21,9 @@ import {
resolvePackage
,
resolveUTSPlatformFile
,
resolveUTSSourceMapPath
,
ToKotlinOptions
,
}
from
'
./utils
'
import
{
Module
}
from
'
../types/types
'
import
{
UtsResult
}
from
'
@dcloudio/uts
'
interface
KotlinCompilerServer
extends
CompilerServer
{
getKotlincHome
():
string
...
...
@@ -63,10 +64,12 @@ export async function runKotlinProd(filename: string) {
if
(
filename
.
includes
(
'
app-ios
'
))
{
return
}
await
compile
(
filename
)
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
outputDir
=
process
.
env
.
UNI_OUTPUT_DIR
await
compile
(
filename
,
{
inputDir
,
outputDir
,
sourceMap
:
true
})
genUTSPlatformResource
(
filename
,
{
inputDir
:
process
.
env
.
UNI_INPUT_DIR
,
outputDir
:
process
.
env
.
UNI_OUTPUT_DIR
,
inputDir
,
outputDir
,
platform
:
'
app-android
'
,
extname
:
'
.kt
'
,
})
...
...
@@ -84,14 +87,20 @@ export async function runKotlinDev(
if
(
filename
.
includes
(
'
app-ios
'
))
{
return
}
const
result
=
(
await
compile
(
filename
))
as
RunKotlinDevResult
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
outputDir
=
process
.
env
.
UNI_OUTPUT_DIR
const
result
=
(
await
compile
(
filename
,
{
inputDir
,
outputDir
,
sourceMap
:
true
,
}))
as
RunKotlinDevResult
result
.
type
=
'
kotlin
'
result
.
changed
=
[]
const
kotlinFile
=
resolveUTSPlatformFile
(
filename
,
{
inputDir
:
process
.
env
.
UNI_INPUT_DIR
,
outputDir
:
process
.
env
.
UNI_OUTPUT_DIR
,
inputDir
,
outputDir
,
platform
:
'
app-android
'
,
extname
:
'
.kt
'
,
})
...
...
@@ -130,13 +139,10 @@ export async function runKotlinDev(
.
concat
(
resDeps
)
),
d8
:
resolveD8Args
(
jarFile
),
sourceRoot
:
process
.
env
.
UNI_INPUT_DIR
,
sourceMapPath
:
resolveSourceMapFile
(
process
.
env
.
UNI_OUTPUT_DIR
,
kotlinFile
),
sourceRoot
:
inputDir
,
sourceMapPath
:
resolveSourceMapFile
(
outputDir
,
kotlinFile
),
}
const
res
=
await
compile
(
options
,
process
.
env
.
UNI_INPUT_DIR
)
const
res
=
await
compile
(
options
,
inputDir
)
// console.log('dex compile time: ' + (Date.now() - time) + 'ms')
if
(
res
)
{
try
{
...
...
@@ -146,9 +152,7 @@ export async function runKotlinDev(
}
catch
(
e
)
{}
const
dexFile
=
resolveDexFile
(
jarFile
)
if
(
fs
.
existsSync
(
dexFile
))
{
result
.
changed
=
[
normalizePath
(
path
.
relative
(
process
.
env
.
UNI_OUTPUT_DIR
,
dexFile
)),
]
result
.
changed
=
[
normalizePath
(
path
.
relative
(
outputDir
,
dexFile
))]
}
}
// else {
...
...
@@ -275,13 +279,11 @@ const DEFAULT_IMPORTS = [
'
io.dcloud.uts.*
'
,
]
async
function
compile
(
filename
:
string
)
{
if
(
!
process
.
env
.
UNI_HBUILDERX_PLUGINS
)
{
throw
'
process.env.UNI_HBUILDERX_PLUGINS is not found
'
}
export
async
function
compile
(
filename
:
string
,
{
inputDir
,
outputDir
,
sourceMap
}:
ToKotlinOptions
)
{
const
{
bundle
,
UtsTarget
}
=
getUtsCompiler
()
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
outputDir
=
process
.
env
.
UNI_OUTPUT_DIR
// let time = Date.now()
const
imports
=
[...
DEFAULT_IMPORTS
]
const
rClass
=
resolveAndroidResourceClass
(
filename
)
...
...
@@ -297,19 +299,20 @@ async function compile(filename: string) {
isPlugin
:
true
,
outDir
:
outputDir
,
package
:
parseKotlinPackage
(
filename
).
package
,
sourceMap
:
resolveUTSSourceMapPath
(
filename
)
,
sourceMap
:
sourceMap
?
resolveUTSSourceMapPath
(
filename
)
:
false
,
extname
:
'
kt
'
,
imports
,
logFilename
:
true
,
noColor
:
isInHBuilderX
(),
},
})
moveRootIndexSourceMap
(
filename
,
{
inputDir
:
process
.
env
.
UNI_INPUT_DIR
,
outputDir
:
process
.
env
.
UNI_OUTPUT_DIR
,
platform
:
'
app-android
'
,
extname
:
'
.kt
'
,
})
sourceMap
&&
moveRootIndexSourceMap
(
filename
,
{
inputDir
,
outputDir
,
platform
:
'
app-android
'
,
extname
:
'
.kt
'
,
})
return
result
}
...
...
packages/uni-uts-v1/src/swift.ts
浏览文件 @
958bfdf0
...
...
@@ -8,6 +8,7 @@ import {
resolvePackage
,
resolveUTSPlatformFile
,
resolveUTSSourceMapPath
,
ToSwiftOptions
,
}
from
'
./utils
'
import
{
isInHBuilderX
}
from
'
./shared
'
import
{
UtsResult
}
from
'
@dcloudio/uts
'
...
...
@@ -32,10 +33,12 @@ export async function runSwiftProd(filename: string) {
if
(
filename
.
includes
(
'
app-android
'
))
{
return
}
await
compile
(
filename
)
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
outputDir
=
process
.
env
.
UNI_OUTPUT_DIR
await
compile
(
filename
,
{
inputDir
,
outputDir
,
sourceMap
:
true
})
genUTSPlatformResource
(
filename
,
{
inputDir
:
process
.
env
.
UNI_INPUT_DIR
,
outputDir
:
process
.
env
.
UNI_OUTPUT_DIR
,
inputDir
,
outputDir
,
platform
:
'
app-ios
'
,
extname
:
'
.swift
'
,
})
...
...
@@ -72,20 +75,26 @@ export async function runSwiftDev(filename: string) {
return
}
}
const
result
=
(
await
compile
(
filename
))
as
RunSwiftDevResult
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
outputDir
=
process
.
env
.
UNI_OUTPUT_DIR
const
result
=
(
await
compile
(
filename
,
{
inputDir
,
outputDir
,
sourceMap
:
true
,
}))
as
RunSwiftDevResult
result
.
type
=
'
swift
'
const
swiftFile
=
resolveUTSPlatformFile
(
filename
,
{
inputDir
:
process
.
env
.
UNI_INPUT_DIR
,
outputDir
:
process
.
env
.
UNI_OUTPUT_DIR
,
inputDir
,
outputDir
,
platform
:
'
app-ios
'
,
extname
:
'
.swift
'
,
})
result
.
changed
=
[]
// 开发模式下,需要生成 framework
if
(
fs
.
existsSync
(
swiftFile
))
{
let
projectPath
=
process
.
env
.
UNI_INPUT_DIR
let
projectPath
=
inputDir
const
isCli
=
isCliProject
(
projectPath
)
if
(
isCli
)
{
projectPath
=
path
.
resolve
(
projectPath
,
'
..
'
)
...
...
@@ -96,14 +105,8 @@ export async function runSwiftDev(filename: string) {
isCli
,
type
:
1
,
pluginName
:
id
,
utsPath
:
resolveCompilerUtsPath
(
process
.
env
.
UNI_INPUT_DIR
,
is_uni_modules
),
swiftPath
:
resolveCompilerSwiftPath
(
process
.
env
.
UNI_OUTPUT_DIR
,
is_uni_modules
),
utsPath
:
resolveCompilerUtsPath
(
inputDir
,
is_uni_modules
),
swiftPath
:
resolveCompilerSwiftPath
(
outputDir
,
is_uni_modules
),
})
result
.
code
=
code
result
.
msg
=
msg
...
...
@@ -127,13 +130,11 @@ function isCliProject(projectPath: string) {
return
false
}
async
function
compile
(
filename
:
string
)
{
if
(
!
process
.
env
.
UNI_HBUILDERX_PLUGINS
)
{
throw
'
process.env.UNI_HBUILDERX_PLUGINS is not found
'
}
export
async
function
compile
(
filename
:
string
,
{
inputDir
,
outputDir
,
sourceMap
}:
ToSwiftOptions
)
{
const
{
bundle
,
UtsTarget
}
=
getUtsCompiler
()
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
outputDir
=
process
.
env
.
UNI_OUTPUT_DIR
// let time = Date.now()
const
result
=
await
bundle
(
UtsTarget
.
SWIFT
,
{
input
:
{
...
...
@@ -144,19 +145,20 @@ async function compile(filename: string) {
isPlugin
:
true
,
outDir
:
outputDir
,
package
:
parseSwiftPackage
(
filename
).
namespace
,
sourceMap
:
resolveUTSSourceMapPath
(
filename
)
,
sourceMap
:
sourceMap
?
resolveUTSSourceMapPath
(
filename
)
:
false
,
extname
:
'
swift
'
,
imports
:
[
'
DCUTSFoundation
'
],
logFilename
:
true
,
noColor
:
isInHBuilderX
(),
},
})
moveRootIndexSourceMap
(
filename
,
{
inputDir
:
process
.
env
.
UNI_INPUT_DIR
,
outputDir
:
process
.
env
.
UNI_OUTPUT_DIR
,
platform
:
'
app-ios
'
,
extname
:
'
.swift
'
,
})
sourceMap
&&
moveRootIndexSourceMap
(
filename
,
{
inputDir
,
outputDir
,
platform
:
'
app-ios
'
,
extname
:
'
.swift
'
,
})
return
result
}
...
...
packages/uni-uts-v1/src/utils.ts
浏览文件 @
958bfdf0
...
...
@@ -10,6 +10,14 @@ import {
runByHBuilderX
,
}
from
'
./shared
'
interface
ToOptions
{
inputDir
:
string
outputDir
:
string
sourceMap
:
boolean
}
export
type
ToKotlinOptions
=
ToOptions
export
type
ToSwiftOptions
=
ToOptions
export
function
resolveUTSSourceMapPath
(
_filename
:
string
)
{
return
resolveSourceMapPath
()
}
...
...
@@ -84,7 +92,7 @@ export function genUTSPlatformResource(
export
function
moveRootIndexSourceMap
(
filename
:
string
,
{
inputDir
,
outputDir
,
platform
,
extname
}:
UTSPlatformResourceOptions
{
inputDir
,
platform
,
extname
}:
UTSPlatformResourceOptions
)
{
if
(
isRootIndex
(
filename
,
platform
))
{
const
sourceMapFilename
=
path
...
...
packages/uts-darwin-arm64/uts.darwin-arm64.node
浏览文件 @
958bfdf0
无法预览此类型文件
packages/uts-darwin-x64/uts.darwin-x64.node
浏览文件 @
958bfdf0
无法预览此类型文件
packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node
浏览文件 @
958bfdf0
无法预览此类型文件
packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node
浏览文件 @
958bfdf0
无法预览此类型文件
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录