Skip to content

Commit

Permalink
[script]upgrade terra (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe authored May 29, 2024
1 parent 94e4fd0 commit f407bd1
Show file tree
Hide file tree
Showing 42 changed files with 935 additions and 2,669 deletions.
85 changes: 85 additions & 0 deletions scripts/terra/config/c_to_ts_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { SimpleType, SimpleTypeKind } from '@agoraio-extensions/cxx-parser';
import {
UpdateNodeConfig,
updateSimpleTypeName,
} from '@agoraio-extensions/terra_shared_configs';

module.exports = {
'^Optional<(.*)>': '$1',
'^(.*)::(.*)': '$2',
'^AString$': 'string',
'^user_id_t$': 'string',
'^view_t$': 'any',
'^view_t\\*$': 'any[]',
'^uid_t$': 'number',
'^const uid_t\\*$': 'number[]',
'^track_id_t$': 'number',
'^video_track_id_t$': 'number',
'^conn_id_t$': 'number',
'^char$': 'number',
'^unsigned int$': 'number',
'^size_t$': 'number',
'^unsigned short$': 'number',
'^unsigned char$': 'number',
'^float$': 'number',
'^double$': 'number',
'^int(.*)_t$': 'number',
'^uint(.*)_t$': 'number',
'^long$': 'number',
'^long long$': 'number',
'^int$': 'number',
'^bool$': 'boolean',
'^intptr_t$': 'number',
'^uintptr_t$': 'number',
'^const char \\*$': 'string',
'^IMetadata': 'RtmMetadata',
'customHook': (node: SimpleType, configs: UpdateNodeConfig) => {
let type = node.name;
if (!type) {
type = node.source;
}
switch (node.asSimpleType().kind) {
case SimpleTypeKind.value_t:
type = updateSimpleTypeName(type, configs);
break;
case SimpleTypeKind.pointer_t:
if (type == 'char') {
if (node.source.endsWith('**')) {
type = 'string[]';
} else {
type = 'string';
}
} else if (type == 'uint8_t' || type == 'unsigned char') {
type = 'Uint8Array';
} else if (type == 'void') {
type = 'any';
} else {
type = updateSimpleTypeName(type, configs);
}
break;
case SimpleTypeKind.reference_t:
type = updateSimpleTypeName(type, configs);
break;
case SimpleTypeKind.array_t:
if (type == 'char') {
if (node.source.endsWith('**')) {
type = 'string[]';
} else {
type = 'string';
}
} else if (type == 'void') {
type = 'Uint8Array';
} else {
type = updateSimpleTypeName(type, configs) + '[]';
}
break;
case SimpleTypeKind.template_t:
type = updateSimpleTypeName(node.template_arguments[0]!, configs);
break;
default:
type = updateSimpleTypeName(type, configs);
break;
}
return type;
},
};
1 change: 0 additions & 1 deletion scripts/terra/config/filter_file_list.json

This file was deleted.

11 changes: 11 additions & 0 deletions scripts/terra/config/fixed_return_type_list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SimpleTypeKind } from '@agoraio-extensions/cxx-parser';

