Skip to content

Commit

Permalink
feat: add --func and --check
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpy committed Apr 27, 2024
1 parent 46bea40 commit 3c39774
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
31 changes: 27 additions & 4 deletions bin/tact
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,32 @@ const meowModule = import("meow");

meowModule.then((meow) => {
const importMeta = { url: new URL("file://" + __dirname + __filename) };
const cli = meow.default(`
const cli = meow.default(
`
Usage
$ tact <config_path>
Options
--project <project_name>, -r <project_name>
--version Prints the current tact version
--func Outputs the intermediate FunC code.
--check Performs type checking and stops.
--help Displays this text
Examples
$ tact --version
1.2.0
`, { importMeta: importMeta, flags: { project: { shortFlag: "p", type: "string", isMultiple: true }, version: { shortFlag: "v", type: "boolean" }} });
`,
{
importMeta: importMeta,
flags: {
project: { shortFlag: "p", type: "string", isMultiple: true },
version: { shortflag: "v", type: "boolean" },
check: { shortflag: "c", type: "boolean" },
func: { shortFlag: "f", type: "boolean" },
},
},
);

if (cli.flags.version) {
cli.showVersion();
Expand All @@ -28,6 +41,16 @@ meowModule.then((meow) => {
cli.showHelp();
return;
}

return main.run({ configPath: cli.input.at(0), projectNames: cli.flags.project ?? [] })

if (cli.flags.check && cli.flags.func) {
console.log("--func and --check are mutually exclusive");
process.exit(30);
}

return main.run({
configPath: cli.input.at(0),
projectNames: cli.flags.project ?? [],
checkOnly: cli.flags.check,
func: cli.flags.func,
});
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@tact-lang/opcode": "^0.0.14",
"@ton/core": "0.56.3",
"@ton/crypto": "^3.2.0",
"arg": "^5.0.2",
"blockstore-core": "1.0.5",
"change-case": "^4.1.2",
"ipfs-unixfs-importer": "9.0.10",
Expand Down Expand Up @@ -92,5 +91,6 @@
"filename": "CHANGELOG.md"
}
}
}
},
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}
6 changes: 5 additions & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { consoleLogger } from "./logger";
export async function run(args: {
configPath: string;
projectNames?: string[];
checkOnly?: boolean;
func?: boolean;
}) {
// Load config
const resolvedPath = path.resolve(args.configPath);
Expand All @@ -28,7 +30,7 @@ export async function run(args: {
// Resolve projects
let projects = config.projects;
if (args.projectNames && args.projectNames.length > 0) {
// Check that all proejct names are valid
// 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);
Expand Down Expand Up @@ -58,6 +60,8 @@ export async function run(args: {
project,
stdlib,
logger: consoleLogger,
checkOnly: args.checkOnly,
func: args.func,
});
success = success && built;
}
Expand Down
16 changes: 16 additions & 0 deletions src/pipeline/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export async function build(args: {
project: VirtualFileSystem;
stdlib: string | VirtualFileSystem;
logger?: TactLogger | null | undefined;
checkOnly?: boolean;
func?: boolean;
}) {
const { config, project } = args;
const stdlib =
Expand Down Expand Up @@ -68,6 +70,11 @@ export async function build(args: {
return false;
}

if (args.checkOnly) {
logger.log("✔️ Type checking succeeded.");
return true;
}

// Compile contracts
let ok = true;
const built: {
Expand Down Expand Up @@ -127,6 +134,10 @@ export async function build(args: {
continue;
}

if (args.func) {
continue;
}

// Compiling contract to TVM
logger.log(" > " + contract + ": func compiler");
let codeBoc: Buffer;
Expand Down Expand Up @@ -198,6 +209,11 @@ export async function build(args: {
return false;
}

if (args.func) {
logger.log("✔️ FunC code generation succeeded.");
return true;
}

// Package
logger.log(" > Packaging");
const contracts = getContracts(ctx);
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ arg@^4.1.0:
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==

arg@^5.0.1, arg@^5.0.2:
arg@^5.0.1:
version "5.0.2"
resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.2.tgz#c81433cc427c92c4dcf4865142dbca6f15acd59c"
integrity sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==
Expand Down

0 comments on commit 3c39774

Please sign in to comment.