Use setProcessState
Summary: `setProcessState` does some adjusting to PATH. This was only ever done for Electron. This change moves that functionality to FlipperServerImpl which is the one what orchestrates. By doing this, flipper server also benefits from getting these adjustments. Reviewed By: antonk52 Differential Revision: D46836659 fbshipit-source-id: f98291d320cf9b7f3808223af8745c068b1318ce
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b4f0657f4f
commit
165a989cc6
@@ -39,7 +39,6 @@ import {
|
|||||||
Logger,
|
Logger,
|
||||||
parseEnvironmentVariables,
|
parseEnvironmentVariables,
|
||||||
setLoggerInstance,
|
setLoggerInstance,
|
||||||
Settings,
|
|
||||||
wrapRequire,
|
wrapRequire,
|
||||||
} from 'flipper-common';
|
} from 'flipper-common';
|
||||||
import constants from './fb-stubs/constants';
|
import constants from './fb-stubs/constants';
|
||||||
@@ -53,7 +52,6 @@ import {initCompanionEnv} from 'flipper-server-companion';
|
|||||||
import ReconnectingWebSocket from 'reconnecting-websocket';
|
import ReconnectingWebSocket from 'reconnecting-websocket';
|
||||||
import WS from 'ws';
|
import WS from 'ws';
|
||||||
import {Module} from 'module';
|
import {Module} from 'module';
|
||||||
import os from 'os';
|
|
||||||
|
|
||||||
Module.prototype.require = wrapRequire(Module.prototype.require);
|
Module.prototype.require = wrapRequire(Module.prototype.require);
|
||||||
enableMapSet();
|
enableMapSet();
|
||||||
@@ -242,8 +240,6 @@ async function start() {
|
|||||||
electronIpcClient,
|
electronIpcClient,
|
||||||
);
|
);
|
||||||
|
|
||||||
setProcessState(flipperServerConfig.settings);
|
|
||||||
|
|
||||||
// By turning this in a require, we force the JS that the body of this module (init) has completed (initializeElectron),
|
// By turning this in a require, we force the JS that the body of this module (init) has completed (initializeElectron),
|
||||||
// before starting the rest of the Flipper process.
|
// before starting the rest of the Flipper process.
|
||||||
// This prevent issues where the render host is referred at module initialisation level,
|
// This prevent issues where the render host is referred at module initialisation level,
|
||||||
@@ -332,22 +328,3 @@ function createDelegatedLogger(): Logger {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function setProcessState(settings: Settings) {
|
|
||||||
const androidHome = settings.androidHome;
|
|
||||||
const idbPath = settings.idbPath;
|
|
||||||
|
|
||||||
if (!process.env.ANDROID_HOME && !process.env.ANDROID_SDK_ROOT) {
|
|
||||||
process.env.ANDROID_HOME = androidHome;
|
|
||||||
process.env.ANDROID_SDK_ROOT = androidHome;
|
|
||||||
}
|
|
||||||
|
|
||||||
// emulator/emulator is more reliable than tools/emulator, so prefer it if
|
|
||||||
// it exists
|
|
||||||
process.env.PATH =
|
|
||||||
['emulator', 'tools', 'platform-tools']
|
|
||||||
.map((directory) => path.resolve(androidHome, directory))
|
|
||||||
.join(':') +
|
|
||||||
`:${idbPath}` +
|
|
||||||
`:${process.env.PATH}`;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import {
|
|||||||
FlipperServerExecOptions,
|
FlipperServerExecOptions,
|
||||||
DeviceDebugData,
|
DeviceDebugData,
|
||||||
CertificateExchangeMedium,
|
CertificateExchangeMedium,
|
||||||
|
Settings,
|
||||||
} from 'flipper-common';
|
} from 'flipper-common';
|
||||||
import {ServerDevice} from './devices/ServerDevice';
|
import {ServerDevice} from './devices/ServerDevice';
|
||||||
import {Base64} from 'js-base64';
|
import {Base64} from 'js-base64';
|
||||||
@@ -56,6 +57,7 @@ import {mkdirp} from 'fs-extra';
|
|||||||
import {flipperDataFolder, flipperSettingsFolder} from './utils/paths';
|
import {flipperDataFolder, flipperSettingsFolder} from './utils/paths';
|
||||||
import {DebuggableDevice} from './devices/DebuggableDevice';
|
import {DebuggableDevice} from './devices/DebuggableDevice';
|
||||||
import {jfUpload} from './fb-stubs/jf';
|
import {jfUpload} from './fb-stubs/jf';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
const {access, copyFile, mkdir, unlink, stat, readlink, readFile, writeFile} =
|
const {access, copyFile, mkdir, unlink, stat, readlink, readFile, writeFile} =
|
||||||
promises;
|
promises;
|
||||||
@@ -68,6 +70,25 @@ function isHandledStartupError(e: Error) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setProcessState(settings: Settings) {
|
||||||
|
const androidHome = settings.androidHome;
|
||||||
|
const idbPath = settings.idbPath;
|
||||||
|
|
||||||
|
if (!process.env.ANDROID_HOME && !process.env.ANDROID_SDK_ROOT) {
|
||||||
|
process.env.ANDROID_HOME = androidHome;
|
||||||
|
process.env.ANDROID_SDK_ROOT = androidHome;
|
||||||
|
}
|
||||||
|
|
||||||
|
// emulator/emulator is more reliable than tools/emulator, so prefer it if
|
||||||
|
// it exists
|
||||||
|
process.env.PATH =
|
||||||
|
['emulator', 'tools', 'platform-tools']
|
||||||
|
.map((directory) => path.resolve(androidHome, directory))
|
||||||
|
.join(':') +
|
||||||
|
`:${idbPath}` +
|
||||||
|
`:${process.env.PATH}`;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FlipperServer takes care of all incoming device & client connections.
|
* FlipperServer takes care of all incoming device & client connections.
|
||||||
* It will set up managers per device type, and create the incoming
|
* It will set up managers per device type, and create the incoming
|
||||||
@@ -99,6 +120,8 @@ export class FlipperServerImpl implements FlipperServer {
|
|||||||
console.log(
|
console.log(
|
||||||
'Loaded flipper config, paths: ' + JSON.stringify(config.paths, null, 2),
|
'Loaded flipper config, paths: ' + JSON.stringify(config.paths, null, 2),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
setProcessState(config.settings);
|
||||||
const server = (this.server = new ServerController(this));
|
const server = (this.server = new ServerController(this));
|
||||||
this.keytarManager = new KeytarManager(keytarModule);
|
this.keytarManager = new KeytarManager(keytarModule);
|
||||||
// given flipper-dump, it might make more sense to have the plugin command
|
// given flipper-dump, it might make more sense to have the plugin command
|
||||||
|
|||||||
Reference in New Issue
Block a user