Skip to content

Commit

Permalink
Properly export executables, fix #934
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoTheThird committed Oct 23, 2019
1 parent d6b84d1 commit be11080
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 38 deletions.
2 changes: 1 addition & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ if (cli.platformTools) {
if (!cli.downloadOnly) build();
});
}).catch(() => {
console.error("Failed to download files!")
console.error("Failed to download files!");
process.exit(1);
});
} else {
Expand Down
48 changes: 11 additions & 37 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,43 +155,17 @@ function die(e) {

// WORKAROUND: the chile spawned by child_process.exec can not access files inside the asar package
function exportExecutablesFromPackage() {
getFallbackPlatformTools().forEach((tool) => {
fs.copy(tool.package, tool.cache, () => {
fs.chmodSync(tool.cache, 0o755);
});
});
}

function maybeEXE(platform, tool) {
if(platform === "win32") tool+=".exe";
return tool;
}

function getPlatform() {
var thisPlatform = os.platform();
if(!platforms[thisPlatform]) die("Unsuported platform");
return platforms[thisPlatform];
}

function getFallbackPlatformTools() {
var thisPlatform = os.platform();
if(!platforms[thisPlatform]) die("Unsupported platform");
var toolInPackage = path.join(__dirname, "/../platform-tools/", platforms[thisPlatform]);
var toolInCache = path.join(utils.getUbuntuTouchDir(), 'platform-tools');
return [
{
package: path.join(toolInPackage, maybeEXE(thisPlatform, "fastboot")),
cache: path.join(toolInCache, maybeEXE(thisPlatform, "fastboot"))
},
{
package: path.join(toolInPackage, maybeEXE(thisPlatform, "adb")),
cache: path.join(toolInCache, maybeEXE(thisPlatform, "adb"))
},
{
package: path.join(toolInPackage, maybeEXE(thisPlatform, "mke2fs")),
cache: path.join(toolInCache, maybeEXE(thisPlatform, "mke2fs"))
fs.copy(
path.join(__dirname, "..", "platform-tools", platforms[os.platform()]),
path.join(utils.getUbuntuTouchDir(), 'platform-tools'),
() => {
if (os.platform() !== "win32") {
["adb", "fastboot", "mke2fs"].map(exe => path.join(utils.getUbuntuTouchDir(), 'platform-tools', exe)).forEach((tool) => {
fs.chmodSync(tool, 0o755);
});
}
}
]
);
}

function isSnap() {
Expand Down Expand Up @@ -274,7 +248,7 @@ function downloadFiles(urls, progress, next) {
reject(err);
return;
});
});
}).catch(reject);
});
});
})).then(() => {
Expand Down

0 comments on commit be11080

Please sign in to comment.