Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] GHDL+Yosys Schematic Viewer Temporary File Spam Fix #700

Open
irshbn opened this issue Nov 9, 2024 · 1 comment
Open

[FIX] GHDL+Yosys Schematic Viewer Temporary File Spam Fix #700

irshbn opened this issue Nov 9, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@irshbn
Copy link

irshbn commented Nov 9, 2024

Problem
When schematic viewer calls runYosysGhdl(), it doesn't call remove_file() on the .teroshdl_${random_id} file that it generates with createTempFileInHome(). This results in temporary schematic descriptions needlessly cluttering the user home directory.

Solution
In src/colibri/yosys/yosys.ts add remove_file(outputPathFilename); on line 175:

export function runYosysGhdl(config: e_config, topTevel: string, sources: t_file[],
    callback: (result: e_schematic_result) => void): any {
    // ...
    const exec_i = p.exec(cmd, opt_exec, (result: p_result) => {
        // ...
        remove_file(outputPathFilename); // add this line here
        callback(schematicResult);
    });
    return exec_i;
}

I've tested this on my machine (see additional context) with a couple of vhdl files, and it works as expected.

Alternatives I've considered
If there is a reason you want the file to exist after the schematic viewer call, consider replacing calls to createTempFileInHome() with calls to something like this (appended to src/colibri/process/utils.ts):

/**
 * Get the OS temporary directory path
 * @returns Temporary directory path
**/
export function get_temp_directory(): string {
    const os_temp_dir = os_lib.tempdir();
    return os_temp_dir;
}

/**
 * Create a random file in the dedicated OS temporary directory
 * @returns Path to created random file in temp dir
 **/
export function createTempFileInTmpdir(content: string): string {
    const os_temp_dir = get_temp_directory();
    const random_id = makeid(5);
    const filePath = path_lib.join(os_temp_dir, `.teroshdl_${random_id}`);
    file_utils.save_file_sync(filePath, content);
    return filePath;
}

This way files keep existing in the tempdir, without cluttering home directory.

Additional context
OS: Ubuntu 24.04 via WSL (x64)
VS Code ver: 1.95.2
TerosHDL ver: 6.0.14

@irshbn irshbn added the enhancement New feature or request label Nov 9, 2024
@malsheimer
Copy link

If the above solution is accepted, remove_file(outputPathFilename) should also be added to other functions as it is missing there as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants