Skip to content

Commit

Permalink
fix: save project with relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
qarlosalberto committed Aug 24, 2023
1 parent 0c590fc commit 16cd59b
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 65 deletions.
87 changes: 44 additions & 43 deletions packages/colibri/src/project_manager/multi_project_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
// You should have received a copy of the GNU General Public License
// along with TerosHDL. If not, see <https://www.gnu.org/licenses/>.

import { t_file_reduced, t_script, t_parameter, e_script_stage, t_action_result, t_watcher, } from "./common";
// import { t_file_reduced, t_script, t_parameter, e_script_stage, t_action_result, t_watcher, } from "./common";
import { t_file_reduced, t_action_result, t_watcher, } from "./common";
import { Config_manager } from "../config/config_manager";
import { e_clean_step } from "./tool/common";
import { Project_manager } from "./project_manager";
Expand Down Expand Up @@ -357,52 +358,52 @@ export class Multi_project_manager {
////////////////////////////////////////////////////////////////////////////
// Hook
////////////////////////////////////////////////////////////////////////////
public add_hook(prj_name: string, script: t_script, stage: e_script_stage)
: t_action_result {
const prj = this.get_project_by_name(prj_name);
if (prj === undefined) {
this.save();
return this.get_project_not_exist();
}
const result = prj.add_hook(script, stage);
this.save();
return result;
}

public delete_hook(prj_name: string, script: t_script, stage: e_script_stage)
: t_action_result {
const prj = this.get_project_by_name(prj_name);
if (prj === undefined) {
this.save();
return this.get_project_not_exist();
}
const result = prj.delete_hook(script, stage);
this.save();
return result;
}
// public add_hook(prj_name: string, script: t_script, stage: e_script_stage)
// : t_action_result {
// const prj = this.get_project_by_name(prj_name);
// if (prj === undefined) {
// this.save();
// return this.get_project_not_exist();
// }
// const result = prj.add_hook(script, stage);
// this.save();
// return result;
// }

// public delete_hook(prj_name: string, script: t_script, stage: e_script_stage)
// : t_action_result {
// const prj = this.get_project_by_name(prj_name);
// if (prj === undefined) {
// this.save();
// return this.get_project_not_exist();
// }
// const result = prj.delete_hook(script, stage);
// this.save();
// return result;
// }

////////////////////////////////////////////////////////////////////////////
// Parameters
////////////////////////////////////////////////////////////////////////////
add_parameter(prj_name: string, parameter: t_parameter): t_action_result {
const prj = this.get_project_by_name(prj_name);
if (prj === undefined) {
return this.get_project_not_exist();
}
const result = prj.add_parameter(parameter);
this.save();
return result;
}

delete_parameter(prj_name: string, parameter: t_parameter): t_action_result {
const prj = this.get_project_by_name(prj_name);
if (prj === undefined) {
return this.get_project_not_exist();
}
const result = prj.delete_parameter(parameter);
this.save();
return result;
}
// add_parameter(prj_name: string, parameter: t_parameter): t_action_result {
// const prj = this.get_project_by_name(prj_name);
// if (prj === undefined) {
// return this.get_project_not_exist();
// }
// const result = prj.add_parameter(parameter);
// this.save();
// return result;
// }

// delete_parameter(prj_name: string, parameter: t_parameter): t_action_result {
// const prj = this.get_project_by_name(prj_name);
// if (prj === undefined) {
// return this.get_project_not_exist();
// }
// const result = prj.delete_parameter(parameter);
// this.save();
// return result;
// }

////////////////////////////////////////////////////////////////////////////
// Toplevel
Expand Down
52 changes: 37 additions & 15 deletions packages/colibri/src/project_manager/project_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// along with TerosHDL. If not, see <https://www.gnu.org/licenses/>.

import {
t_file_reduced, t_script, t_parameter, e_script_stage, t_action_result, t_watcher,
t_file_reduced, t_action_result, t_watcher,
e_watcher_type
} from "./common";
import * as manager_watcher from "./list_manager/watcher";
Expand Down Expand Up @@ -135,39 +135,57 @@ export class Project_manager {
////////////////////////////////////////////////////////////////////////////
// Hook
////////////////////////////////////////////////////////////////////////////
public add_hook(script: t_script, stage: e_script_stage)
: t_action_result {
return this.hooks.add(script, stage);
}
// public add_hook(script: t_script, stage: e_script_stage)
// : t_action_result {
// return this.hooks.add(script, stage);
// }

public delete_hook(script: t_script, stage: e_script_stage)
: t_action_result {
return this.hooks.delete(script, stage);
}
// public delete_hook(script: t_script, stage: e_script_stage)
// : t_action_result {
// return this.hooks.delete(script, stage);
// }

////////////////////////////////////////////////////////////////////////////
// Parameters
////////////////////////////////////////////////////////////////////////////
add_parameter(parameter: t_parameter): t_action_result {
return this.parameters.add(parameter);
}
// add_parameter(parameter: t_parameter): t_action_result {
// return this.parameters.add(parameter);
// }

delete_parameter(parameter: t_parameter): t_action_result {
return this.parameters.delete(parameter);
}
// delete_parameter(parameter: t_parameter): t_action_result {
// return this.parameters.delete(parameter);
// }

////////////////////////////////////////////////////////////////////////////
// Toplevel
////////////////////////////////////////////////////////////////////////////
/**
* Add top level path to project. Delete de previous one.
* @param toplevel_path_inst Top level path to add.
* @returns Operation result
**/
add_toplevel_path(toplevel_path_inst: string): t_action_result {
this.toplevel_path.clear();
return this.toplevel_path.add(toplevel_path_inst);
}

/**
* Delete top level path to project.
* @param toplevel_path_inst Top level path to delete.
* @returns Operation result
**/
delete_toplevel_path(toplevel_path_inst: string): t_action_result {
return this.toplevel_path.delete(toplevel_path_inst);
}

/**
* Get top level path.
* @returns Top level path.
**/
get_toplevel_path(): string[] {
return this.toplevel_path.get();
}

////////////////////////////////////////////////////////////////////////////
// Watcher
////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -331,6 +349,10 @@ export class Project_manager {
return result;
}

get_file() : t_file_reduced[]{
return this.files.get();
}

delete_file_by_logical_name(logical_name: string) {
const result = this.files.delete_by_logical_name(logical_name);
this.delete_phantom_toplevel();
Expand Down
4 changes: 0 additions & 4 deletions packages/colibri/src/utils/file_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ export function get_absolute_path(current_directory: string, path: string): stri
* @returns Direcotry of path
**/
export function get_directory(path: string): string {
const is_file = check_if_file(path);
if (!is_file){
return path;
}
return path_lib.dirname(path);
}

Expand Down
132 changes: 132 additions & 0 deletions packages/colibri/tests/project_manager/project_manager.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright 2023
// Carlos Alberto Ruiz Naranjo [[email protected]]
// Ismael Perez Rojo [[email protected]]
//
// This file is part of TerosHDL
//
// Colibri is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Colibri is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TerosHDL. If not, see <https://www.gnu.org/licenses/>.

import { t_file_reduced } from '../../src/project_manager/common';
import {Project_manager} from '../../src/project_manager/project_manager';

const DEFAULT_NAME = "def_name";

describe('project_manager', () => {
let project_manager: Project_manager;

beforeEach(() => {
project_manager = new Project_manager(DEFAULT_NAME, undefined);
});

test('rename', () => {
const new_name = "sancho_panza";

expect(project_manager.get_name()).toBe(DEFAULT_NAME);
project_manager.rename(new_name);
expect(project_manager.get_name()).toBe(new_name);
});

test('add_toplevel_path', () => {
project_manager.add_toplevel_path("path1");
expect(project_manager.get_toplevel_path()).toStrictEqual(["path1"]);

project_manager.add_toplevel_path("path2");
expect(project_manager.get_toplevel_path()).toStrictEqual(["path2"]);
});

test('delete_toplevel_path', () => {
project_manager.add_toplevel_path("path1");
project_manager.delete_toplevel_path("path1");
expect(project_manager.get_toplevel_path()).toStrictEqual([]);
});

// test('add_file_watcher', () => {

// });

// test('delete_file_watcher', () => {

// });

test('add_file', () => {
const file_0 : t_file_reduced = {
name: 'file_0',
is_include_file: false,
include_path: '',
logical_name: 'logical_0',
is_manual: false
};

const file_1 : t_file_reduced = {
name: 'file_1',
is_include_file: false,
include_path: '',
logical_name: 'logical_1',
is_manual: false
};

project_manager.add_file(file_0);
expect(project_manager.get_file()).toStrictEqual([file_0]);

project_manager.add_file(file_1);
expect(project_manager.get_file()).toStrictEqual([file_0, file_1]);
});

test('remove_file', () => {
const file_0 : t_file_reduced = {
name: 'file_0',
is_include_file: false,
include_path: '',
logical_name: 'logical_0',
is_manual: false
};

const file_1 : t_file_reduced = {
name: 'file_1',
is_include_file: false,
include_path: '',
logical_name: 'logical_1',
is_manual: false
};

project_manager.add_file(file_0);
project_manager.add_file(file_1);

const result_0 = project_manager.delete_file("file_0", "logical_0");
expect(project_manager.get_file()).toStrictEqual([file_1, file_1]);
expect(result_0.successful).toBe(true);

const result_1 = project_manager.delete_file("file_1", "logical_5");
expect(result_1.successful).toBe(true);

const result_2 = project_manager.delete_file("file_1", "logical_1");
expect(project_manager.get_file()).toStrictEqual([]);
expect(result_2.successful).toBe(true);
});


// test('delete_file_by_logical_name', () => {

// });

// test('add_logical', () => {

// });

// test('delete_phantom_toplevel', () => {

// });


});
2 changes: 1 addition & 1 deletion packages/teroshdl/auto_package/templates/info.nj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"displayName": "TerosHDL",
"publisher": "teros-technology",
"description": "Powerful IDE for ASIC/FPGA: state machine viewer, linter, documentation, snippets... and more! ",
"version": "5.0.10",
"version": "5.0.11",
"engines": {
"vscode": "^1.74.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/teroshdl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "TerosHDL",
"publisher": "teros-technology",
"description": "Powerful IDE for ASIC/FPGA: state machine viewer, linter, documentation, snippets... and more! ",
"version": "5.0.10",
"version": "5.0.11",
"engines": {
"vscode": "^1.74.0"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/teroshdl/resources/release_notes/release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
</p>
<br>

<h4 id="release-notes"> Minor changes v5.0.5 and v5.0.10</h4>
<h4 id="release-notes"> Minor changes v5.0.5 and v5.0.11</h4>
<p>
<ul>
<li> Fix: Save project with relative paths</li>
<li> Fix: Delete auxiliar files in Vivado linter</li>
<li> Fix: VHDL formatter in new PORT MAP line</li>
<li> Fix: tables in markdown format auto doc</li>
Expand Down

0 comments on commit 16cd59b

Please sign in to comment.