Skip to content

Commit

Permalink
1/N Integration new APIO development
Browse files Browse the repository at this point in the history
  • Loading branch information
cavearr committed Dec 18, 2024
1 parent c402941 commit a75bcca
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 70 deletions.
3 changes: 2 additions & 1 deletion app/resources/libs/Icestudio/Icestudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Icestudio {
this.pluginManager = false;
this.gui = false;
this.env={};
this.toolchain={apio:false,installed:false};

}
isInitialized(){
Expand Down Expand Up @@ -43,4 +44,4 @@ class Icestudio {
}
}

}
}
185 changes: 117 additions & 68 deletions app/scripts/services/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,65 @@ angular
//-- build dir is used
nodeFse.removeSync(common.OLD_BUILD_DIR);

async function apioIntegrityCheck(){

let test=true;
if(iceStudio.toolchain.apio >= '0.9.6'){
const hd = new IceHD();
console.log('Checks for APIO project integrity');
//Check if build dir exists
if (!nodeFs.existsSync(common.BUILD_DIR)) {
console.log('Build dir not exists',common.BUILD_DIR);
nodeFs.mkdirSync(common.BUILD_DIR, { recursive: true });

}//-- if buildir exists

if (!nodeFs.existsSync(hd.joinPath(common.BUILD_DIR, 'Apio.ini'))) {
console.log('Apio.ini not found');
test=false;

}//-- if buildir exists

let board = (common.selectedBoard.name === 'MCH2022_badge') ? 'iCE40-UP5K' : common.selectedBoard.name;
if(!test){
test=true;
try{
apioRun(
["create",'--board',board],
'Setup Apio project',
'Apio project ready',
false
);


}catch(error){
test=false;
console.log('ERROR CHECK',error);
}
}
}

return test;

} //--Apio Integrity check
//-- Execute the apio verify command. It checks the syntax of the current
//-- circuit
this.verifyCode = function (startMessage, endMessage) {

console.log('APIO VERIFY', this.toolchain.apio);
console.log('APIO VERIFY', this.toolchain.apio);
let board = (common.selectedBoard.name === 'MCH2022_badge') ? 'iCE40-UP5K' : common.selectedBoard.name;

let apioParams=[];

if (toolchain.apio >= '0.9.6') {
if(iceStudio.toolchain.apio >= '0.9.6'){
apioParams = ["lint"];
}else{

apioParams= ["verify", "--board", board];
}

return apioRun(
apioParams,
apioParams,
startMessage,
endMessage
);
Expand All @@ -81,7 +122,7 @@ angular
this.buildCode = function (startMessage, endMessage) {
let board = (common.selectedBoard.name === 'MCH2022_badge') ? 'iCE40-UP5K' : common.selectedBoard.name;
let apioParams = [];
if (toolchain.apio >= '0.9.6') {
if(iceStudio.toolchain.apio >= '0.9.6'){
apioParams = ["build"];
}else if (toolchain.apio >= '0.9.0') {
apioParams = ["build", "--board", board, "--top-module", "main"];
Expand All @@ -104,7 +145,7 @@ angular
return toolchainRun(['upload'], startMessage, endMessage);
}
let apioParams = [];
if (toolchain.apio >= '0.9.6') {
if(iceStudio.toolchain.apio >= '0.9.6'){
apioParams = ["upload"];
} else if (toolchain.apio >= '0.9.0') {
apioParams = ["upload", "--board", common.selectedBoard.name, "--top-module", "main"];
Expand Down Expand Up @@ -221,8 +262,15 @@ angular

//----------------------------------------------------------------
//-- Execute an apio command: build, verify, upload
function apioRun(commands, startMessage, endMessage) {
return new Promise(function (resolve) {
function apioRun(commands, startMessage, endMessage,checkIntegrity=true) {


return new Promise(function (resolve,reject) {

if (checkIntegrity && !apioIntegrityCheck()) {
reject(new Error("No Apio project found"));
return; // Asegúrate de salir de la función aquí
}

//-- Variable for storing the verilog source code of
//-- the current circuit
Expand Down Expand Up @@ -521,14 +569,15 @@ angular
//-- Get the version number
toolchain.apio = msg.match(/apio,\sversion\s(.+)/)[1];


iceStudio.toolchain.apio=toolchain.apio;
//-- Check if the apio version is ok with the specification
//-- in the package.json file

toolchain.installed =
toolchain.apio >= _package.apio.min &&
toolchain.apio < _package.apio.max;

iceStudio.toolchain.installed=toolchain.installed;
//-- Everything is ok: call the callback function
if (toolchain.installed) {

Expand Down Expand Up @@ -602,9 +651,9 @@ angular
);
nodeSSHexec(
["apio"]
.concat(commands)
.concat(["--project-dir", ".build"])
.join(" "),
.concat(commands)
.concat(["--project-dir", ".build"])
.join(" "),
hostname,
function (error, stdout, stderr) {
resolve({
Expand Down Expand Up @@ -750,7 +799,7 @@ angular
);
} else if (stdout.indexOf("[upload] Error") !== -1) {
switch (common.selectedBoard.name) {
// TinyFPGA-B2 programmer errors
// TinyFPGA-B2 programmer errors
case "TinyFPGA-B2":
case "TinyFPGA-BX":
var match = stdout.match(/Bootloader\snot\sactive/g);
Expand Down Expand Up @@ -1109,7 +1158,7 @@ angular
var match = pattern.exec(output);
return (match && match[1]) ? match[1] : previousValue;
}
*/
*/
function mapCodeModules(code) {
var codelines = code.split("\n");
var match,
Expand Down Expand Up @@ -1979,7 +2028,7 @@ angular
if (hasNewVersion === "stable") {
msg =
'<div class="new-version-notifier-box"><div class="new-version-notifier-box--icon"><img src="resources/images/confetti.svg"></div>\
<div class="new-version-notifier-box--text">' +
<div class="new-version-notifier-box--text">' +
gettextCatalog.getString(
"There is a new stable version available"
) +
Expand All @@ -1991,7 +2040,7 @@ angular
} else {
msg =
'<div class="new-version-notifier-box"><div class="new-version-notifier-box--icon"><img src="resources/images/confetti.svg"></div>\
<div class="new-version-notifier-box--text">' +
<div class="new-version-notifier-box--text">' +
gettextCatalog.getString(
"There is a new nightly version available"
) +
Expand All @@ -2008,63 +2057,63 @@ angular
);
}
};
this.ifDevelopmentMode = function () {
this.ifDevelopmentMode = function () {
if (
typeof _package.development !== "undefined" &&
typeof _package.development.mode !== "undefined" &&
_package.development.mode === true
) {
utils.openDevToolsUI();
}
};

this.initializePluginManager = function (callbackOnRun) {
if (typeof ICEpm !== "undefined") {
ICEpm.setEnvironment(common);
ICEpm.setPluginDir(common.DEFAULT_PLUGIN_DIR, function () {
let plist = ICEpm.getAll();
let uri = ICEpm.getBaseUri();
let t = $(".icm-icon-list");
t.empty();
let html = "";
for (let prop in plist) {
if (
typeof _package.development !== "undefined" &&
typeof _package.development.mode !== "undefined" &&
_package.development.mode === true
typeof plist[prop].manifest.type === "undefined" ||
plist[prop].manifest.type === "app"
) {
utils.openDevToolsUI();
html +=
'<a href="#" data-action="icm-plugin-run" data-plugin="' +
prop +
'"><img class="icm-plugin-icon" src="' +
uri +
"/" +
prop +
"/" +
plist[prop].manifest.icon +
'"><span>' +
plist[prop].manifest.name +
"</span></a>";
}
};

this.initializePluginManager = function (callbackOnRun) {
if (typeof ICEpm !== "undefined") {
ICEpm.setEnvironment(common);
ICEpm.setPluginDir(common.DEFAULT_PLUGIN_DIR, function () {
let plist = ICEpm.getAll();
let uri = ICEpm.getBaseUri();
let t = $(".icm-icon-list");
t.empty();
let html = "";
for (let prop in plist) {
if (
typeof plist[prop].manifest.type === "undefined" ||
plist[prop].manifest.type === "app"
) {
html +=
'<a href="#" data-action="icm-plugin-run" data-plugin="' +
prop +
'"><img class="icm-plugin-icon" src="' +
uri +
"/" +
prop +
"/" +
plist[prop].manifest.icon +
'"><span>' +
plist[prop].manifest.name +
"</span></a>";
}
}
t.append(html);

$('[data-action="icm-plugin-run"]').off();
$('[data-action="icm-plugin-run"]').on("click", function (e) {
e.preventDefault();
let ptarget = $(this).data("plugin");
if (typeof callbackOnRun !== "undefined") {
callbackOnRun();
}
ICEpm.run(ptarget);
return false;
});
}
t.append(html);

$('[data-action="icm-plugin-run"]').off();
$('[data-action="icm-plugin-run"]').on("click", function (e) {
e.preventDefault();
let ptarget = $(this).data("plugin");
if (typeof callbackOnRun !== "undefined") {
callbackOnRun();
}
ICEpm.run(ptarget);
return false;
});



});
});


}
};
}
);
}
};
}
);
21 changes: 20 additions & 1 deletion app/scripts/services/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,28 @@ angular.module('icestudio')
//--
this.apioInstall = function (pkg, callback) {

iceConsole.log("APIO VERSION "+common.APIO_VERSION+' / '+iceStudio.toolchain.apio);

if(iceStudio.toolchain.apio >= '0.9.6'){
let args='--install';
let edge='packages';
switch(pkg){
case 'drivers':
edge='drivers';
args='--install-ftdi';
pkg='';
break;
default:

}
iceConsole.log("OSS-CAD-SUITE? "+common.APIO_CMD+' '+edge+' '+args+' '+pkg);
this.executeCommand([common.APIO_CMD, edge ,args,pkg], null, true, callback);
}else{
iceConsole.log('--->OLD APIO');
//-- common.APIO_CMD contains the command for executing APIO
this.executeCommand([common.APIO_CMD, 'install', pkg], null, true, callback);
};
}
};

//-- The toolchains are NOT disabled by default
this.toolchainDisabled = false;
Expand Down

0 comments on commit a75bcca

Please sign in to comment.