Skip to content
18 changes: 8 additions & 10 deletions src/Compiler/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "Utils/LogUtils.h"
#include "Utils/ProcessUtils.h"
#include "Utils/StringUtils.h"
#include "Utils/PathUtils.h"
#include "scope_guard/scope_guard.hpp"

extern FOEDAG::Session* GlobalSession;
Expand Down Expand Up @@ -217,6 +218,12 @@ void Compiler::Help(std::ostream* out) {

void Compiler::CustomSimulatorSetup(Simulator::SimulationType action) {}

Compiler::Compiler()
{
IPCatalog* catalog = new IPCatalog();
SetIPGenerator(new IPGenerator(PathUtils::instance().installDir(), catalog, this));
}

Compiler::Compiler(TclInterpreter* interp, std::ostream* out,
TclInterpreterHandler* tclInterpreterHandler)
: m_interp(interp),
Expand All @@ -225,7 +232,7 @@ Compiler::Compiler(TclInterpreter* interp, std::ostream* out,
if (m_tclInterpreterHandler) m_tclInterpreterHandler->setCompiler(this);
SetConstraints(new Constraints{this});
IPCatalog* catalog = new IPCatalog();
SetIPGenerator(new IPGenerator(catalog, this));
SetIPGenerator(new IPGenerator(PathUtils::instance().installDir(), catalog, this));
m_simulator = new Simulator(m_interp, this, m_out, m_tclInterpreterHandler);
}

Expand Down Expand Up @@ -355,11 +362,6 @@ tcl_interp_clone

bool Compiler::BuildLiteXIPCatalog(std::filesystem::path litexPath,
bool namesOnly) {
if (m_IPGenerator == nullptr) {
IPCatalog* catalog = new IPCatalog();
SetIPGenerator(new IPGenerator(catalog, this));

}
if (m_simulator == nullptr) {
m_simulator = new Simulator(m_interp, this, m_out, m_tclInterpreterHandler);
}
Expand Down Expand Up @@ -424,10 +426,6 @@ Simulator* Compiler::GetSimulator() {
}

bool Compiler::RegisterCommands(TclInterpreter* interp, bool batchMode) {
if (m_IPGenerator == nullptr) {
IPCatalog* catalog = new IPCatalog();
m_IPGenerator = new IPGenerator(catalog, this);
}
// if (m_DesignQuery == nullptr) {
// m_DesignQuery = new DesignQuery(this);
// }
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Compiler {
enum class STAEngineOpt { Tatum, Opensta };

// Most common use case, create the compiler in your main
Compiler() = default;
Compiler();
Compiler(TclInterpreter* interp, std::ostream* out,
TclInterpreterHandler* tclInterpreterHandler = nullptr);
void SetInterpreter(TclInterpreter* interp) { m_interp = interp; }
Expand Down
13 changes: 1 addition & 12 deletions src/Compiler/CompilerOpenFPGA_ql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5645,23 +5645,12 @@ std::string CompilerOpenFPGA_ql::FinishOpenFPGAScript(const std::string& script)
read_openfpga_bitstream_setting_command);

// repack constraints
// 1. pass in the PCF file, if available with '--pcf'
// 2. pass in the user provided repack design constraint xml if available with '--design_constraints'
// 3. pass in option '--write_design_constraints' to dump constraints to verify
// 1. pass in the user provided repack design constraint xml if available with '--design_constraints'
std::string openfpga_repack_constraints_command = "repack";
std::filesystem::path filepath_pcf = QLSettingsManager::getInstance()->getPCFFilePath();
if(!filepath_pcf.empty()) {
openfpga_repack_constraints_command +=
" --pcf " + filepath_pcf.string();
}
if(!m_OpenFpgaRepackConstraintsFile.empty()) {
openfpga_repack_constraints_command +=
" --design_constraints " + m_OpenFpgaRepackConstraintsFile.string();
}
std::string generated_repack_design_constraint_filename =
"repack_design_constraint_generated.xml";
openfpga_repack_constraints_command +=
" --write_design_constraints " + generated_repack_design_constraint_filename;
result = ReplaceAll(result, "${OPENFPGA_REPACK_CONSTRAINTS_COMMAND}",
openfpga_repack_constraints_command);

Expand Down
12 changes: 4 additions & 8 deletions src/IPGenerate/IPGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,20 @@ using ms = std::chrono::milliseconds;
// Right now we bypass new approach and still use legacy flow of building commandline arguments.
#define EXCLUDE_MODIFICATION_JSON_FLOW

std::filesystem::path IPGenerator::ExecPath() const {
return GlobalSession->Context()->DataPath()/std::filesystem::path("..")/std::filesystem::path("bin");
}

std::filesystem::path IPGenerator::EnvsPath() const {
return std::filesystem::weakly_canonical(ExecPath() / ".." / "envs");
return std::filesystem::weakly_canonical(m_installDir / "envs");
}

std::filesystem::path IPGenerator::IPCatalogPath() const {
return std::filesystem::weakly_canonical(ExecPath() / ".." / "IP_Catalog");
return std::filesystem::weakly_canonical(m_installDir / "IP_Catalog");
}

void IPGenerator::setIpOutputLocation(const std::string& moduleName, const std::string& version, const std::filesystem::path& ipOutputLocation)
{
m_ipOutputLocations[moduleName + "_" + version] = ipOutputLocation;
}

IPGenerator::IPGenerator(IPCatalog* catalog, Compiler* compiler): m_catalog(catalog), m_compiler(compiler) {
IPGenerator::IPGenerator(const std::filesystem::path& installDir, IPCatalog* catalog, Compiler* compiler): m_installDir(installDir), m_catalog(catalog), m_compiler(compiler) {
m_environment["PYTHONHOME"] = (EnvsPath() / "python3.8").string();
#ifndef __WIN32
// IP Generator requires libffi.so.6 which is absent on ubuntu>=20.04
Expand Down Expand Up @@ -655,7 +651,7 @@ bool IPGenerator::Generate() {
jsonF << " \"" << param.Name() << "\": " << value << ","
<< std::endl;
}
jsonF << " \"build_dir\": \"" << inst->OutputLocation().string() << "\","
jsonF << " \"build_dir\": \"" << FileUtils::resolvePathStr(inst->OutputLocation().string()) << "\","
<< std::endl;
jsonF << " \"build_name\": \"" << inst->ModuleName() << "\","
<< std::endl;
Expand Down
4 changes: 2 additions & 2 deletions src/IPGenerate/IPGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ class IPInstance;

class IPGenerator {
public:
IPGenerator(IPCatalog* catalog, Compiler* compiler);
IPGenerator(const std::filesystem::path& installDir, IPCatalog* catalog, Compiler* compiler);
virtual ~IPGenerator() {}

void setIpOutputLocation(const std::string& moduleName, const std::string& version, const std::filesystem::path& ipOutputLocation);
void shareContext();
const std::map<std::string, std::string>& environment() const { return m_environment; }

std::filesystem::path ExecPath() const;
std::filesystem::path EnvsPath() const;
std::filesystem::path IPCatalogPath() const;

Expand Down Expand Up @@ -98,6 +97,7 @@ class IPGenerator {
std::map<std::string, std::string> m_environment;

private:
std::filesystem::path m_installDir;
std::map<std::string, std::filesystem::path> m_ipOutputLocations;

void dumpDeviceInfo(const std::filesystem::path&);
Expand Down
2 changes: 1 addition & 1 deletion src/IpConfigurator/IPDialogBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ std::pair<std::string, std::string> IPDialogBox::generateNewJson(
jsonF.insert(param.Name(), value);
}

jsonF["build_dir"] = inst->OutputLocation().string();
jsonF["build_dir"] = FileUtils::resolvePathStr(inst->OutputLocation().string());
jsonF["build_name"] = inst->ModuleName();
jsonF["build"] = false;
jsonF["json"] = jsonFile.filename().string();
Expand Down
75 changes: 3 additions & 72 deletions src/Main/Foedag_ql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,9 @@ extern "C" {
#include "ProjectFile/ProjectFileLoader.h"
#include "Tcl/TclInterpreter.h"
#include "Utils/FileUtils.h"
#include "Utils/PathUtils.h"
#include "qttclnotifier.hpp"

#if defined(_MSC_VER)
#include <direct.h>
#define PATH_MAX _MAX_PATH
#else
#include <sys/param.h>
#include <unistd.h>
#endif

#if (defined(__MINGW32__))
#include <windows.h> // for FreeConsole()
#endif
Expand All @@ -89,65 +82,6 @@ FOEDAG::GUI_TYPE Foedag::getGuiType(const bool& withQt, const bool& withQml) {
return FOEDAG::GUI_TYPE::GT_WIDGET;
}

bool getFullPath(const std::filesystem::path& path,
std::filesystem::path* result) {
std::error_code ec;
std::filesystem::path fullPath = std::filesystem::canonical(path, ec);
bool found = (!ec && std::filesystem::is_regular_file(fullPath));
if (result != nullptr) {
*result = found ? fullPath : path;
}
return found;
}

// Try to find the full absolute path of the program currently running.
static std::filesystem::path GetProgramNameAbsolutePath(const char* progname) {
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
const char PATH_DELIMITER = ';';
#else
char buf[PATH_MAX];
// If the executable is invoked with a path, we can extract it from there,
// otherwise, we use some operating system trick to find that path:
// In Linux, the current running binary is symbolically linked from
// /proc/self/exe which we can resolve.
// It won't resolve anything on other platforms, but doesnt harm either.
for (const char* testpath : {progname, "/proc/self/exe"}) {
const char* const program_name = realpath(testpath, buf);
if (program_name != nullptr) return program_name;
}
const char PATH_DELIMITER = ':';
#endif

// Still not found, let's go through the $PATH and see what comes up first.
const char* const path = std::getenv("PATH");
if (path != nullptr) {
std::stringstream search_path(path);
std::string path_element;
std::filesystem::path program_path;
while (std::getline(search_path, path_element, PATH_DELIMITER)) {
const std::filesystem::path testpath =
path_element / std::filesystem::path(progname);
if (getFullPath(testpath, &program_path)) {
return program_path;
}
#if _WIN32
// additional search for cmd.exe, we need to be specific about the program name + extension!
// TODO: why don't we use the Qt method to get the path definitively?
else {
std::string progname_exe_str = std::string(progname) + std::string(".exe");
const std::filesystem::path testpath_exe =
path_element / std::filesystem::path(progname_exe_str);
if (getFullPath(testpath_exe, &program_path)) {
return program_path;
}
}
#endif // #if _WIN32
}
}

return progname; // Didn't find anything, return progname as-is.
}

void loadTclInitFile(CommandStack* commandStack,
const std::string& initFilePrefix) {
if (!commandStack) return;
Expand Down Expand Up @@ -180,11 +114,8 @@ Foedag::Foedag(FOEDAG::CommandLine* cmdLine, MainWindowBuilder* mainWinBuilder,
if (context == nullptr)
m_context = new ToolContext("Aurora", "QuickLogic", "aurora");
if (m_context->BinaryPath().empty()) {
std::filesystem::path exePath =
GetProgramNameAbsolutePath(m_cmdLine->Argv()[0]);
std::filesystem::path exeDirPath = exePath.parent_path();
m_context->BinaryPath(exeDirPath);
std::filesystem::path installDir = exeDirPath.parent_path();
m_context->BinaryPath(PathUtils::instance().exeDir());
std::filesystem::path installDir = PathUtils::instance().installDir();

// for generic usage (not specific to device-data) use the DataPath()
// API which will always be 'install_dir_path'/device_data/
Expand Down
3 changes: 3 additions & 0 deletions src/Main/main_ql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "Main/ToolContext.h"
#include "MainWindow/Session.h"
#include "MainWindow/main_window.h"
#include "Utils/PathUtils.h"

QWidget* mainWindowBuilder(FOEDAG::Session* session) {
auto m = new FOEDAG::MainWindow{session};
Expand All @@ -41,6 +42,8 @@ int main(int argc, char** argv) {
FOEDAG::CommandLine* cmd = new FOEDAG::CommandLine(argc, argv);
cmd->processArgs();

FOEDAG::PathUtils::instance().init(cmd->Argv()[0]);

FOEDAG::GUI_TYPE guiType =
FOEDAG::Foedag::getGuiType(cmd->WithQt(), cmd->WithQml());

Expand Down
2 changes: 2 additions & 0 deletions src/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ set (SRC_CPP_LIST
QtUtils.cpp
LogUtils.cpp
JsonWriter.cpp
PathUtils.cpp
)

set (SRC_H_INSTALL_LIST
Expand All @@ -59,6 +60,7 @@ set (SRC_H_INSTALL_LIST
LogUtils.h
JsonWriter.h
SerializationUtils.h
PathUtils.h
)

set (SRC_H_LIST
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ Return FileUtils::ExecuteSystemCommand(const std::string& command,
m_processes.push_back(&process);
process.start(program, args_);
}
// qDebug() << ExecuteSystemCommand" << program << args_.join(" ");
// qDebug() << "ExecuteSystemCommand" << program << args_.join(" ");

bool finished = process.waitForFinished(timeout_ms);
auto it = std::find(m_processes.begin(), m_processes.end(), &process);
Expand Down
Loading
Loading