From d2e96af3f41339ed34dce7d9b922fd5c274bbbcd Mon Sep 17 00:00:00 2001 From: Jonathan Cubides Date: Tue, 10 Jan 2023 18:08:47 +0100 Subject: [PATCH] Add support for --internal-build-dir option with juvix-mode.internalBuildDir option --- package.json | 7 ++++++- src/config.ts | 23 ++++++++++++++++++++++- src/extension.ts | 1 - src/tasks.ts | 29 ++++++++++++----------------- src/utils/base.ts | 4 +++- test/HelloWorld | Bin 0 -> 26352 bytes test/HelloWorld.juvix | 2 +- 7 files changed, 44 insertions(+), 22 deletions(-) create mode 100755 test/HelloWorld diff --git a/package.json b/package.json index dc8633d..711a621 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "juvix-mode", - "version": "0.1.17", + "version": "0.1.18", "license": "GPL-3.0", "description": "Juvix Mode for VSCode", "displayName": "Juvix", @@ -486,6 +486,11 @@ "noStdlib": { "type": "boolean", "description": "Do not use the standard library" + }, + "internalBuildDir": { + "type": "string", + "default": ".juvix-build", + "description": "Directory for compiler internal output. Empty string will make the compiler use a temporary directory." } }, "additionalProperties": false, diff --git a/src/config.ts b/src/config.ts index 6ea488f..729342a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -5,7 +5,10 @@ 'use strict'; import { serializerWithDefault, VsCodeSetting } from './utils/VsCodeSetting'; +import * as fs from 'fs'; import * as path from 'path'; +import { tmpdir } from 'os'; +import { debugChannel } from './utils/debug'; export class JuvixConfig { readonly binaryName = new VsCodeSetting('juvix-mode.bin.name', { @@ -16,6 +19,7 @@ export class JuvixConfig { serializer: serializerWithDefault(''), }); + public getJuvixExec(): string { return path.join(this.binaryPath.get(), this.binaryName.get()); } @@ -29,7 +33,21 @@ export class JuvixConfig { readonly noTermination = new VsCodeSetting('juvix-mode.opts.noTermination'); readonly noPositivity = new VsCodeSetting('juvix-mode.opts.noPositivity'); readonly noStdlib = new VsCodeSetting('juvix-mode.opts.noStdlib'); - + readonly internalBuildDir = new VsCodeSetting('juvix-mode.opts.internalBuildDir'); + + public getInternalBuildDir(): string { + const buildDir = this.internalBuildDir.get(); + if (buildDir) return buildDir.toString(); + const tmp = path.join(tmpdir(),fs.mkdtempSync('juvix')); + try { + fs.mkdirSync(tmp); + return tmp.toString(); + } catch (e) { + debugChannel.error('Error creating temporary directory: ' + e); + } + return '.juvix-build'; + } + // Dev readonly enableDevTasks = new VsCodeSetting('juvix-mode.enableDevTasks', { serializer: serializerWithDefault(false), @@ -38,6 +56,7 @@ export class JuvixConfig { serializer: serializerWithDefault({}), }); + public getGlobalFlags(): string { const flags = []; if (this.noColors.get()) flags.push('--no-colors'); @@ -46,6 +65,8 @@ export class JuvixConfig { if (this.noTermination.get()) flags.push('--no-termination'); if (this.noPositivity.get()) flags.push('--no-positivity'); if (this.noStdlib.get()) flags.push('--no-stdlib'); + flags.push('--internal-build-dir'); + flags.push(this.getInternalBuildDir()); return flags.join(' ').trim(); } diff --git a/src/extension.ts b/src/extension.ts index cd10166..4d7ac46 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,7 +6,6 @@ import * as vscode from 'vscode'; import { debugChannel } from './utils/debug'; import * as tasks from './tasks'; -import * as user from './config'; import * as statusBar from './statusbar'; import * as syntaxHighlighter from './highlighting'; import * as goToDefinition from './definitions'; diff --git a/src/tasks.ts b/src/tasks.ts index 4a611a6..7d0d764 100644 --- a/src/tasks.ts +++ b/src/tasks.ts @@ -5,9 +5,6 @@ import * as vscode from 'vscode'; import * as user from './config'; import { debugChannel } from './utils/debug'; -import * as fs from 'fs'; -import * as path from 'path'; -import { tmpdir } from 'os'; export const TASK_TYPE = 'Juvix'; @@ -84,14 +81,13 @@ export class JuvixTaskProvider implements vscode.TaskProvider { }, { command: 'typecheck', - args: ['${file}', config.getGlobalFlags()], + args: ['${file}'], group: vscode.TaskGroup.Build, reveal: setupPanel(), }, { command: 'compile', args: [ - config.getGlobalFlags(), config.getCompilationFlags(), '${file}', ], @@ -100,7 +96,7 @@ export class JuvixTaskProvider implements vscode.TaskProvider { }, { command: 'run', - args: ['${file}', config.getGlobalFlags()], + args: ['${file}'], group: vscode.TaskGroup.Build, reveal: vscode.TaskRevealKind.Always, }, @@ -112,13 +108,13 @@ export class JuvixTaskProvider implements vscode.TaskProvider { }, { command: 'dev parse', - args: ['${file}', config.getGlobalFlags()], + args: ['${file}'], group: vscode.TaskGroup.Build, reveal: vscode.TaskRevealKind.Always, }, { command: 'dev scope', - args: ['${file}', config.getGlobalFlags()], + args: ['${file}'], group: vscode.TaskGroup.Build, reveal: vscode.TaskRevealKind.Always, }, @@ -167,23 +163,22 @@ export async function JuvixTask( args: string[] ): Promise { let input = args.join(' ').trim(); - - let exec: vscode.ProcessExecution | vscode.ShellExecution | undefined; const config = new user.JuvixConfig(); + const JuvixExec = [config.getJuvixExec(), config.getGlobalFlags()].join(' '); + let exec: vscode.ProcessExecution | vscode.ShellExecution | undefined; switch (name) { case 'run': input = args.slice(1).join(' ').trim(); - const tmp = path.join(tmpdir(),fs.mkdtempSync('juvix')); - fs.mkdirSync(tmp); + const buildDir = config.getInternalBuildDir(); + exec = new vscode.ShellExecution( - config.getJuvixExec() + - ` compile --output ${tmp}\${pathSeparator}out ${input} && ${tmp}\${pathSeparator}out && rm -rf \${fileDirname}\${pathSeparator}.juvix-build` - , { cwd: tmp} + JuvixExec + + ` compile --output ${buildDir}\${pathSeparator}out ${input} && ${buildDir}\${pathSeparator}out` + , { cwd: buildDir} ); break; default: - const call = config.getJuvixExec() + ` ${input}`; - exec = new vscode.ShellExecution(call); + exec = new vscode.ShellExecution(JuvixExec+ ` ${input}`); break; } return new vscode.Task( diff --git a/src/utils/base.ts b/src/utils/base.ts index 4d784e2..4663f93 100644 --- a/src/utils/base.ts +++ b/src/utils/base.ts @@ -1,4 +1,6 @@ - +/*--------------------------------------------------------- + * Copyright (C) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------*/ import * as vscode from 'vscode'; export function isJuvixFile(document: vscode.TextDocument): boolean { diff --git a/test/HelloWorld b/test/HelloWorld new file mode 100755 index 0000000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H(lfT3Nr9^$o^_$oNe7 zHHcK|_pp8s>n|2TrZUbIxXYz4?^W*b$ltAh4fH?6HxE+&eVqS3SN<4|>EJGZ3@FX5 zi@tmZa+vj71CAcmk)on6@Qs3b5xxxDTNT?z(Oix}qd>!XX zeR=*FWr26ZF)S~7%&Kp?^yQn3C;7plyq=#G-2L|-S-+f(5pg69hg|HC@>%>Rz;_X$ z@{7K_H(72t67M^te0JymB2p^#jYSbHYbOX)?GYXOEgSp^{{T@Rp-`(nt}dqK zM%Qbiw(|#Yv`0(}4)L4Ze<@k&?r1n?gMJtgeo?-$IJ}hG;piPqZT-NFj>K}8f{RuE E1v6ly8~^|S literal 0 HcmV?d00001 diff --git a/test/HelloWorld.juvix b/test/HelloWorld.juvix index 03db0be..49c1771 100644 --- a/test/HelloWorld.juvix +++ b/test/HelloWorld.juvix @@ -1,6 +1,6 @@ module HelloWorld; open import Stdlib.Prelude; main : IO; - main := putStrLn "helloasdf world!"; + main := putStrLn "hello world!"; end; \ No newline at end of file