module.exports = {
'agora::rtm::IStreamChannel.getSubscribedUserList': {
name: 'agora::rtm::UserList',
source: 'agora::rtm::UserList*',
kind: SimpleTypeKind.array_t,
is_const: false,
is_builtin_type: true,
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
parsers:
# CXXParser should always put first
- name: CXXParser
package: '@agoraio-extensions/cxx-parser'
args:
Expand All @@ -9,6 +8,7 @@ parsers:
include:
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/*.h'
exclude:
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/IAgoraRtmService.h'
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/IAgoraService.h'

- name: AddNodeParser
Expand All @@ -22,27 +22,40 @@ parsers:
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/*.h'
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/custom_headers/*.h'
exclude:
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/IAgoraRtmService.h'
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/IAgoraService.h'

- name: RemoveNodeParser
package: '@agoraio-extensions/terra_shared_configs'
args:
ignoreDefaultConfig: true
configFilePath: ./remove_node_list.ts
- name: PointerToArrayParser
package: '@agoraio-extensions/terra_shared_configs'
args:
configJsonFilePath: ./pointer_to_array.json
- name: OrderNodeParser
ignoreDefaultConfig: true
configFilePath: ./pointer_to_array.ts
- name: UpdateSimpleTypeParser
package: '@agoraio-extensions/terra_shared_configs'
args:
ignoreDefaultConfig: true
configFilePath: ./rename_member_function_param_type_list.ts
- name: ReturnTypeParser
package: '@agoraio-extensions/terra_shared_configs'
args:
convertReturnToVoid: false
ignoreDefaultConfig: true
configFilePath: ./fixed_return_type_list.ts
- name: FixEnumConstantParser
package: '@agoraio-extensions/terra_shared_configs'
- name: UpdateSimpleTypeParser
- name: OrderNodeParser
package: '@agoraio-extensions/terra_shared_configs'
args:
configJsonFilePath: ./param_type_list.json
- name: RemoveNodeParser
- name: UpdateSimpleTypeParser
package: '@agoraio-extensions/terra_shared_configs'
args:
configJsonFilePath: ./remove_node_list.json

# defines_macros:
# - __IRIS_WEB__
parserDefaultValue: true
ignoreDefaultConfig: true
configFilePath: ./c_to_ts_config.ts

renderers:
- path: ../impl.ts
Expand Down
31 changes: 0 additions & 31 deletions scripts/terra/config/impl_special_return_list.json

This file was deleted.

36 changes: 0 additions & 36 deletions scripts/terra/config/param_optional_list.json

This file was deleted.

40 changes: 0 additions & 40 deletions scripts/terra/config/param_type_list.json

This file was deleted.

1 change: 0 additions & 1 deletion scripts/terra/config/pointer_to_array.json

This file was deleted.

10 changes: 10 additions & 0 deletions scripts/terra/config/pointer_to_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = [
'agora::rtm::IRtmPresence.setState.items',
'agora::rtm::IRtmEventHandler.onWhereNowResult.channels',
'agora::rtm::IRtmEventHandler.onGetUserChannelsResult.channels',
'agora::rtm::IChannelEventHandler.onMembersGotten.members',
'agora::rtm::IStreamChannel.unsubscribeTopic.options',
'agora::rtm::IChannelEventHandler.onAttributesUpdated.attributes',
'agora::rtm::IChannelEventHandler.onAttributesDeleted.attributes',
'agora::rtm::IChannelEventHandler.updateAttributes.attributes',
];
9 changes: 0 additions & 9 deletions scripts/terra/config/remove_node_list.json

This file was deleted.

4 changes: 4 additions & 0 deletions scripts/terra/config/remove_node_list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = [
'agora::rtm::IMetadata',
'agora::rtm::IStreamChannel.getSubscribedUserList.users',
];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
parsers:
# CXXParser should always put first
- name: CXXParser
package: '@agoraio-extensions/cxx-parser'
args:
Expand All @@ -9,6 +8,7 @@ parsers:
include:
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/*.h'
exclude:
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/IAgoraRtmService.h'
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/IAgoraService.h'

- name: AddNodeParser
Expand All @@ -22,27 +22,44 @@ parsers:
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/*.h'
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/custom_headers/*.h'
exclude:
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/IAgoraRtmService.h'
- '@agoraio-extensions/terra_shared_configs:headers/rtm_2.1.7/include/IAgoraService.h'

- name: RemoveNodeParser
package: '@agoraio-extensions/terra_shared_configs'
args:
ignoreDefaultConfig: true
configFilePath: ./remove_node_list.ts
- name: PointerToArrayParser
package: '@agoraio-extensions/terra_shared_configs'
args:
configJsonFilePath: ./pointer_to_array.json
- name: OrderNodeParser
ignoreDefaultConfig: true
configFilePath: ./pointer_to_array.ts
- name: UpdateSimpleTypeParser
package: '@agoraio-extensions/terra_shared_configs'
args:
ignoreDefaultConfig: true
configFilePath: ./rename_member_function_param_type_list.ts
- name: ReturnTypeParser
package: '@agoraio-extensions/terra_shared_configs'
args:
convertReturnToVoid: false
ignoreDefaultConfig: true
configFilePath: ./fixed_return_type_list.ts
- name: FixEnumConstantParser
package: '@agoraio-extensions/terra_shared_configs'
- name: OrderNodeParser
package: '@agoraio-extensions/terra_shared_configs'
- name: UpdateSimpleTypeParser
package: '@agoraio-extensions/terra_shared_configs'
args:
configJsonFilePath: ./param_type_list.json
- name: RemoveNodeParser
parserDefaultValue: true
ignoreDefaultConfig: true
configFilePath: ./c_to_ts_config.ts
- name: TsCommentParser
package: '@agoraio-extensions/terra_shared_configs'
args:
configJsonFilePath: ./remove_node_list.json

# defines_macros:
# - __IRIS_WEB__
language: 'ts'

renderers:
- path: ../index.ts
Expand Down
18 changes: 18 additions & 0 deletions scripts/terra/generate-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e
set -x

MY_PATH=$(realpath $(dirname "$0"))
PROJECT_ROOT=$(realpath ${MY_PATH}/../..)

npm exec terra -- run \
--config ${PROJECT_ROOT}/scripts/terra/config/types_config.yaml \
--output-dir=${PROJECT_ROOT}/src

npm exec terra -- run \
--config ${PROJECT_ROOT}/scripts/terra/config/impl_config.yaml \
--output-dir=${PROJECT_ROOT}/src

cd ${PROJECT_ROOT}

yarn exec eslint --fix --ext .ts ./src
Loading

0 comments on commit f407bd1

Please sign in to comment.