mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 05:37:20 +03:00
chore: locate binaries in case of cli deployment (#4107)
This commit is contained in:
parent
db744e28ee
commit
3f68713f1e
@ -15,8 +15,7 @@
|
||||
*/
|
||||
|
||||
import { ChildProcess } from 'child_process';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { ffmpegExecutable } from '../../utils/binaryPaths';
|
||||
import { assert } from '../../utils/utils';
|
||||
import { launchProcess } from '../processLauncher';
|
||||
import { Progress, ProgressController } from '../progress';
|
||||
@ -59,16 +58,11 @@ export class VideoRecorder {
|
||||
args.push(options.outputFile);
|
||||
const progress = this._progress;
|
||||
|
||||
let ffmpegPath = 'ffmpeg';
|
||||
const binPath = path.join(__dirname, '../../../third_party/ffmpeg/');
|
||||
if (os.platform() === 'win32')
|
||||
ffmpegPath = path.join(binPath, os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe');
|
||||
else if (os.platform() === 'darwin')
|
||||
ffmpegPath = path.join(binPath, 'ffmpeg-mac');
|
||||
else
|
||||
ffmpegPath = path.join(binPath, 'ffmpeg-linux');
|
||||
const executablePath = ffmpegExecutable();
|
||||
if (!executablePath)
|
||||
throw new Error('ffmpeg executable was not found');
|
||||
const { launchedProcess, gracefullyClose } = await launchProcess({
|
||||
executablePath: ffmpegPath,
|
||||
executablePath,
|
||||
args,
|
||||
pipeStdin: true,
|
||||
progress,
|
||||
|
@ -20,6 +20,7 @@ import * as os from 'os';
|
||||
import { spawn } from 'child_process';
|
||||
import { getUbuntuVersion } from '../utils/ubuntuVersion';
|
||||
import { linuxLddDirectories, windowsExeAndDllDirectories, BrowserDescriptor } from '../utils/browserPaths.js';
|
||||
import { printDepsWindowsExecutable } from '../utils/binaryPaths';
|
||||
|
||||
const accessAsync = util.promisify(fs.access.bind(fs));
|
||||
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
|
||||
}
|
||||
|
||||
async function missingFileDependenciesWindows(filePath: string): Promise<Array<string>> {
|
||||
const executable = printDepsWindowsExecutable();
|
||||
if (!executable)
|
||||
return [];
|
||||
|
||||
const dirname = path.dirname(filePath);
|
||||
const printDepsWindowsExecutable = process.env.PW_PRINT_DEPS_WINDOWS_EXECUTABLE || path.join(__dirname, '../../bin/PrintDeps.exe');
|
||||
const {stdout, code} = await spawnAsync(printDepsWindowsExecutable, [filePath], {
|
||||
const {stdout, code} = await spawnAsync(executable, [filePath], {
|
||||
cwd: dirname,
|
||||
env: {
|
||||
...process.env,
|
||||
|
51
src/utils/binaryPaths.ts
Normal file
51
src/utils/binaryPaths.ts
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
||||
export function printDepsWindowsExecutable(): string | undefined {
|
||||
return pathToExecutable(['bin', 'PrintDeps.exe']);
|
||||
}
|
||||
|
||||
export function ffmpegExecutable(): string | undefined {
|
||||
let ffmpegName;
|
||||
if (process.platform === 'win32')
|
||||
ffmpegName = os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe';
|
||||
else if (process.platform === 'darwin')
|
||||
ffmpegName = 'ffmpeg-mac';
|
||||
else
|
||||
ffmpegName = 'ffmpeg-linux';
|
||||
return pathToExecutable(['third_party', 'ffmpeg', ffmpegName]);
|
||||
}
|
||||
|
||||
function pathToExecutable(relative: string[]): string | undefined {
|
||||
const defaultPath = path.join(__dirname, '..', '..', ...relative);
|
||||
const localPath = path.join(path.dirname(process.argv[0]), relative[relative.length - 1]);
|
||||
try {
|
||||
if (fs.existsSync(defaultPath))
|
||||
return defaultPath;
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (fs.existsSync(localPath))
|
||||
return localPath;
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user