Skip to content

Commit

Permalink
Refactor native-pack-tool/windows run logic
Browse files Browse the repository at this point in the history
  • Loading branch information
PatriceJiang committed Jun 25, 2023
1 parent 53f4200 commit 7487635
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
5 changes: 5 additions & 0 deletions scripts/native-pack-tool/source/base/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ export abstract class NativePackTool {
return /^[0-9a-zA-Z_-]+$/.test(this.params.projectName) ? this.params.projectName : 'CocosGame';
}

protected getExcutableNameOrDefault(): string {
const en = this.params.executableName;
return en ? en : this.projectNameASCII();
}

protected async excuteTemplateTask(tasks: CocosProjectTasks) {
if (tasks.appendFile) {
await Promise.all(tasks.appendFile.map((task) => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/native-pack-tool/source/platforms/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class IOSPackTool extends MacOSPackTool {
}

readBundleId(): string | null {
const prjName = this.params.projectName!;
const prjName = this.getExcutableNameOrDefault();
const cmakeTmpDir =
fs.readdirSync(ps.join(this.paths.nativePrjDir, 'CMakeFiles'))
.filter((x) => x.startsWith(prjName))[0];
Expand Down
18 changes: 2 additions & 16 deletions scripts/native-pack-tool/source/platforms/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,8 @@ export class WindowsPackTool extends NativePackTool {

async run(): Promise<boolean> {
const executableDir = ps.join(this.paths.nativePrjDir, this.params.debug ? 'Debug' : 'Release')
let executableFile: string;
let targetFile: string;
if (this.params.executableName) {
executableFile = ps.join(executableDir, this.params.executableName + '.exe');
targetFile = this.params.executableName;
} else {
if (/^[0-9a-zA-Z_-]+$/.test(this.params.projectName)) {
executableFile = ps.join(executableDir, this.params.projectName + '.exe');
targetFile = this.params.projectName;
} else {
const executableFiles = ['CocosGame', this.params.projectName].map(x => ps.join(executableDir, x + '.exe')).filter(x => fs.existsSync(x));
executableFile = executableFiles[0];
targetFile = 'CocosGame';
}
}

const targetFile = this.getExcutableNameOrDefault();
const executableFile = ps.join(executableDir, targetFile + '.exe');
if (!executableFile || !fs.existsSync(executableFile)) {
throw new Error(`[windows run] '${targetFile}' is not found within ' + ${executableDir}!`);
}
Expand Down
2 changes: 1 addition & 1 deletion templates/cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ macro(cc_common_after_target target_name)
endif()

target_compile_definitions(${target_name} PRIVATE
GAME_NAME="${APP_NAME}"
GAME_NAME="${CC_EXECUTABLE_NAME}"
)
if(XXTEAKEY)
target_compile_definitions(${target_name} PRIVATE
Expand Down

0 comments on commit 7487635

Please sign in to comment.