Skip to content

Commit

Permalink
Add Fantom mode for development with Hermes bytecode (facebook#48178)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#48178

Changelog: [internal]

Adds a new mode for Fantom to run tests with dev-mode bytecode. Right now the modes were only dev (development with source code) or opt (optimized bytecode).

Reviewed By: rshest

Differential Revision: D66888986

fbshipit-source-id: 34b2566a65d138790e16f8fb5787fd9c2bcde536
  • Loading branch information
rubennorte authored and facebook-github-bot committed Dec 9, 2024
1 parent 4d07fb7 commit 3cc67fe
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
11 changes: 8 additions & 3 deletions packages/react-native-fantom/runner/getFantomTestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type JsOnlyFeatureFlags = (typeof ReactNativeFeatureFlags)['jsOnly'];
type DocblockPragmas = {[key: string]: string | string[]};

export enum FantomTestConfigMode {
Development,
DevelopmentWithBytecode,
DevelopmentWithSource,
Optimized,
}

Expand All @@ -40,7 +41,8 @@ export type FantomTestConfig = {
},
};

const DEFAULT_MODE: FantomTestConfigMode = FantomTestConfigMode.Development;
const DEFAULT_MODE: FantomTestConfigMode =
FantomTestConfigMode.DevelopmentWithSource;

const FANTOM_FLAG_FORMAT = /^(\w+):(\w+)$/;

Expand Down Expand Up @@ -89,7 +91,10 @@ export default function getFantomTestConfig(

switch (mode) {
case 'dev':
config.mode = FantomTestConfigMode.Development;
config.mode = FantomTestConfigMode.DevelopmentWithSource;
break;
case 'dev-bytecode':
config.mode = FantomTestConfigMode.DevelopmentWithBytecode;
break;
case 'opt':
config.mode = FantomTestConfigMode.Optimized;
Expand Down
47 changes: 24 additions & 23 deletions packages/react-native-fantom/runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,21 @@ function generateBytecodeBundle({
bytecodePath: string,
isOptimizedMode: boolean,
}): void {
const hermesCompilerCommandResult = runBuck2([
'run',
getBuckModeForPlatform(isOptimizedMode),
'//xplat/hermes/tools/hermesc:hermesc',
'--',
'-emit-binary',
'-O',
'-max-diagnostic-width',
'80',
'-out',
bytecodePath,
sourcePath,
]);
const hermesCompilerCommandResult = runBuck2(
[
'run',
getBuckModeForPlatform(isOptimizedMode),
'//xplat/hermes/tools/hermesc:hermesc',
'--',
'-emit-binary',
isOptimizedMode ? '-O' : null,
'-max-diagnostic-width',
'80',
'-out',
bytecodePath,
sourcePath,
].filter(Boolean),
);

if (hermesCompilerCommandResult.status !== 0) {
throw new Error(getDebugInfoFromCommandResult(hermesCompilerCommandResult));
Expand All @@ -98,8 +100,6 @@ module.exports = async function runTest(

const testConfig = getFantomTestConfig(testPath);

const isOptimizedMode = testConfig.mode === FantomTestConfigMode.Optimized;

const metroConfig = await Metro.loadConfig({
config: path.resolve(__dirname, '..', 'config', 'metro.config.js'),
});
Expand All @@ -121,8 +121,7 @@ module.exports = async function runTest(
BUILD_OUTPUT_PATH,
`${getShortHash(entrypointContents)}-${path.basename(testPath)}`,
);
const testBundlePath = entrypointPath + '.bundle';
const testJSBundlePath = testBundlePath + '.js';
const testJSBundlePath = entrypointPath + '.bundle.js';
const testBytecodeBundlePath = testJSBundlePath + '.hbc';

fs.mkdirSync(path.dirname(entrypointPath), {recursive: true});
Expand All @@ -137,27 +136,29 @@ module.exports = async function runTest(
entry: entrypointPath,
out: testJSBundlePath,
platform: 'android',
minify: isOptimizedMode,
dev: !isOptimizedMode,
minify: testConfig.mode === FantomTestConfigMode.Optimized,
dev: testConfig.mode !== FantomTestConfigMode.Optimized,
sourceMap: true,
sourceMapUrl: sourceMapPath,
});

if (isOptimizedMode) {
if (testConfig.mode !== FantomTestConfigMode.DevelopmentWithSource) {
generateBytecodeBundle({
sourcePath: testJSBundlePath,
bytecodePath: testBytecodeBundlePath,
isOptimizedMode,
isOptimizedMode: testConfig.mode === FantomTestConfigMode.Optimized,
});
}

const rnTesterCommandResult = runBuck2([
'run',
getBuckModeForPlatform(isOptimizedMode),
getBuckModeForPlatform(testConfig.mode === FantomTestConfigMode.Optimized),
'//xplat/ReactNative/react-native-cxx/samples/tester:tester',
'--',
'--bundlePath',
testBundlePath,
testConfig.mode === FantomTestConfigMode.DevelopmentWithSource
? testJSBundlePath
: testBytecodeBundlePath,
'--featureFlags',
JSON.stringify(testConfig.flags.common),
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
* @fantom_mode dev-bytecode
*/

describe('"@fantom_mode dev-bytecode" in docblock', () => {
it('should use development builds', () => {
expect(__DEV__).toBe(true);
});
});

0 comments on commit 3cc67fe

Please sign in to comment.