Skip to content

Commit

Permalink
Move compiling the go utilities from buildMain to postinstall.
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Promislow <epromislow@suse.com>
  • Loading branch information
ericpromislow committed Jul 7, 2023
1 parent 7fd89df commit 8ea0c6d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
23 changes: 12 additions & 11 deletions pkg/rancher-desktop/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,21 @@ function getPaths(): Paths {
let pathsData: Partial<Paths>;

if (rdctlPath) {
const result = spawnSync(rdctlPath, ['paths'], { encoding: 'utf8' });
try {
const result = spawnSync(rdctlPath, ['paths'], { encoding: 'utf8' });

if (result.status !== 0) {
throw new Error(`rdctl paths failed: ${ JSON.stringify(result) }`);
if (!result.status && result.stdout) {
pathsData = JSON.parse(result.stdout);
}
} catch {
}
pathsData = JSON.parse(result.stdout);
} else {
// If rdctl hasn't been compiled yet, we can't use it to get paths.
// Define defaults that assume that we are running a script.
pathsData = {
resources: path.join(process.cwd(), 'resources'),
logs: path.join(process.cwd(), 'script_logs'),
};
}
// If rdctl hasn't been compiled yet, we can't use it to get paths.
// Define defaults that assume that we are running a script.
pathsData ??= {
resources: path.join(process.cwd(), 'resources'),
logs: path.join(process.cwd(), 'script_logs'),
};

switch (process.platform) {
case 'darwin':
Expand Down
9 changes: 8 additions & 1 deletion scripts/lib/build-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,14 @@ export default {
* Build the main process code.
*/
buildMain(): Promise<void> {
const tasks = [() => this.buildJavaScript(this.webpackConfig)];
return this.wait(() => this.buildJavaScript(this.webpackConfig));
},

/**
* Build the things we build with go
*/
buildGoUtilities(): Promise<void> {
const tasks = [];

if (os.platform().startsWith('win')) {
tasks.push(() => this.buildWSLHelper());
Expand Down
3 changes: 3 additions & 0 deletions scripts/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import fs from 'fs';
import os from 'os';
import path from 'path';

import buildUtils from './lib/build-utils';

import { spawnFile } from '@pkg/utils/childProcess';
import { LimaAndQemu, AlpineLimaISO } from 'scripts/dependencies/lima';
import { MobyOpenAPISpec } from 'scripts/dependencies/moby-openapi';
Expand Down Expand Up @@ -129,6 +131,7 @@ const keepScriptAlive = setTimeout(() => { }, 24 * 3600 * 1000);
'pkg/rancher-desktop/assets/specs/command-api.yaml',
'src/go/rdctl/pkg/options/generated/options.go'],
{ stdio: 'inherit' });
await buildUtils.buildGoUtilities();
exitCode = 0;
} catch (e: any) {
console.error('POSTINSTALL ERROR: ', e);
Expand Down

0 comments on commit 8ea0c6d

Please sign in to comment.