Skip to content

Commit

Permalink
Merge pull request #2 from Javadyakuza/ast-over-write-handled
Browse files Browse the repository at this point in the history
ast-over-write-handled
  • Loading branch information
Cyace84 authored Aug 4, 2023
2 parents a046ecf + 15a3cf9 commit a13e4e9
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/ast-builder/compile-ast.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs';
import { execSync } from 'child_process';
import { Config } from '../config';
import { getAstsFromSources, getContractsList } from './getters';
import path from 'path';
import fs from "fs";
import { execSync } from "child_process";
import { Config } from "../config";
import { getAstsFromSources, getContractsList } from "./getters";
import path from "path";

/**
* It takes the config object, gets a list of contracts, and then compiles the AST for each contract
Expand All @@ -15,14 +15,20 @@ export const compileAst = async (config: Config) => {
fs.rm(path.resolve(config.root!, config.astOutputDir!), () => {});
}

contracts.forEach(contract => {
let ast_cache_path = `ast-cache`;

execSync(`mkdir $PWD/${ast_cache_path}`);
execSync(`mkdir $PWD/ast`);

contracts.forEach((contract) => {
execSync(
`${config.compilerPath} --ast-compact-json $PWD/${config.sourcesDir}/${contract} --output-dir=$PWD/${config.astOutputDir}`,
`${config.compilerPath} --ast-compact-json $PWD/${config.sourcesDir}/${contract} --output-dir=$PWD/${ast_cache_path}`
);
execSync(`mv $PWD/${ast_cache_path}/* $PWD/${config.astOutputDir}/`);
});
execSync(`rm -rf $PWD/${ast_cache_path}`);
compileExternalAst(config);
};

/**
* It compiles all the external sources in the project, and saves the ASTs in the `astOutputDir`
* directory
Expand All @@ -31,15 +37,15 @@ export const compileAst = async (config: Config) => {
export const compileExternalAst = async (config: Config) => {
const { fullSources } = getAstsFromSources(
config.astOutputDir!,
config.root!,
config.root!
);

Object.values(fullSources).forEach(source => {
Object.values(fullSources).forEach((source) => {
for (const ast of source.asts) {
const absolutePath = ast.absolutePath;
if (!absolutePath.startsWith(config.sourcesDir!)) {
execSync(
`${config.compilerPath} --ast-compact-json $PWD/${absolutePath} --output-dir=$PWD/${config.astOutputDir}`,
`${config.compilerPath} --ast-compact-json $PWD/${absolutePath} --output-dir=$PWD/${config.astOutputDir}`
);
}
}
Expand Down

0 comments on commit a13e4e9

Please sign in to comment.