From c7cfa37a641a19e0949ca655bc20263e15e9d6f1 Mon Sep 17 00:00:00 2001 From: Rahul Yadav Date: Fri, 28 Jun 2024 17:51:52 +0530 Subject: [PATCH 01/19] Enhance error handling to support third-party tools - Replaced consoleLogger with the new Logger - Removed jest mock where consoleLogger was used - Improved support for third-party tools --- bin/tact | 4 +- scripts/prepare.ts | 14 +-- src/browser.ts | 12 ++- src/func/funcCompile.spec.ts | 4 +- src/func/funcCompile.ts | 7 +- src/logger.ts | 92 ++++++++++++++++-- src/node.ts | 32 ++++-- src/pipeline/build.ts | 97 +++++++++++-------- .../const-eval-failed.spec.ts | 14 --- .../compilation-failed/stdlib-bugs.spec.ts | 14 --- src/test/compilation-failed/util.ts | 9 +- src/test/e2e-emulated/address.spec.ts | 12 --- src/verify.ts | 10 +- 13 files changed, 194 insertions(+), 127 deletions(-) diff --git a/bin/tact b/bin/tact index f55ac6d1c..13a39f243 100755 --- a/bin/tact +++ b/bin/tact @@ -165,9 +165,9 @@ meowModule.then( projectNames: cli.flags.projects ?? [], additionalCliOptions: { mode }, }) - .then((success) => { + .then((response) => { // https://nodejs.org/docs/v20.12.1/api/process.html#exit-codes - process.exit(success ? 0 : 30); + process.exit(response.ok ? 0 : 30); }); }, ); diff --git a/scripts/prepare.ts b/scripts/prepare.ts index 13fed6367..d487006f0 100644 --- a/scripts/prepare.ts +++ b/scripts/prepare.ts @@ -5,7 +5,7 @@ import { FuncCompilationResult, funcCompile } from "../src/func/funcCompile"; import path from "path"; import { glob } from "glob"; import { verify } from "../src/verify"; -import { consoleLogger } from "../src/logger"; +import { Logger } from "../src/logger"; import { __DANGER__disableVersionNumber } from "../src/pipeline/version"; // Read cases @@ -13,8 +13,10 @@ import { __DANGER__disableVersionNumber } from "../src/pipeline/version"; // Disable version number in packages __DANGER__disableVersionNumber(); + const logger = new Logger(); + // Compile projects - if (!(await run({ configPath: __dirname + "/../tact.config.json" }))) { + if (!(await run({ configPath: __dirname + "/../tact.config.json" })).ok) { console.error("Tact projects compilation failed"); process.exit(1); } @@ -64,15 +66,15 @@ import { __DANGER__disableVersionNumber } from "../src/pipeline/version"; content: code, }, ], - logger: consoleLogger, + logger: logger, }); if (!c.ok) { - console.error(c.log); + logger.error(c.log); process.exit(1); } } catch (e) { - console.error(e); - console.error("Failed"); + logger.error(e as Error); + logger.error("Failed"); process.exit(1); } fs.writeFileSync(p.path + r + ".fift", c.fift!); diff --git a/src/browser.ts b/src/browser.ts index 5dd218640..cc2678caf 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -1,12 +1,12 @@ import { Config, verifyConfig } from "./config/parseConfig"; -import { TactLogger } from "./logger"; +import { Logger } from "./logger"; import { build } from "./pipeline/build"; import { createVirtualFileSystem } from "./vfs/createVirtualFileSystem"; export async function run(args: { config: Config; files: { [key: string]: string }; - logger?: TactLogger | null | undefined; + logger?: Logger | null | undefined; }) { // Verify config const config = verifyConfig(args.config); @@ -19,6 +19,7 @@ export async function run(args: { // Compile let success = true; + let errorCollection: Error[] = []; for (const p of config.projects) { const built = await build({ config: p, @@ -26,7 +27,10 @@ export async function run(args: { stdlib, logger: args.logger, }); - success = success && built; + success = success && built.ok; + if (!built.ok && built.error) { + errorCollection = { ...errorCollection, ...built.error }; + } } - return success; + return { ok: success, error: errorCollection }; } diff --git a/src/func/funcCompile.spec.ts b/src/func/funcCompile.spec.ts index e8661f8af..60e937b10 100644 --- a/src/func/funcCompile.spec.ts +++ b/src/func/funcCompile.spec.ts @@ -1,6 +1,6 @@ import fs from "fs"; import path from "path"; -import { consoleLogger } from "../logger"; +import { Logger } from "../logger"; import { funcCompile } from "./funcCompile"; import files from "../imports/stdlib"; @@ -22,7 +22,7 @@ describe("funcCompile", () => { }, { path: "/small.fc", content: source }, ], - logger: consoleLogger, + logger: new Logger(), }); expect(res.ok).toBe(true); }); diff --git a/src/func/funcCompile.ts b/src/func/funcCompile.ts index f0809d6b7..005e3d5c6 100644 --- a/src/func/funcCompile.ts +++ b/src/func/funcCompile.ts @@ -1,5 +1,4 @@ -import { TactLogger } from "../logger"; -import { errorToString } from "../utils/errorToString"; +import { Logger } from "../logger"; // Wasm Imports // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -60,7 +59,7 @@ type CompileResult = export async function funcCompile(args: { entries: string[]; sources: { path: string; content: string }[]; - logger: TactLogger; + logger: Logger; }): Promise { // Parameters const files: string[] = args.entries; @@ -180,7 +179,7 @@ export async function funcCompile(args: { throw Error("Unexpected compiler response"); } } catch (e) { - args.logger.error(errorToString(e)); + args.logger.error(e as Error); throw Error("Unexpected compiler response"); } finally { for (const i of allocatedFunctions) { diff --git a/src/logger.ts b/src/logger.ts index f50888ee6..62803512e 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,9 +1,87 @@ -export type TactLogger = { - log: (message: string) => void; - error: (message: string) => void; -}; +export enum LogLevel { + /** Logging is turned off */ + NONE, + /** Logs only error messages */ + ERROR, + /** Logs warning and error messages */ + WARN, + /** Logs informational, warning, and error messages */ + INFO, + /** Logs debugging, informational, warning, and error messages */ + DEBUG, +} + +type messageType = string | Error; -export const consoleLogger: TactLogger = { - log: console.log, - error: console.error, +export interface LogMethods { + debug: (message: messageType) => void; + info: (message: messageType) => void; + warn: (message: messageType) => void; + error: (message: messageType) => void; +} + +const logLevelToMethodName: { [key in LogLevel]: keyof LogMethods | null } = { + [LogLevel.NONE]: null, + [LogLevel.ERROR]: "error", + [LogLevel.WARN]: "warn", + [LogLevel.INFO]: "info", + [LogLevel.DEBUG]: "debug", }; + +function getLoggingMethod(level: LogLevel): keyof LogMethods | null { + return logLevelToMethodName[level]; +} + +export class Logger { + private level: LogLevel; + private logMethods: LogMethods; + + constructor(level: LogLevel = LogLevel.INFO) { + this.level = level; + this.logMethods = { + debug: console.log, + info: console.log, + warn: console.warn, + error: console.error, + }; + } + + protected log(level: LogLevel, message: messageType) { + if (this.level === LogLevel.NONE) { + return; + } + + if (message instanceof Error) { + message = message.stack || message.message; + } else { + message = "" + message.toString(); + } + + if (level > this.level) return; + + const loggingMethod = getLoggingMethod(level); + if (!loggingMethod) return; + + this.logMethods[loggingMethod](message); + } + + debug(message: messageType) { + this.log(LogLevel.DEBUG, message); + } + + info(message: messageType) { + this.log(LogLevel.INFO, message); + } + + warn(message: messageType) { + this.log(LogLevel.WARN, message); + } + + error(message: messageType) { + this.log(LogLevel.ERROR, message); + } + + setLevel(level: LogLevel) { + this.level = level; + } +} diff --git a/src/node.ts b/src/node.ts index 8e5338080..aba2842d4 100644 --- a/src/node.ts +++ b/src/node.ts @@ -3,7 +3,7 @@ import fs from "fs"; import { ConfigProject, Config, parseConfig } from "./config/parseConfig"; import { createNodeFileSystem } from "./vfs/createNodeFileSystem"; import { build } from "./pipeline/build"; -import { consoleLogger } from "./logger"; +import { LogLevel, Logger } from "./logger"; type AdditionalCliOptions = { mode?: ConfigProject["mode"]; @@ -64,20 +64,27 @@ export async function run(args: { configPath?: string; projectNames?: string[]; additionalCliOptions?: AdditionalCliOptions; + suppressLog?: boolean; }) { const configWithRootPath = await loadConfig(args.fileName, args.configPath); if (!configWithRootPath) { - return false; + return { ok: false, error: [new Error("Unable to load config")] }; } + const logger = new Logger(args.suppressLog ? LogLevel.NONE : LogLevel.INFO); + // Resolve projects let projects = configWithRootPath.projects; if (args.projectNames && args.projectNames.length > 0) { // Check that all project names are valid for (const pp of args.projectNames) { if (!projects.find((v) => v.name === pp)) { - console.warn("Unable to find project " + pp); - return false; + const message = "Unable to find project " + pp; + logger.warn(message); + return { + ok: false, + error: [new Error(message)], + }; } } @@ -85,12 +92,14 @@ export async function run(args: { projects = projects.filter((v) => args.projectNames!.includes(v.name)); } if (projects.length === 0) { - console.warn("No projects to compile"); - return false; + const message = "No projects to compile"; + console.warn(message); + return { ok: false, error: [new Error(message)] }; } // Compile let success = true; + let errorMessages: Error[] = []; const project = createNodeFileSystem( configWithRootPath.rootPath as string, false, @@ -100,7 +109,7 @@ export async function run(args: { false, ); // Improves developer experience for (const config of projects) { - consoleLogger.log("💼 Compiling project " + config.name + "..."); + logger.info("💼 Compiling project " + config.name + "..."); let cliConfig = { ...config }; if ( @@ -114,11 +123,14 @@ export async function run(args: { config: cliConfig, project, stdlib, - logger: consoleLogger, + logger, }); - success = success && built; + success = success && built.ok; + if (!built.ok && built.error && built.error.length > 0) { + errorMessages = [...errorMessages, ...built.error]; + } } - return success; + return { ok: success, error: errorMessages }; } export { createNodeFileSystem } from "./vfs/createNodeFileSystem"; diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index c99bfdd51..5215c9d68 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -8,12 +8,11 @@ import { funcCompile } from "../func/funcCompile"; import { writeReport } from "../generator/writeReport"; import { getRawAST } from "../grammar/store"; import files from "../imports/stdlib"; -import { consoleLogger, TactLogger } from "../logger"; +import { Logger } from "../logger"; import { PackageFileFormat } from "../packaging/fileFormat"; import { packageCode } from "../packaging/packageCode"; import { createABITypeRefFromTypeRef } from "../types/resolveABITypeRef"; import { getContracts, getType } from "../types/resolveDescriptors"; -import { errorToString } from "../utils/errorToString"; import { posixNormalize } from "../utils/filePath"; import { createVirtualFileSystem } from "../vfs/createVirtualFileSystem"; import { VirtualFileSystem } from "../vfs/VirtualFileSystem"; @@ -25,14 +24,14 @@ export async function build(args: { config: ConfigProject; project: VirtualFileSystem; stdlib: string | VirtualFileSystem; - logger?: TactLogger | null | undefined; -}) { + logger?: Logger | null | undefined; +}): Promise<{ ok: boolean; error: Error[] }> { const { config, project } = args; const stdlib = typeof args.stdlib === "string" ? createVirtualFileSystem(args.stdlib, files) : args.stdlib; - const logger: TactLogger = args.logger || consoleLogger; + const logger: Logger = args.logger || new Logger(); // Configure context let ctx: CompilerContext = new CompilerContext({ shared: {} }); @@ -68,17 +67,18 @@ export async function build(args: { ? "Syntax and type checking failed" : "Tact compilation failed", ); - logger.error(errorToString(e)); - return false; + logger.error(e as Error); + return { ok: false, error: [e as Error] }; } if (config.mode === "checkOnly") { - logger.log("✔️ Syntax and type checking succeeded."); - return true; + logger.info("✔️ Syntax and type checking succeeded."); + return { ok: true, error: [] }; } // Compile contracts let ok = true; + const errorMessages: Error[] = []; const built: { [key: string]: { codeBoc: Buffer; @@ -110,7 +110,7 @@ export async function build(args: { let codeEntrypoint: string; // Compiling contract to func - logger.log(" > " + contract + ": tact compiler"); + logger.info(" > " + contract + ": tact compiler"); let abi: string; try { const res = await compile( @@ -131,8 +131,9 @@ export async function build(args: { codeEntrypoint = res.output.entrypoint; } catch (e) { logger.error("Tact compilation failed"); - logger.error(errorToString(e)); + logger.error(e as Error); ok = false; + errorMessages.push(e as Error); continue; } @@ -141,7 +142,7 @@ export async function build(args: { } // Compiling contract to TVM - logger.log(" > " + contract + ": func compiler"); + logger.info(" > " + contract + ": func compiler"); let codeBoc: Buffer; try { const stdlibPath = stdlib.resolve("stdlib.fc"); @@ -172,6 +173,7 @@ export async function build(args: { if (!c.ok) { logger.error(c.log); ok = false; + errorMessages.push(new Error(c.log)); continue; } project.writeFile(pathCodeFif, c.fift); @@ -179,8 +181,9 @@ export async function build(args: { codeBoc = c.output; } catch (e) { logger.error("FunC compiler crashed"); - logger.error(errorToString(e)); + logger.error(e as Error); ok = false; + errorMessages.push(e as Error); continue; } @@ -192,39 +195,42 @@ export async function build(args: { if (config.mode === "fullWithDecompilation") { // Fift decompiler for generated code debug - logger.log(" > " + contract + ": fift decompiler"); + logger.info(" > " + contract + ": fift decompiler"); let codeFiftDecompiled: string; try { codeFiftDecompiled = decompileAll({ src: codeBoc }); project.writeFile(pathCodeFifDec, codeFiftDecompiled); } catch (e) { logger.error("Fift decompiler crashed"); - logger.error(errorToString(e)); + logger.error(e as Error); ok = false; + errorMessages.push(e as Error); continue; } } } if (!ok) { - logger.log("💥 Compilation failed. Skipping packaging"); - return false; + logger.info("💥 Compilation failed. Skipping packaging"); + return { ok: false, error: errorMessages }; } if (config.mode === "funcOnly") { - logger.log("✔️ FunC code generation succeeded."); - return true; + logger.info("✔️ FunC code generation succeeded."); + return { ok: true, error: errorMessages }; } // Package - logger.log(" > Packaging"); + logger.info(" > Packaging"); const contracts = getContracts(ctx); const packages: PackageFileFormat[] = []; for (const contract of contracts) { - logger.log(" > " + contract); + logger.info(" > " + contract); const artifacts = built[contract]; if (!artifacts) { - logger.error(" > " + contract + ": no artifacts found"); - return false; + const message = " > " + contract + ": no artifacts found"; + logger.error(message); + errorMessages.push(new Error(message)); + return { ok: false, error: errorMessages }; } // System cell @@ -237,8 +243,10 @@ export async function build(args: { for (const c of ct.dependsOn) { const cd = built[c.name]; if (!cd) { - logger.error(" > " + cd + ": no artifacts found"); - return false; + const message = " > " + cd + ": no artifacts found"; + logger.error(message); + errorMessages.push(new Error(message)); + return { ok: false, error: errorMessages }; } depends.set(c.uid, Cell.fromBoc(cd.codeBoc)[0]); } @@ -298,17 +306,18 @@ export async function build(args: { } // Bindings - logger.log(" > Bindings"); + logger.info(" > Bindings"); for (const pkg of packages) { - logger.log(" > " + pkg.name); + logger.info(" > " + pkg.name); if (pkg.init.deployment.kind !== "system-cell") { - logger.error( + const message = " > " + - pkg.name + - ": unsupported deployment kind " + - pkg.init.deployment.kind, - ); - return false; + pkg.name + + ": unsupported deployment kind " + + pkg.init.deployment.kind; + logger.error(message); + errorMessages.push(new Error(message)); + return { ok: false, error: errorMessages }; } try { const bindingsServer = writeTypescript(JSON.parse(pkg.abi), { @@ -325,16 +334,18 @@ export async function build(args: { bindingsServer, ); } catch (e) { - logger.error("Bindings compiler crashed"); - logger.error(errorToString(e)); - return false; + const message = "Bindings compiler crashed"; + logger.error(message); + logger.error(e as Error); + errorMessages.push(new Error(message)); + return { ok: false, error: errorMessages }; } } // Reports - logger.log(" > Reports"); + logger.info(" > Reports"); for (const pkg of packages) { - logger.log(" > " + pkg.name); + logger.info(" > " + pkg.name); try { const report = writeReport(ctx, pkg); const pathBindings = project.resolve( @@ -343,11 +354,13 @@ export async function build(args: { ); project.writeFile(pathBindings, report); } catch (e) { - logger.error("Report generation crashed"); - logger.error(errorToString(e)); - return false; + const message = "Report generation crashed"; + logger.error(message); + logger.error(e as Error); + errorMessages.push(new Error(message)); + return { ok: false, error: errorMessages }; } } - return true; + return { ok: true, error: [] }; } diff --git a/src/test/compilation-failed/const-eval-failed.spec.ts b/src/test/compilation-failed/const-eval-failed.spec.ts index eefcd3ba3..245d868bf 100644 --- a/src/test/compilation-failed/const-eval-failed.spec.ts +++ b/src/test/compilation-failed/const-eval-failed.spec.ts @@ -1,25 +1,11 @@ import { __DANGER_resetNodeId } from "../../grammar/ast"; -import { consoleLogger } from "../../logger"; import { itShouldNotCompile } from "./util"; describe("fail-const-eval", () => { - beforeAll(() => { - jest.spyOn(consoleLogger, "error").mockImplementation(() => {}); - jest.spyOn(consoleLogger, "log").mockImplementation(() => {}); - }); - beforeEach(() => { __DANGER_resetNodeId(); }); - afterAll(() => { - jest.restoreAllMocks(); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); - itShouldNotCompile({ testName: "const-eval-div-by-zero", errorMessage: diff --git a/src/test/compilation-failed/stdlib-bugs.spec.ts b/src/test/compilation-failed/stdlib-bugs.spec.ts index 7659947e7..da8cc72e6 100644 --- a/src/test/compilation-failed/stdlib-bugs.spec.ts +++ b/src/test/compilation-failed/stdlib-bugs.spec.ts @@ -1,25 +1,11 @@ import { __DANGER_resetNodeId } from "../../grammar/ast"; -import { consoleLogger } from "../../logger"; import { itShouldNotCompile } from "./util"; describe("stdlib-bugs", () => { - beforeAll(() => { - jest.spyOn(consoleLogger, "error").mockImplementation(() => {}); - jest.spyOn(consoleLogger, "log").mockImplementation(() => {}); - }); - beforeEach(() => { __DANGER_resetNodeId(); }); - afterAll(() => { - jest.restoreAllMocks(); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); - itShouldNotCompile({ testName: "stdlib-skipBits", errorMessage: 'Type mismatch: "" is not assignable to "Slice"', diff --git a/src/test/compilation-failed/util.ts b/src/test/compilation-failed/util.ts index 9c91d5067..6369d5906 100644 --- a/src/test/compilation-failed/util.ts +++ b/src/test/compilation-failed/util.ts @@ -1,5 +1,4 @@ import { run } from "../../node"; -import { consoleLogger } from "../../logger"; // helper to reduce boilerplate export function itShouldNotCompile(params: { @@ -10,10 +9,10 @@ export function itShouldNotCompile(params: { const result = await run({ configPath: __dirname + "/tact.config.json", projectNames: [`${params.testName}`], + suppressLog: true, }); - expect(result).toBe(false); - expect((consoleLogger.error as jest.Mock).mock.lastCall[0]).toContain( - params.errorMessage, - ); + expect(result.ok).toBe(false); + const message = result.error.map((err) => err.message).join("; "); + expect(message).toContain(params.errorMessage); }); } diff --git a/src/test/e2e-emulated/address.spec.ts b/src/test/e2e-emulated/address.spec.ts index dc19a42f0..9cd828551 100644 --- a/src/test/e2e-emulated/address.spec.ts +++ b/src/test/e2e-emulated/address.spec.ts @@ -2,24 +2,12 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; import { __DANGER_resetNodeId } from "../../grammar/ast"; import { AddressTester } from "./contracts/output/address_AddressTester"; -import { consoleLogger } from "../../logger"; describe("address", () => { - beforeAll(() => { - jest.spyOn(consoleLogger, "error").mockImplementation(() => {}); - }); - beforeEach(() => { __DANGER_resetNodeId(); }); - afterAll(() => { - (consoleLogger.error as jest.Mock).mockRestore(); - }); - - afterEach(() => { - (consoleLogger.error as jest.Mock).mockClear(); - }); it("should implement addresses correctly", async () => { // Init const system = await ContractSystem.create(); diff --git a/src/verify.ts b/src/verify.ts index 6f05c1c15..57aaefaed 100644 --- a/src/verify.ts +++ b/src/verify.ts @@ -1,8 +1,8 @@ import normalize from "path-normalize"; import { Cell } from "@ton/core"; import { Config, Options } from "./config/parseConfig"; -import { consoleLogger } from "./logger"; -import { PackageFileFormat, run, TactLogger } from "./main"; +import { Logger } from "./logger"; +import { PackageFileFormat, run } from "./main"; import { fileFormat } from "./packaging/fileFormat"; import { getCompilerVersion } from "./pipeline/version"; @@ -24,9 +24,9 @@ export type VerifyResult = export async function verify(args: { pkg: string; - logger?: TactLogger | null | undefined; + logger?: Logger | null | undefined; }): Promise { - const logger = args.logger || consoleLogger; + const logger = args.logger || new Logger(); // Loading package let unpacked: PackageFileFormat; @@ -75,7 +75,7 @@ export async function verify(args: { } const result = await run({ config, files, logger }); - if (!result) { + if (!result.ok) { return { ok: false, error: "compilation-failed" }; } From 17ce414d226f97e64625638e3c203a92b3e5731b Mon Sep 17 00:00:00 2001 From: Rahul Yadav Date: Fri, 28 Jun 2024 18:30:12 +0530 Subject: [PATCH 02/19] fix: remove unused consoleLogger and jest mocks --- .../contract-duplicate-opcodes.spec.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/test/compilation-failed/contract-duplicate-opcodes.spec.ts b/src/test/compilation-failed/contract-duplicate-opcodes.spec.ts index 98595eb4c..a799e930c 100644 --- a/src/test/compilation-failed/contract-duplicate-opcodes.spec.ts +++ b/src/test/compilation-failed/contract-duplicate-opcodes.spec.ts @@ -1,25 +1,11 @@ import { __DANGER_resetNodeId } from "../../grammar/ast"; -import { consoleLogger } from "../../logger"; import { itShouldNotCompile } from "./util"; describe("contract-duplicate-opcodes", () => { - beforeAll(() => { - jest.spyOn(consoleLogger, "error").mockImplementation(() => {}); - jest.spyOn(consoleLogger, "log").mockImplementation(() => {}); - }); - beforeEach(() => { __DANGER_resetNodeId(); }); - afterAll(() => { - jest.restoreAllMocks(); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); - itShouldNotCompile({ testName: "contract-duplicate-bounced-opcode", errorMessage: From a457c8184c6071922eb856e255c1516414e28374 Mon Sep 17 00:00:00 2001 From: Rahul Yadav Date: Wed, 3 Jul 2024 16:03:08 +0530 Subject: [PATCH 03/19] Add TactErrorCollection type --- src/errors.ts | 7 +++++++ src/node.ts | 3 ++- src/pipeline/build.ts | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/errors.ts b/src/errors.ts index cfb0bf01a..f5457e795 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -104,3 +104,10 @@ export function idTextErr(ident: AstId | string): string { } return `"${ident.text}"`; } + +export type TactErrorCollection = + | Error + | TactParseError + | TactCompilationError + | TactInternalCompilerError + | TactConstEvalError; diff --git a/src/node.ts b/src/node.ts index 1549e83b6..a828f3314 100644 --- a/src/node.ts +++ b/src/node.ts @@ -4,6 +4,7 @@ import { ConfigProject, Config, parseConfig } from "./config/parseConfig"; import { createNodeFileSystem } from "./vfs/createNodeFileSystem"; import { build } from "./pipeline/build"; import { LogLevel, Logger } from "./logger"; +import { TactErrorCollection } from "./errors"; type AdditionalCliOptions = { mode?: ConfigProject["mode"]; @@ -99,7 +100,7 @@ export async function run(args: { // Compile let success = true; - let errorMessages: Error[] = []; + let errorMessages: TactErrorCollection[] = []; const project = createNodeFileSystem( configWithRootPath.rootPath as string, false, diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index 2fd6b1eec..7b39c3dea 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -20,13 +20,14 @@ import { compile } from "./compile"; import { precompile } from "./precompile"; import { getCompilerVersion } from "./version"; import { idText } from "../grammar/ast"; +import { TactErrorCollection } from "../errors"; export async function build(args: { config: ConfigProject; project: VirtualFileSystem; stdlib: string | VirtualFileSystem; logger?: Logger | null | undefined; -}): Promise<{ ok: boolean; error: Error[] }> { +}): Promise<{ ok: boolean; error: TactErrorCollection[] }> { const { config, project } = args; const stdlib = typeof args.stdlib === "string" @@ -79,7 +80,7 @@ export async function build(args: { // Compile contracts let ok = true; - const errorMessages: Error[] = []; + const errorMessages: TactErrorCollection[] = []; const built: { [key: string]: { codeBoc: Buffer; From 302905316018bda23a8256e309e9a41dd0e7c5b4 Mon Sep 17 00:00:00 2001 From: Rahul Yadav Date: Fri, 5 Jul 2024 10:44:00 +0530 Subject: [PATCH 04/19] Address review comments --- scripts/prepare.ts | 134 +++++++++++++++++++++++------------------- src/browser.ts | 2 +- src/logger.ts | 2 +- src/node.ts | 9 ++- src/pipeline/build.ts | 20 +++---- 5 files changed, 92 insertions(+), 75 deletions(-) diff --git a/scripts/prepare.ts b/scripts/prepare.ts index d487006f0..f5838706a 100644 --- a/scripts/prepare.ts +++ b/scripts/prepare.ts @@ -15,74 +15,84 @@ import { __DANGER__disableVersionNumber } from "../src/pipeline/version"; const logger = new Logger(); - // Compile projects - if (!(await run({ configPath: __dirname + "/../tact.config.json" })).ok) { - console.error("Tact projects compilation failed"); - process.exit(1); - } - - // Verify projects - for (const pkgPath of glob.sync( - path.normalize( - path.resolve(__dirname, "..", "examples", "output", "*.pkg"), - ), - )) { - const res = await verify({ pkg: fs.readFileSync(pkgPath, "utf-8") }); - if (!res.ok) { - console.error("Failed to verify " + pkgPath + ": " + res.error); - process.exit(1); + try { + // Compile projects + const compileResult = await run({ + configPath: path.join(__dirname, "../tact.config.json"), + }); + if (!compileResult.ok) { + throw new Error("Tact projects compilation failed"); } - } - // Compile func files - for (const p of [{ path: __dirname + "/../func/" }]) { - const recs = fs.readdirSync(p.path); - for (const r of recs) { - if (!r.endsWith(".fc")) { - continue; + // Verify projects + for (const pkgPath of glob.sync( + path.normalize( + path.resolve(__dirname, "..", "examples", "output", "*.pkg"), + ), + )) { + const res = await verify({ + pkg: fs.readFileSync(pkgPath, "utf-8"), + }); + if (!res.ok) { + throw new Error(`Failed to verify ${pkgPath}: ${res.error}`); } + } - // Precompile - console.log("Processing " + p.path + r); - let c: FuncCompilationResult; - try { - const stdlibPath = path.resolve( - __dirname, - "..", - "stdlib", - "stdlib.fc", - ); - const stdlib = fs.readFileSync(stdlibPath, "utf-8"); - const code = fs.readFileSync(p.path + r, "utf-8"); - c = await funcCompile({ - entries: [stdlibPath, p.path + r], - sources: [ - { - path: stdlibPath, - content: stdlib, - }, - { - path: p.path + r, - content: code, - }, - ], - logger: logger, - }); - if (!c.ok) { - logger.error(c.log); - process.exit(1); + // Compile func files + for (const p of [{ path: path.join(__dirname, "/../func/") }]) { + const recs = fs.readdirSync(p.path); + for (const r of recs) { + if (!r.endsWith(".fc")) { + continue; } - } catch (e) { - logger.error(e as Error); - logger.error("Failed"); - process.exit(1); - } - fs.writeFileSync(p.path + r + ".fift", c.fift!); - fs.writeFileSync(p.path + r + ".cell", c.output!); - // Cell -> Fift decompiler - const source = decompileAll({ src: c.output! }); - fs.writeFileSync(p.path + r + ".rev.fift", source); + // Precompile + logger.info(`Processing ${path.join(p.path + r)}`); + let c: FuncCompilationResult; + try { + const stdlibPath = path.resolve( + __dirname, + "..", + "stdlib", + "stdlib.fc", + ); + const stdlib = fs.readFileSync(stdlibPath, "utf-8"); + const code = fs.readFileSync(p.path + r, "utf-8"); + c = await funcCompile({ + entries: [stdlibPath, p.path + r], + sources: [ + { + path: stdlibPath, + content: stdlib, + }, + { + path: p.path + r, + content: code, + }, + ], + logger: logger, + }); + if (!c.ok) { + logger.error(c.log); + throw new Error( + `FunC compilation failed for ${path.join(p.path, r)}`, + ); + } + } catch (e) { + logger.error(e as Error); + logger.error(`Failed for ${path.join(p.path, r)}`); + throw e; + } + fs.writeFileSync(p.path + r + ".fift", c.fift!); + fs.writeFileSync(p.path + r + ".cell", c.output!); + + // Cell -> Fift decompiler + const source = decompileAll({ src: c.output! }); + fs.writeFileSync(p.path + r + ".rev.fift", source); + } } + } catch (error) { + logger.error(error as Error); + process.exit(1); } })(); diff --git a/src/browser.ts b/src/browser.ts index cc2678caf..146e734e0 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -6,7 +6,7 @@ import { createVirtualFileSystem } from "./vfs/createVirtualFileSystem"; export async function run(args: { config: Config; files: { [key: string]: string }; - logger?: Logger | null | undefined; + logger?: Logger; }) { // Verify config const config = verifyConfig(args.config); diff --git a/src/logger.ts b/src/logger.ts index 62803512e..76bb998d1 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -54,7 +54,7 @@ export class Logger { if (message instanceof Error) { message = message.stack || message.message; } else { - message = "" + message.toString(); + message = message.toString(); } if (level > this.level) return; diff --git a/src/node.ts b/src/node.ts index a828f3314..5c415b1b9 100644 --- a/src/node.ts +++ b/src/node.ts @@ -69,7 +69,14 @@ export async function run(args: { }) { const configWithRootPath = await loadConfig(args.fileName, args.configPath); if (!configWithRootPath) { - return { ok: false, error: [new Error("Unable to load config")] }; + return { + ok: false, + error: [ + new Error( + `Unable to load config from path: ${args.configPath}`, + ), + ], + }; } const logger = new Logger(args.suppressLog ? LogLevel.NONE : LogLevel.INFO); diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index 7b39c3dea..dc13677d9 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -26,7 +26,7 @@ export async function build(args: { config: ConfigProject; project: VirtualFileSystem; stdlib: string | VirtualFileSystem; - logger?: Logger | null | undefined; + logger?: Logger; }): Promise<{ ok: boolean; error: TactErrorCollection[] }> { const { config, project } = args; const stdlib = @@ -112,7 +112,7 @@ export async function build(args: { let codeEntrypoint: string; // Compiling contract to func - logger.info(" > " + contract + ": tact compiler"); + logger.info(` > ${contract}: tact compiler`); let abi: string; try { const res = await compile( @@ -336,10 +336,10 @@ export async function build(args: { bindingsServer, ); } catch (e) { - const message = "Bindings compiler crashed"; - logger.error(message); - logger.error(e as Error); - errorMessages.push(new Error(message)); + const error = e as Error; + error.message = `Bindings compiler crashed, ${error.message}`; + logger.error(error); + errorMessages.push(error); return { ok: false, error: errorMessages }; } } @@ -356,10 +356,10 @@ export async function build(args: { ); project.writeFile(pathBindings, report); } catch (e) { - const message = "Report generation crashed"; - logger.error(message); - logger.error(e as Error); - errorMessages.push(new Error(message)); + const error = e as Error; + error.message = `Report generation crashed, ${error.message}`; + logger.error(error); + errorMessages.push(error); return { ok: false, error: errorMessages }; } } From 6d7e69f02a756bbd5b9bc361ebe13bc547d9dbb6 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:13:33 +0200 Subject: [PATCH 05/19] feat: add `-q`/`--quiet` flags to suppress compiler log output --- bin/tact | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/tact b/bin/tact index 13a39f243..85d37019a 100755 --- a/bin/tact +++ b/bin/tact @@ -16,6 +16,7 @@ meowModule.then( Flags -c, --config CONFIG Specify path to config file (tact.config.json) -p, --project ...names Build only the specified project name(s) from the config file + -q, --quiet Suppress compiler log output --with-decompilation Full compilation followed by decompilation of produced binary code --func Output intermediate FunC code and exit --check Perform syntax and type checking, then exit @@ -51,14 +52,12 @@ meowModule.then( ); }, }, - eval: { - shortFlag: "e", - type: "string", - }, projects: { shortFlag: "p", type: "string", isMultiple: true }, + quiet: { shortFlag: "q", type: "boolean", default: false }, withDecompilation: { type: "boolean", default: false }, func: { type: "boolean", default: false }, check: { type: "boolean", default: false }, + eval: { shortFlag: "e", type: "string" }, version: { shortFlag: "v", type: "boolean" }, help: { shortFlag: "h", type: "boolean" }, }, @@ -164,6 +163,7 @@ meowModule.then( configPath: cli.flags.config, projectNames: cli.flags.projects ?? [], additionalCliOptions: { mode }, + suppressLog: cli.flags.quiet }) .then((response) => { // https://nodejs.org/docs/v20.12.1/api/process.html#exit-codes From 4e96bbdfcb21e4aa76fd8e07d0cbb757cc2127a9 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:14:01 +0200 Subject: [PATCH 06/19] chore: CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20555fc91..f0b639e21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `-e` / `--eval` CLI flags to evaluate constant Tact expressions: PR [#462](https://github.com/tact-lang/tact/pull/462) +- `-q` / `--quiet` CLI flags to suppress compiler log output: PR [#509](https://github.com/tact-lang/tact/pull/509) ### Changed @@ -34,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Error message for duplicate receiver definitions inherited from traits: PR [#519](https://github.com/tact-lang/tact/issues/519) - Usage of `initOf` inside of `init()` does not cause error `135` anymore: PR [#521](https://github.com/tact-lang/tact/issues/521) - Usage of `newAddress` with hash parts shorter than 64 hexadecimal digits does not cause constant evaluation error `Invalid address hash length` anymore: PR [#525](https://github.com/tact-lang/tact/pull/525) +- Introduced a streamlined error logger for compilation pipeline to support third-party tools: PR [#509](https://github.com/tact-lang/tact/pull/509) ## [1.4.0] - 2024-06-21 From d8d1d2b6d4a0641ae5355137b4bcb50a8baff421 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:16:37 +0200 Subject: [PATCH 07/19] chore: formatting --- bin/tact | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/tact b/bin/tact index 85d37019a..92515b43a 100755 --- a/bin/tact +++ b/bin/tact @@ -163,7 +163,7 @@ meowModule.then( configPath: cli.flags.config, projectNames: cli.flags.projects ?? [], additionalCliOptions: { mode }, - suppressLog: cli.flags.quiet + suppressLog: cli.flags.quiet, }) .then((response) => { // https://nodejs.org/docs/v20.12.1/api/process.html#exit-codes From 0bb4e92f39a73751fcf89c38606aadbc9d7a9a9a Mon Sep 17 00:00:00 2001 From: Anton Trunov Date: Fri, 5 Jul 2024 13:42:03 +0400 Subject: [PATCH 08/19] Update src/pipeline/build.ts Co-authored-by: byakuren-hijiri <159621697+byakuren-hijiri@users.noreply.github.com> --- src/pipeline/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index 81fe7d9b3..b16f01345 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -228,7 +228,7 @@ export async function build(args: { logger.info(" > " + contract); const artifacts = built[contract]; if (!artifacts) { - const message = " > " + contract + ": no artifacts found"; + const message = ` > ${contract}: no artifacts found`; logger.error(message); errorMessages.push(new Error(message)); return { ok: false, error: errorMessages }; From d10df50d263e15b945adf39bd34d955ea39e439f Mon Sep 17 00:00:00 2001 From: Anton Trunov Date: Fri, 5 Jul 2024 13:42:10 +0400 Subject: [PATCH 09/19] Update src/pipeline/build.ts Co-authored-by: byakuren-hijiri <159621697+byakuren-hijiri@users.noreply.github.com> --- src/pipeline/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index b16f01345..c5ef5a744 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -309,7 +309,7 @@ export async function build(args: { // Bindings logger.info(" > Bindings"); for (const pkg of packages) { - logger.info(" > " + pkg.name); + logger.info(` > ${pkg.name}`); if (pkg.init.deployment.kind !== "system-cell") { const message = " > " + From 9f7f11925960332942e734c4dc7804f2fdafd4f7 Mon Sep 17 00:00:00 2001 From: Anton Trunov Date: Fri, 5 Jul 2024 13:42:52 +0400 Subject: [PATCH 10/19] Update scripts/prepare.ts Co-authored-by: byakuren-hijiri <159621697+byakuren-hijiri@users.noreply.github.com> --- scripts/prepare.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/prepare.ts b/scripts/prepare.ts index 6966dbc91..ace4ebac9 100644 --- a/scripts/prepare.ts +++ b/scripts/prepare.ts @@ -18,7 +18,7 @@ void (async () => { try { // Compile projects const compileResult = await run({ - configPath: path.join(__dirname, "../tact.config.json"), + configPath: path.join(__dirname, "..", "tact.config.json"), }); if (!compileResult.ok) { throw new Error("Tact projects compilation failed"); From 17999a71afe001534ec888df153ce192f75ef019 Mon Sep 17 00:00:00 2001 From: Anton Trunov Date: Fri, 5 Jul 2024 13:43:10 +0400 Subject: [PATCH 11/19] Update src/pipeline/build.ts Co-authored-by: byakuren-hijiri <159621697+byakuren-hijiri@users.noreply.github.com> --- src/pipeline/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index c5ef5a744..bbe4dc06e 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -196,7 +196,7 @@ export async function build(args: { if (config.mode === "fullWithDecompilation") { // Fift decompiler for generated code debug - logger.info(" > " + contract + ": fift decompiler"); + logger.info(` > ${contract}: fift decompiler`); let codeFiftDecompiled: string; try { codeFiftDecompiled = decompileAll({ src: codeBoc }); From 701a3400a5dbe1a1a0f96dd58859bc38c09d5877 Mon Sep 17 00:00:00 2001 From: Anton Trunov Date: Fri, 5 Jul 2024 13:43:20 +0400 Subject: [PATCH 12/19] Update src/pipeline/build.ts Co-authored-by: byakuren-hijiri <159621697+byakuren-hijiri@users.noreply.github.com> --- src/pipeline/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index bbe4dc06e..6e63c51c5 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -143,7 +143,7 @@ export async function build(args: { } // Compiling contract to TVM - logger.info(" > " + contract + ": func compiler"); + logger.info(` > ${contract}: func compiler`); let codeBoc: Buffer; try { const stdlibPath = stdlib.resolve("stdlib.fc"); From 824ac30fbfe23a8f55a21e51785440408726467c Mon Sep 17 00:00:00 2001 From: Anton Trunov Date: Fri, 5 Jul 2024 13:43:31 +0400 Subject: [PATCH 13/19] Update src/node.ts Co-authored-by: byakuren-hijiri <159621697+byakuren-hijiri@users.noreply.github.com> --- src/node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node.ts b/src/node.ts index d45b3abc2..6ef82d510 100644 --- a/src/node.ts +++ b/src/node.ts @@ -115,7 +115,7 @@ export async function run(args: { false, ); // Improves developer experience for (const config of projects) { - logger.info("💼 Compiling project " + config.name + "..."); + logger.info(`💼 Compiling project ${config.name} ...`); let cliConfig = { ...config }; if (args.additionalCliOptions?.mode !== undefined) { From f621b222b7d2dcab5d888715f6ac3b1cfff23f0b Mon Sep 17 00:00:00 2001 From: Anton Trunov Date: Fri, 5 Jul 2024 13:43:45 +0400 Subject: [PATCH 14/19] Update src/pipeline/build.ts Co-authored-by: byakuren-hijiri <159621697+byakuren-hijiri@users.noreply.github.com> --- src/pipeline/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index 6e63c51c5..ed4a86eb1 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -356,7 +356,7 @@ export async function build(args: { project.writeFile(pathBindings, report); } catch (e) { const error = e as Error; - error.message = `Report generation crashed, ${error.message}`; + error.message = `Report generation crashed: ${error.message}`; logger.error(error); errorMessages.push(error); return { ok: false, error: errorMessages }; From f1de0831e4d02ee88ad372bb5083e26063247a64 Mon Sep 17 00:00:00 2001 From: Anton Trunov Date: Fri, 5 Jul 2024 13:43:56 +0400 Subject: [PATCH 15/19] Update src/pipeline/build.ts Co-authored-by: byakuren-hijiri <159621697+byakuren-hijiri@users.noreply.github.com> --- src/pipeline/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index ed4a86eb1..7b9b9f862 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -336,7 +336,7 @@ export async function build(args: { ); } catch (e) { const error = e as Error; - error.message = `Bindings compiler crashed, ${error.message}`; + error.message = `Bindings compiler crashed: ${error.message}`; logger.error(error); errorMessages.push(error); return { ok: false, error: errorMessages }; From 94d8b9423e601373064243347cd664e4d5ec3b41 Mon Sep 17 00:00:00 2001 From: Anton Trunov Date: Fri, 5 Jul 2024 13:44:11 +0400 Subject: [PATCH 16/19] Update scripts/prepare.ts Co-authored-by: byakuren-hijiri <159621697+byakuren-hijiri@users.noreply.github.com> --- scripts/prepare.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/prepare.ts b/scripts/prepare.ts index ace4ebac9..f350ca0c2 100644 --- a/scripts/prepare.ts +++ b/scripts/prepare.ts @@ -39,7 +39,7 @@ void (async () => { } // Compile func files - for (const p of [{ path: path.join(__dirname, "/../func/") }]) { + for (const p of [{ path: path.join(__dirname, "..", "func") }]) { const recs = fs.readdirSync(p.path); for (const r of recs) { if (!r.endsWith(".fc")) { From 576b3548ebaa7807ec2f736bf248de90d470334e Mon Sep 17 00:00:00 2001 From: Anton Trunov Date: Fri, 5 Jul 2024 15:02:35 +0400 Subject: [PATCH 17/19] fix prepare.ts --- scripts/prepare.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/scripts/prepare.ts b/scripts/prepare.ts index f350ca0c2..50093bfe7 100644 --- a/scripts/prepare.ts +++ b/scripts/prepare.ts @@ -40,14 +40,15 @@ void (async () => { // Compile func files for (const p of [{ path: path.join(__dirname, "..", "func") }]) { - const recs = fs.readdirSync(p.path); - for (const r of recs) { - if (!r.endsWith(".fc")) { + const files = fs.readdirSync(p.path); + for (const file of files) { + if (!file.endsWith(".fc")) { continue; } // Precompile - logger.info(`Processing ${path.join(p.path + r)}`); + const funcFileFullPath = path.join(p.path, file); + logger.info(`Processing ${path.join(funcFileFullPath)}`); let c: FuncCompilationResult; try { const stdlibPath = path.resolve( @@ -57,16 +58,16 @@ void (async () => { "stdlib.fc", ); const stdlib = fs.readFileSync(stdlibPath, "utf-8"); - const code = fs.readFileSync(p.path + r, "utf-8"); + const code = fs.readFileSync(funcFileFullPath, "utf-8"); c = await funcCompile({ - entries: [stdlibPath, p.path + r], + entries: [stdlibPath, funcFileFullPath], sources: [ { path: stdlibPath, content: stdlib, }, { - path: p.path + r, + path: funcFileFullPath, content: code, }, ], @@ -75,20 +76,20 @@ void (async () => { if (!c.ok) { logger.error(c.log); throw new Error( - `FunC compilation failed for ${path.join(p.path, r)}`, + `FunC compilation failed for ${path.join(p.path, file)}`, ); } } catch (e) { logger.error(e as Error); - logger.error(`Failed for ${path.join(p.path, r)}`); + logger.error(`Failed for ${path.join(p.path, file)}`); throw e; } - fs.writeFileSync(p.path + r + ".fift", c.fift!); - fs.writeFileSync(p.path + r + ".cell", c.output!); + fs.writeFileSync(funcFileFullPath + ".fift", c.fift!); + fs.writeFileSync(funcFileFullPath + ".cell", c.output!); // Cell -> Fift decompiler const source = decompileAll({ src: c.output! }); - fs.writeFileSync(p.path + r + ".rev.fift", source); + fs.writeFileSync(funcFileFullPath + ".rev.fift", source); } } } catch (error) { From 8d8b772313c7cf60c4945f4c100fa2ffa46ce79e Mon Sep 17 00:00:00 2001 From: Anton Trunov Date: Fri, 5 Jul 2024 15:06:00 +0400 Subject: [PATCH 18/19] fix build.ts --- src/pipeline/build.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index 5a215c0a5..1e5bd8c85 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -319,11 +319,7 @@ export async function build(args: { for (const pkg of packages) { logger.info(` > ${pkg.name}`); if (pkg.init.deployment.kind !== "system-cell") { - const message = - " > " + - pkg.name + - ": unsupported deployment kind " + - pkg.init.deployment.kind; + const message = ` > ${pkg.name}: unsupported deployment kind ${pkg.init.deployment.kind}`; logger.error(message); errorMessages.push(new Error(message)); return { ok: false, error: errorMessages }; From b6dcbae5071cb3379cd9aed43f35598be29d0400 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:24:44 +0200 Subject: [PATCH 19/19] chore: simplified a bit more --- scripts/prepare.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/prepare.ts b/scripts/prepare.ts index 50093bfe7..c1c35fecf 100644 --- a/scripts/prepare.ts +++ b/scripts/prepare.ts @@ -48,7 +48,7 @@ void (async () => { // Precompile const funcFileFullPath = path.join(p.path, file); - logger.info(`Processing ${path.join(funcFileFullPath)}`); + logger.info(`Processing ${funcFileFullPath}`); let c: FuncCompilationResult; try { const stdlibPath = path.resolve( @@ -76,12 +76,12 @@ void (async () => { if (!c.ok) { logger.error(c.log); throw new Error( - `FunC compilation failed for ${path.join(p.path, file)}`, + `FunC compilation failed for ${funcFileFullPath}`, ); } } catch (e) { logger.error(e as Error); - logger.error(`Failed for ${path.join(p.path, file)}`); + logger.error(`Failed for ${funcFileFullPath}`); throw e; } fs.writeFileSync(funcFileFullPath + ".fift", c.fift!);