Skip to content

Commit 3f68713

Browse files
authored
chore: locate binaries in case of cli deployment (#4107)
1 parent db744e2 commit 3f68713

File tree

3 files changed

+62
-13
lines changed

3 files changed

+62
-13
lines changed

src/server/chromium/videoRecorder.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616

1717
import { ChildProcess } from 'child_process';
18-
import * as os from 'os';
19-
import * as path from 'path';
18+
import { ffmpegExecutable } from '../../utils/binaryPaths';
2019
import { assert } from '../../utils/utils';
2120
import { launchProcess } from '../processLauncher';
2221
import { Progress, ProgressController } from '../progress';
@@ -59,16 +58,11 @@ export class VideoRecorder {
5958
args.push(options.outputFile);
6059
const progress = this._progress;
6160

62-
let ffmpegPath = 'ffmpeg';
63-
const binPath = path.join(__dirname, '../../../third_party/ffmpeg/');
64-
if (os.platform() === 'win32')
65-
ffmpegPath = path.join(binPath, os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe');
66-
else if (os.platform() === 'darwin')
67-
ffmpegPath = path.join(binPath, 'ffmpeg-mac');
68-
else
69-
ffmpegPath = path.join(binPath, 'ffmpeg-linux');
61+
const executablePath = ffmpegExecutable();
62+
if (!executablePath)
63+
throw new Error('ffmpeg executable was not found');
7064
const { launchedProcess, gracefullyClose } = await launchProcess({
71-
executablePath: ffmpegPath,
65+
executablePath,
7266
args,
7367
pipeStdin: true,
7468
progress,

src/server/validateDependencies.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as os from 'os';
2020
import { spawn } from 'child_process';
2121
import { getUbuntuVersion } from '../utils/ubuntuVersion';
2222
import { linuxLddDirectories, windowsExeAndDllDirectories, BrowserDescriptor } from '../utils/browserPaths.js';
23+
import { printDepsWindowsExecutable } from '../utils/binaryPaths';
2324

2425
const accessAsync = util.promisify(fs.access.bind(fs));
2526
const checkExecutable = (filePath: string) => accessAsync(filePath, fs.constants.X_OK).then(() => true).catch(e => false);
@@ -190,9 +191,12 @@ async function executablesOrSharedLibraries(directoryPath: string): Promise<stri
190191
}
191192

192193
async function missingFileDependenciesWindows(filePath: string): Promise<Array<string>> {
194+
const executable = printDepsWindowsExecutable();
195+
if (!executable)
196+
return [];
197+
193198
const dirname = path.dirname(filePath);
194-
const printDepsWindowsExecutable = process.env.PW_PRINT_DEPS_WINDOWS_EXECUTABLE || path.join(__dirname, '../../bin/PrintDeps.exe');
195-
const {stdout, code} = await spawnAsync(printDepsWindowsExecutable, [filePath], {
199+
const {stdout, code} = await spawnAsync(executable, [filePath], {
196200
cwd: dirname,
197201
env: {
198202
...process.env,

src/utils/binaryPaths.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import * as fs from 'fs';
18+
import * as os from 'os';
19+
import * as path from 'path';
20+
21+
export function printDepsWindowsExecutable(): string | undefined {
22+
return pathToExecutable(['bin', 'PrintDeps.exe']);
23+
}
24+
25+
export function ffmpegExecutable(): string | undefined {
26+
let ffmpegName;
27+
if (process.platform === 'win32')
28+
ffmpegName = os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe';
29+
else if (process.platform === 'darwin')
30+
ffmpegName = 'ffmpeg-mac';
31+
else
32+
ffmpegName = 'ffmpeg-linux';
33+
return pathToExecutable(['third_party', 'ffmpeg', ffmpegName]);
34+
}
35+
36+
function pathToExecutable(relative: string[]): string | undefined {
37+
const defaultPath = path.join(__dirname, '..', '..', ...relative);
38+
const localPath = path.join(path.dirname(process.argv[0]), relative[relative.length - 1]);
39+
try {
40+
if (fs.existsSync(defaultPath))
41+
return defaultPath;
42+
} catch (e) {
43+
}
44+
45+
try {
46+
if (fs.existsSync(localPath))
47+
return localPath;
48+
} catch (e) {
49+
}
50+
}
51+

0 commit comments

Comments
 (0)