Skip to content

Hermes scripts: rename tarball methods to distinguish between source code and prebuilt artifacts #35156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions scripts/__tests__/hermes-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const {
configureMakeForPrebuiltHermesC,
copyBuildScripts,
copyPodSpec,
downloadHermesTarball,
expandHermesTarball,
getHermesTarballName,
downloadHermesSourceTarball,
expandHermesSourceTarball,
getHermesPrebuiltArtifactsTarballName,
getHermesTagSHA,
readHermesTag,
setHermesTag,
Expand Down Expand Up @@ -155,29 +155,29 @@ describe('hermes-utils', () => {
expect(readHermesTag()).toEqual(hermesTag);
});
});
describe('getHermesTarballName', () => {
describe('getHermesPrebuiltArtifactsTarballName', () => {
it('should return Hermes tarball name', () => {
expect(getHermesTarballName('Debug', '1000.0.0')).toEqual(
'hermes-runtime-darwin-debug-v1000.0.0.tar.gz',
);
expect(
getHermesPrebuiltArtifactsTarballName('Debug', '1000.0.0'),
).toEqual('hermes-runtime-darwin-debug-v1000.0.0.tar.gz');
});
it('should throw if build type is undefined', () => {
expect(() => {
getHermesTarballName();
getHermesPrebuiltArtifactsTarballName();
}).toThrow('Did not specify build type.');
});
it('should throw if release version is undefined', () => {
expect(() => {
getHermesTarballName('Release');
getHermesPrebuiltArtifactsTarballName('Release');
}).toThrow('Did not specify release version.');
});
it('should return debug Hermes tarball name for RN 0.70.0', () => {
expect(getHermesTarballName('Debug', '0.70.0')).toEqual(
expect(getHermesPrebuiltArtifactsTarballName('Debug', '0.70.0')).toEqual(
'hermes-runtime-darwin-debug-v0.70.0.tar.gz',
);
});
it('should return a wildcard Hermes tarball name for any RN version', () => {
expect(getHermesTarballName('Debug', '*')).toEqual(
expect(getHermesPrebuiltArtifactsTarballName('Debug', '*')).toEqual(
'hermes-runtime-darwin-debug-v*.tar.gz',
);
});
Expand All @@ -188,10 +188,10 @@ describe('hermes-utils', () => {
expect(execCalls.git).toBe(true);
});
});
describe('downloadHermesTarball', () => {
it('should download Hermes tarball to download dir', () => {
describe('downloadHermesSourceTarball', () => {
it('should download Hermes source tarball to download dir', () => {
fs.writeFileSync(path.join(SDKS_DIR, '.hermesversion'), hermesTag);
downloadHermesTarball();
downloadHermesSourceTarball();
expect(execCalls.curl).toBe(true);
expect(
fs.readFileSync(
Expand All @@ -210,25 +210,25 @@ describe('hermes-utils', () => {
tarballContents,
);

downloadHermesTarball();
downloadHermesSourceTarball();
expect(execCalls.curl).toBeUndefined();
});
});
describe('expandHermesTarball', () => {
it('should expand Hermes tarball to Hermes source dir', () => {
describe('expandHermesSourceTarball', () => {
it('should expand Hermes source tarball to Hermes source dir', () => {
fs.mkdirSync(path.join(SDKS_DIR, 'download'), {recursive: true});
fs.writeFileSync(
path.join(SDKS_DIR, 'download', `hermes-${hermesTagSha}.tgz`),
tarballContents,
);
expect(fs.existsSync(path.join(SDKS_DIR, 'hermes'))).toBeFalsy();
expandHermesTarball();
expandHermesSourceTarball();
expect(execCalls.tar).toBe(true);
expect(fs.existsSync(path.join(SDKS_DIR, 'hermes'))).toBe(true);
});
it('should fail if Hermes tarball does not exist', () => {
it('should fail if Hermes source tarball does not exist', () => {
expect(() => {
expandHermesTarball();
expandHermesSourceTarball();
}).toThrow('[Hermes] Could not locate Hermes tarball.');
expect(execCalls.tar).toBeUndefined();
});
Expand Down
4 changes: 2 additions & 2 deletions scripts/hermes/create-tarball.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const path = require('path');
* Must be invoked after Hermes has been built.
*/
const yargs = require('yargs');
const {createHermesTarball} = require('./hermes-utils');
const {createHermesPrebuiltArtifactsTarball} = require('./hermes-utils');

let argv = yargs
.option('i', {
Expand Down Expand Up @@ -60,7 +60,7 @@ async function main() {
}
}

const tarballOutputPath = createHermesTarball(
const tarballOutputPath = createHermesPrebuiltArtifactsTarball(
hermesDir,
buildType,
releaseVersion,
Expand Down
7 changes: 5 additions & 2 deletions scripts/hermes/get-tarball-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Hermes tarball for the given build type and release version.
*/
const yargs = require('yargs');
const {getHermesTarballName} = require('./hermes-utils');
const {getHermesPrebuiltArtifactsTarballName} = require('./hermes-utils');

let argv = yargs
.option('b', {
Expand All @@ -31,7 +31,10 @@ let argv = yargs
}).argv;

async function main() {
const tarballName = getHermesTarballName(argv.buildType, argv.releaseVersion);
const tarballName = getHermesPrebuiltArtifactsTarballName(
argv.buildType,
argv.releaseVersion,
);
console.log(tarballName);
return tarballName;
}
Expand Down
26 changes: 15 additions & 11 deletions scripts/hermes/hermes-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const {execSync} = require('child_process');
const SDKS_DIR = path.normalize(path.join(__dirname, '..', '..', 'sdks'));
const HERMES_DIR = path.join(SDKS_DIR, 'hermes');
const HERMES_TAG_FILE_PATH = path.join(SDKS_DIR, '.hermesversion');
const HERMES_TARBALL_BASE_URL = 'https://github.com/facebook/hermes/tarball/';
const HERMES_SOURCE_TARBALL_BASE_URL =
'https://github.com/facebook/hermes/tarball/';
const HERMES_TARBALL_DOWNLOAD_DIR = path.join(SDKS_DIR, 'download');
const MACOS_BIN_DIR = path.join(SDKS_DIR, 'hermesc', 'osx-bin');
const MACOS_HERMESC_PATH = path.join(MACOS_BIN_DIR, 'hermesc');
Expand Down Expand Up @@ -71,11 +72,11 @@ function getHermesTarballDownloadPath(hermesTag) {
return path.join(HERMES_TARBALL_DOWNLOAD_DIR, `hermes-${hermesTagSHA}.tgz`);
}

function downloadHermesTarball() {
function downloadHermesSourceTarball() {
const hermesTag = readHermesTag();
const hermesTagSHA = getHermesTagSHA(hermesTag);
const hermesTarballDownloadPath = getHermesTarballDownloadPath(hermesTag);
let hermesTarballUrl = HERMES_TARBALL_BASE_URL + hermesTag;
let hermesTarballUrl = HERMES_SOURCE_TARBALL_BASE_URL + hermesTag;

if (fs.existsSync(hermesTarballDownloadPath)) {
return;
Expand All @@ -95,7 +96,7 @@ function downloadHermesTarball() {
}
}

function expandHermesTarball() {
function expandHermesSourceTarball() {
const hermesTag = readHermesTag();
const hermesTagSHA = getHermesTagSHA(hermesTag);
const hermesTarballDownloadPath = getHermesTarballDownloadPath(hermesTag);
Expand Down Expand Up @@ -196,7 +197,7 @@ set_target_properties(native-hermesc PROPERTIES
}
}

function getHermesTarballName(buildType, releaseVersion) {
function getHermesPrebuiltArtifactsTarballName(buildType, releaseVersion) {
if (!buildType) {
throw Error('Did not specify build type.');
}
Expand All @@ -206,7 +207,7 @@ function getHermesTarballName(buildType, releaseVersion) {
return `hermes-runtime-darwin-${buildType.toLowerCase()}-v${releaseVersion}.tar.gz`;
}

function createHermesTarball(
function createHermesPrebuiltArtifactsTarball(
hermesDir,
buildType,
releaseVersion,
Expand Down Expand Up @@ -245,7 +246,10 @@ function createHermesTarball(
throw new Error(`Failed to copy destroot to tempdir: ${error}`);
}

const tarballFilename = getHermesTarballName(buildType, releaseVersion);
const tarballFilename = getHermesPrebuiltArtifactsTarballName(
buildType,
releaseVersion,
);
const tarballOutputPath = path.join(tarballOutputDir, tarballFilename);

try {
Expand All @@ -267,11 +271,11 @@ module.exports = {
configureMakeForPrebuiltHermesC,
copyBuildScripts,
copyPodSpec,
createHermesTarball,
downloadHermesTarball,
expandHermesTarball,
createHermesPrebuiltArtifactsTarball,
downloadHermesSourceTarball,
expandHermesSourceTarball,
getHermesTagSHA,
getHermesTarballName,
getHermesPrebuiltArtifactsTarballName,
readHermesTag,
setHermesTag,
shouldBuildHermesFromSource,
Expand Down
8 changes: 4 additions & 4 deletions scripts/hermes/prepare-hermes-for-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const {
configureMakeForPrebuiltHermesC,
copyBuildScripts,
copyPodSpec,
downloadHermesTarball,
expandHermesTarball,
downloadHermesSourceTarball,
expandHermesSourceTarball,
shouldUsePrebuiltHermesC,
shouldBuildHermesFromSource,
} = require('./hermes-utils');
Expand All @@ -28,8 +28,8 @@ async function main(isInCI) {
copyPodSpec();
return;
}
downloadHermesTarball();
expandHermesTarball();
downloadHermesSourceTarball();
expandHermesSourceTarball();
copyPodSpec();
copyBuildScripts();

Expand Down