Skip to content

Commit

Permalink
hermes-utils: Strip debug symbols during tarball creation (#35162)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #35162

The dSYMs for Apple will not be distributed as part of the prebuilts tarball. They can still be included in the tarball by passing a `-d` flag to the create-tarball script.

Changelog: [internal]

Reviewed By: cipolleschi

Differential Revision: D40813679

fbshipit-source-id: 26dee8251684c5ecad649ccd27ce688cfe88ec8f
  • Loading branch information
hramos authored and facebook-github-bot committed Nov 1, 2022
1 parent dbb9252 commit d71d0db
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
7 changes: 7 additions & 0 deletions scripts/hermes/create-tarball.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ let argv = yargs
.option('o', {
alias: 'outputDir',
describe: 'Location where the tarball will be saved to.',
})
.option('exclude-debug-symbols', {
describe: 'Whether dSYMs should be excluded from the tarball.',
type: 'boolean',
default: true,
}).argv;

async function main() {
const hermesDir = argv.inputDir;
const buildType = argv.buildType;
const releaseVersion = argv.releaseVersion;
const excludeDebugSymbols = argv.excludeDebugSymbols;
let tarballOutputDir = argv.outputDir;

if (!tarballOutputDir) {
Expand All @@ -65,6 +71,7 @@ async function main() {
buildType,
releaseVersion,
tarballOutputDir,
excludeDebugSymbols,
);
console.log(tarballOutputPath);
return tarballOutputPath;
Expand Down
48 changes: 32 additions & 16 deletions scripts/hermes/hermes-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,33 +212,28 @@ function createHermesPrebuiltArtifactsTarball(
buildType,
releaseVersion,
tarballOutputDir,
excludeDebugSymbols,
) {
if (!hermesDir) {
hermesDir = HERMES_DIR;
}
if (!fs.existsSync(hermesDir)) {
throw new Error(`Path to Hermes does not exist at ${hermesDir}`);
}
if (!fs.existsSync(path.join(hermesDir, 'destroot'))) {
throw new Error(
`destroot not found at ${path.join(
hermesDir,
'destroot',
)}. Are you sure Hermes has been built?`,
);
}
validateHermesFrameworksExist(path.join(hermesDir, 'destroot'));

if (!fs.existsSync(tarballOutputDir)) {
fs.mkdirSync(tarballOutputDir, {recursive: true});
}

let tarballTempDir;

try {
tarballTempDir = fs.mkdtempSync(
path.join(os.tmpdir(), 'hermes-engine-destroot-'),
);

execSync(`cp -R ./destroot ${tarballTempDir}`, {cwd: hermesDir});
let args = ['-a'];
if (excludeDebugSymbols) {
args.push('--exclude=dSYMs/');
args.push('--exclude=*.dSYM/');
}
execSync(`rsync ${args.join(' ')} ./destroot ${tarballTempDir}`, {
cwd: hermesDir,
});
if (fs.existsSync(path.join(hermesDir, 'LICENSE'))) {
execSync(`cp LICENSE ${tarballTempDir}`, {cwd: hermesDir});
}
Expand Down Expand Up @@ -267,6 +262,27 @@ function createHermesPrebuiltArtifactsTarball(
return tarballOutputPath;
}

function validateHermesFrameworksExist(destrootDir) {
if (
!fs.existsSync(
path.join(destrootDir, 'Library/Frameworks/macosx/hermes.framework'),
)
) {
throw new Error(
'Error: Hermes macOS Framework not found. Are you sure Hermes has been built?',
);
}
if (
!fs.existsSync(
path.join(destrootDir, 'Library/Frameworks/universal/hermes.xcframework'),
)
) {
throw new Error(
'Error: Hermes iOS XCFramework not found. Are you sure Hermes has been built?',
);
}
}

module.exports = {
configureMakeForPrebuiltHermesC,
copyBuildScripts,
Expand Down

0 comments on commit d71d0db

Please sign in to comment.