Skip to content

Commit

Permalink
omnetpp: above version 6.1, auto-import projects defined in $OPP_ENV_…
Browse files Browse the repository at this point in the history
…PROJECT_DEPS

Based on the content of the OPP_ENV_PROJECT_DEPS environment variable.
  • Loading branch information
avarga committed Oct 11, 2024
1 parent 8264ef5 commit c768664
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
5 changes: 5 additions & 0 deletions opp_env/database/omnetpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ def make_omnetpp_project_description(version, base_version=None, is_modernized=F
"sed -i 's|^WITH_TKENV=yes|WITH_TKENV=no|' configure.user" if version >= "5.0" and version < "6.0" and is_macos and is_aarch64 else None, # on macos aarch64, tkenv is not supported
f"sed -i '/^PERL =/i CFLAGS += {extra_cflags}' Makefile.inc.in" if extra_cflags and version >= "4.0" else # no Makefile.inc.in in 3.x yet
f"sed -i 's/^CFLAGS=.*/CFLAGS=\\\"-O2 -DNDEBUG=1 {extra_cflags}\\\"/' configure.user" if extra_cflags and version < "4.0" else None, # no Makefile.inc.in in 3.x yet

# use the opp_env workspace as the default IDE workspace (on 6.1 or later, where auto importing of projects are supported)
# and copy IDE startup script into it (auto-imports projects)
"sed -i 's|../samples|../..|' src/utils/opp_ide""" if version >= "6.1" else None,
"mkdir -p ../.metadata && cp \"$OPP_ENV_DIR/templates/metadata/startup.bsh\" ../.metadata" if version >= "6.1" else None,
]

# More recent releases can handle parallel build
Expand Down
82 changes: 82 additions & 0 deletions opp_env/templates/metadata/startup.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// This is the startup script for the OMNeT++ IDE, added by opp_env.
// It is automatically executed when the IDE starts up. It ensures that
// projects active in the opp_env session are imported and opened,
// and the project references are correctly set up.
//

//System.out.println("startup.bsh: Running");

void importAndOpenProject(String projectName, String[] referencedProjectNames) {
workspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace();
projectDir = workspace.getRoot().getLocation().append(projectName);
projectFile = projectDir.append(".project");
if (projectFile.toFile().exists()) {
//System.out.println("startup.bsh: Importing/opening " + projectName);
description = workspace.loadProjectDescription(projectFile);
description.setName(projectName);
project = workspace.getRoot().getProject(description.getName());
if (!project.exists())
project.create(description, null);
if (!project.isOpen())
project.open(null);

referencedProjects = new org.eclipse.core.resources.IProject[referencedProjectNames.length];
for (int i = 0; i < referencedProjectNames.length; i++)
referencedProjects[i] = workspace.getRoot().getProject(referencedProjectNames[i]);
description = project.getDescription();
description.setReferencedProjects(referencedProjects);
project.setDescription(description, null);
}
}

void closeOtherProjects(ArrayList projectNames) {
workspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace();
workspaceProjects = workspace.getRoot().getProjects();
for (int j = 0; j < workspaceProjects.length; j++)
if (!projectNames.contains(workspaceProjects[j].getName()) && workspaceProjects[j].isOpen()) {
//System.out.println("startup.bsh: Closing " + workspaceProjects[j].getName());
workspaceProjects[j].close(null);
}
}

void importAndOpenProjectsWithDependencies(String projectDepsEnv) {
collectedProjectNames = new ArrayList<String>();

if (projectDepsEnv != null && !projectDepsEnv.isEmpty()) {
// Split by ';' to get each project definition
String[] projectEntries = projectDepsEnv.split(";");

// Iterate over each project entry to parse the dependencies and call importAndOpenProject
for (int i = 0; i < projectEntries.length; i++) {
String entry = projectEntries[i].trim();
if (entry.isEmpty())
continue;

// Split by ':' to separate the project name from its dependencies, and split up the dependencies
String[] parts = entry.split(":", 2);
String projectName = parts[0].trim();
String dependencies = parts.length > 1 ? parts[1].trim() : "";
String[] referencedProjectNames = dependencies.isEmpty() ? new String[0] : dependencies.split("[ ,]+");

// Collect the project name
collectedProjectNames.add(projectName);

// Import / open project
if (!projectName.startsWith("omnetpp-"))
importAndOpenProject(projectName, referencedProjectNames);
}
}

closeOtherProjects(collectedProjectNames);
}

// Read the OPP_ENV_PROJECT_DEPS environment variable.
// The OPP_ENV_PROJECT_DEPS environment variable is formatted as a semicolon-separated list
// of project entries, where each entry consists of a project name optionally
// followed by a colon and a list of dependencies separated by spaces or commas
// (e.g., "proj1: dep1 dep2 dep3; proj2: dep4,dep5; proj3; proj4:dep6").
String projectDepsEnv = System.getenv("OPP_ENV_PROJECT_DEPS");
importAndOpenProjectsWithDependencies(projectDepsEnv);

//System.out.println("startup.bsh: Completed");

0 comments on commit c768664

Please # to comment.