Skip to content

Commit 5aea721

Browse files
committed
[projmgr] Extend SWIG interface
1 parent 6f2f061 commit 5aea721

15 files changed

Lines changed: 279 additions & 87 deletions

File tree

.github/workflows/projmgr.yml

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,30 +95,48 @@ jobs:
9595
retention-days: 1
9696
if-no-files-found: error
9797

98-
- name: Build projmgr swig libs
98+
- name: Build projmgr swig libs windows
99+
if: ${{ startsWith(matrix.os, 'windows') }}
99100
run: |
100101
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DSWIG_LIBS=ON ..
101-
cmake --build . --target projmgr --config Release
102+
cmake --build . --target projmgr-python --config Release
102103
working-directory: ./buildswig
103104

104-
- name: Archive projmgr swig libs windows
105+
- name: Build projmgr swig libs macos ubuntu
106+
if: ${{ startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu') }}
107+
run: |
108+
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DSWIG_LIBS=ON ..
109+
cmake --build . --target projmgr-python projmgr-go --config Release
110+
working-directory: ./buildswig
111+
112+
- name: Archive projmgr swig python libs windows
105113
if: ${{ startsWith(matrix.os, 'windows') }}
106114
uses: actions/upload-artifact@v2
107115
with:
108-
name: projmgr-swig-${{ matrix.target }}
116+
name: projmgr-swig-python-${{ matrix.target }}
117+
path: |
118+
./buildswig/tools/projmgr/swig/python/projmgr.py
119+
./buildswig/tools/projmgr/swig/python/_projmgr.pyd
120+
retention-days: 1
121+
122+
- name: Archive projmgr swig python libs macos ubuntu
123+
if: ${{ startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu') }}
124+
uses: actions/upload-artifact@v2
125+
with:
126+
name: projmgr-swig-python-${{ matrix.target }}
109127
path: |
110-
./buildswig/tools/projmgr/swig/projmgr.py
111-
./buildswig/tools/projmgr/swig/_projmgr.pyd
128+
./buildswig/tools/projmgr/swig/python/projmgr.py
129+
./buildswig/tools/projmgr/swig/python/_projmgr.so
112130
retention-days: 1
113131

114-
- name: Archive projmgr swig libs macos ubuntu
132+
- name: Archive projmgr swig go libs macos ubuntu
115133
if: ${{ startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu') }}
116134
uses: actions/upload-artifact@v2
117135
with:
118-
name: projmgr-swig-${{ matrix.target }}
136+
name: projmgr-swig-go-${{ matrix.target }}
119137
path: |
120-
./buildswig/tools/projmgr/swig/projmgr.py
121-
./buildswig/tools/projmgr/swig/_projmgr.so
138+
./buildswig/tools/projmgr/swig/go/projmgr.go
139+
./buildswig/tools/projmgr/swig/go/projmgr.so
122140
retention-days: 1
123141

124142
release:
@@ -157,23 +175,35 @@ jobs:
157175
name: projmgr-windows64
158176
path: tools/projmgr/distribution/bin/windows64/
159177

160-
- name: Download projmgr-swig linux
178+
- name: Download projmgr-swig-python linux
179+
uses: actions/download-artifact@v2
180+
with:
181+
name: projmgr-swig-python-linux64
182+
path: tools/projmgr/distribution/lib/linux64/python/
183+
184+
- name: Download projmgr-swig-python macos
185+
uses: actions/download-artifact@v2
186+
with:
187+
name: projmgr-swig-python-darwin64
188+
path: tools/projmgr/distribution/lib/darwin64/python/
189+
190+
- name: Download projmgr-swig-python windows
161191
uses: actions/download-artifact@v2
162192
with:
163-
name: projmgr-swig-linux64
164-
path: tools/projmgr/distribution/lib/linux64/
193+
name: projmgr-swig-python-windows64
194+
path: tools/projmgr/distribution/lib/windows64/python/
165195

166-
- name: Download projmgr-swig macos
196+
- name: Download projmgr-swig-go linux
167197
uses: actions/download-artifact@v2
168198
with:
169-
name: projmgr-swig-darwin64
170-
path: tools/projmgr/distribution/lib/darwin64/
199+
name: projmgr-swig-go-linux64
200+
path: tools/projmgr/distribution/lib/linux64/go/
171201

172-
- name: Download projmgr-swig windows
202+
- name: Download projmgr-swig-go macos
173203
uses: actions/download-artifact@v2
174204
with:
175-
name: projmgr-swig-windows64
176-
path: tools/projmgr/distribution/lib/windows64/
205+
name: projmgr-swig-go-darwin64
206+
path: tools/projmgr/distribution/lib/darwin64/go/
177207

178208
- name: Zip distribution folder
179209
run: zip -r projmgr.zip *

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,39 +176,39 @@ class ProjMgrWorker {
176176
* @param packs reference to list of packs
177177
* @return true if executed successfully
178178
*/
179-
bool ListPacks(const std::string& filter, std::set<std::string>& packs);
179+
bool ListPacks(const std::string& filter, std::vector<std::string>& packs);
180180

181181
/**
182182
* @brief list available devices
183183
* @param filter words to filter results
184184
* @param packs reference to list of packs
185185
* @return true if executed successfully
186186
*/
187-
bool ListDevices(const std::string& filter, std::set<std::string>& devices);
187+
bool ListDevices(const std::string& filter, std::vector<std::string>& devices);
188188

189189
/**
190190
* @brief list available components
191191
* @param filter words to filter results
192192
* @param packs reference to list of packs
193193
* @return true if executed successfully
194194
*/
195-
bool ListComponents(const std::string& filter, std::set<std::string>& components);
195+
bool ListComponents(const std::string& filter, std::vector<std::string>& components);
196196

197197
/**
198198
* @brief list available dependencies
199199
* @param filter words to filter results
200200
* @param packs reference to list of packs
201201
* @return true if executed successfully
202202
*/
203-
bool ListDependencies(const std::string& filter, std::set<std::string>& dependencies);
203+
bool ListDependencies(const std::string& filter, std::vector<std::string>& dependencies);
204204

205205
/**
206206
* @brief list contexts
207207
* @param filter words to filter results
208208
* @param reference list of contexts
209209
* @return true if executed successfully
210210
*/
211-
bool ListContexts(const std::string& filter, std::set<std::string>& contexts);
211+
bool ListContexts(const std::string& filter, std::vector<std::string>& contexts);
212212

213213
/**
214214
* @brief add contexts for a given descriptor
@@ -221,9 +221,9 @@ class ProjMgrWorker {
221221

222222
/**
223223
* @brief get context map
224-
* @return context map
224+
* @param reference to context map
225225
*/
226-
std::map<std::string, ContextItem>& GetContexts(void);
226+
void GetContexts(std::map<std::string, ContextItem>& contexts);
227227

228228
/**
229229
* @brief copy context files into output directory

tools/projmgr/src/ProjMgr.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,17 @@ bool ProjMgr::RunConvert(void) {
224224
}
225225

226226
// Process contexts
227-
for (auto& context : m_worker.GetContexts()) {
227+
map<string, ContextItem> contexts;
228+
m_worker.GetContexts(contexts);
229+
for (auto& context : contexts) {
228230
if (!m_worker.ProcessContext(context.second, true)) {
229231
ProjMgrLogger::Error("processing context '" + context.first + "' failed");
230232
return false;
231233
}
232234
}
233235

234236
// Generate Cprjs
235-
for (auto& context : m_worker.GetContexts()) {
237+
for (auto& context : contexts) {
236238
error_code ec;
237239
const string& directory = m_outputDir.empty() ? context.second.directories.cproject : m_outputDir + "/" + context.first;
238240
const string& filename = fs::weakly_canonical(directory + "/" + context.first + ".cprj", ec).generic_string();
@@ -252,7 +254,7 @@ bool ProjMgr::RunConvert(void) {
252254
}
253255

254256
bool ProjMgr::RunListPacks(void) {
255-
set<string> packs;
257+
vector<string> packs;
256258
if (!m_worker.ListPacks(m_filter, packs)) {
257259
ProjMgrLogger::Error("processing pack list failed");
258260
return false;
@@ -275,7 +277,7 @@ bool ProjMgr::RunListDevices(void) {
275277
return false;
276278
}
277279
}
278-
set<string> devices;
280+
vector<string> devices;
279281
if (!m_worker.ListDevices(m_filter, devices)) {
280282
ProjMgrLogger::Error("processing devices list failed");
281283
return false;
@@ -296,7 +298,7 @@ bool ProjMgr::RunListComponents(void) {
296298
return false;
297299
}
298300
}
299-
set<string> components;
301+
vector<string> components;
300302
if (!m_worker.ListComponents(m_filter, components)) {
301303
ProjMgrLogger::Error("processing components list failed");
302304
return false;
@@ -319,7 +321,7 @@ bool ProjMgr::RunListDependencies(void) {
319321
if (!m_worker.AddContexts(m_parser, descriptor, m_cprojectFile)) {
320322
return false;
321323
}
322-
set<string> dependencies;
324+
vector<string> dependencies;
323325
if (!m_worker.ListDependencies(m_filter, dependencies)) {
324326
ProjMgrLogger::Error("processing dependencies list failed");
325327
return false;
@@ -353,7 +355,7 @@ bool ProjMgr::RunListContexts(void) {
353355
return false;
354356
}
355357
}
356-
set<string> contexts;
358+
vector<string> contexts;
357359
if (!m_worker.ListContexts(m_filter, contexts)) {
358360
ProjMgrLogger::Error("processing contexts list failed");
359361
return false;

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ bool ProjMgrWorker::AddContext(ProjMgrParser& parser, ContextDesc& descriptor, c
111111
return true;
112112
}
113113

114-
map<string, ContextItem>& ProjMgrWorker::GetContexts(void) {
115-
return m_contexts;
114+
void ProjMgrWorker::GetContexts(map<string, ContextItem>& contexts) {
115+
contexts = m_contexts;
116116
}
117117

118118
void ProjMgrWorker::SetOutputDir(const std::string& outputDir) {
@@ -1028,30 +1028,32 @@ set<string> ProjMgrWorker::SplitArgs(const string& args, const string& delimiter
10281028
return s;
10291029
}
10301030

1031-
bool ProjMgrWorker::ListPacks(const string& filter, set<string>&packs) {
1031+
bool ProjMgrWorker::ListPacks(const string& filter, vector<string>&packs) {
10321032
if (!LoadPacks()) {
10331033
return false;
10341034
}
10351035
if (m_installedPacks.empty()) {
10361036
ProjMgrLogger::Error("no installed pack was found");
10371037
return false;
10381038
}
1039+
set<string> packsSet;
10391040
for (const auto& pack : m_installedPacks) {
1040-
packs.insert(GetPackageID(pack));
1041+
packsSet.insert(GetPackageID(pack));
10411042
}
10421043
if (!filter.empty()) {
10431044
set<string> filteredPacks;
1044-
ApplyFilter(packs, SplitArgs(filter), filteredPacks);
1045+
ApplyFilter(packsSet, SplitArgs(filter), filteredPacks);
10451046
if (filteredPacks.empty()) {
10461047
ProjMgrLogger::Error("no pack was found with filter '" + filter + "'");
10471048
return false;
10481049
}
1049-
packs = filteredPacks;
1050+
packsSet = filteredPacks;
10501051
}
1052+
packs.assign(packsSet.begin(), packsSet.end());
10511053
return true;
10521054
}
10531055

1054-
bool ProjMgrWorker::ListDevices(const string & filter, set<string>& devices) {
1056+
bool ProjMgrWorker::ListDevices(const string & filter, vector<string>& devices) {
10551057
if (!m_contexts.empty()) {
10561058
ContextItem context = m_contexts.begin()->second;
10571059
if (!context.cproject->packages.empty()) {
@@ -1063,6 +1065,7 @@ bool ProjMgrWorker::ListDevices(const string & filter, set<string>& devices) {
10631065
if (!LoadPacks()) {
10641066
return false;
10651067
}
1068+
set<string> devicesSet;
10661069
for (const auto& pack : m_installedPacks) {
10671070
list<RteDeviceItem*> deviceItems;
10681071
pack->GetEffectiveDeviceItems(deviceItems);
@@ -1071,30 +1074,31 @@ bool ProjMgrWorker::ListDevices(const string & filter, set<string>& devices) {
10711074
if (deviceItem->GetProcessorCount() > 1) {
10721075
const auto& processors = deviceItem->GetProcessors();
10731076
for (const auto& processor : processors) {
1074-
devices.insert(deviceName + ":" + processor.first);
1077+
devicesSet.insert(deviceName + ":" + processor.first);
10751078
}
10761079
} else {
1077-
devices.insert(deviceName);
1080+
devicesSet.insert(deviceName);
10781081
}
10791082
}
10801083
}
1081-
if (devices.empty()) {
1084+
if (devicesSet.empty()) {
10821085
ProjMgrLogger::Error("no installed device was found");
10831086
return false;
10841087
}
10851088
if (!filter.empty()) {
10861089
set<string> matchedDevices;
1087-
ApplyFilter(devices, SplitArgs(filter), matchedDevices);
1090+
ApplyFilter(devicesSet, SplitArgs(filter), matchedDevices);
10881091
if (matchedDevices.empty()) {
10891092
ProjMgrLogger::Error("no device was found with filter '" + filter + "'");
10901093
return false;
10911094
}
1092-
devices = matchedDevices;
1095+
devicesSet = matchedDevices;
10931096
}
1097+
devices.assign(devicesSet.begin(), devicesSet.end());
10941098
return true;
10951099
}
10961100

1097-
bool ProjMgrWorker::ListComponents(const string & filter, set<string>& components) {
1101+
bool ProjMgrWorker::ListComponents(const string& filter, vector<string>& components) {
10981102
ContextItem context;
10991103
if (!LoadPacks()) {
11001104
return false;
@@ -1144,52 +1148,56 @@ bool ProjMgrWorker::ListComponents(const string & filter, set<string>& component
11441148
componentIds = filteredIds;
11451149
}
11461150
for (const auto& componentId : componentIds) {
1147-
components.insert(componentId + " (" + GetPackageID(componentMap[componentId]->GetPackage()) + ")");
1151+
components.push_back(componentId + " (" + GetPackageID(componentMap[componentId]->GetPackage()) + ")");
11481152
}
11491153
return true;
11501154
}
11511155

1152-
bool ProjMgrWorker::ListDependencies(const string& filter, set<string>& dependencies) {
1156+
bool ProjMgrWorker::ListDependencies(const string& filter, vector<string>& dependencies) {
11531157
if (m_contexts.empty()) {
11541158
return false;
11551159
}
11561160
ContextItem context = m_contexts.begin()->second;
11571161
if (!ProcessContext(context)) {
11581162
return false;
11591163
}
1164+
set<string>dependenciesSet;
11601165
for (const auto& [component, deps] : context.dependencies) {
11611166
for (const auto& dep : deps) {
1162-
dependencies.insert(component + " " + dep);
1167+
dependenciesSet.insert(component + " " + dep);
11631168
}
11641169
}
11651170
if (!filter.empty()) {
11661171
set<string> filteredDependencies;
1167-
ApplyFilter(dependencies, SplitArgs(filter), filteredDependencies);
1172+
ApplyFilter(dependenciesSet, SplitArgs(filter), filteredDependencies);
11681173
if (filteredDependencies.empty()) {
11691174
ProjMgrLogger::Error("no unresolved dependency was found with filter '" + filter + "'");
11701175
return false;
11711176
}
1172-
dependencies = filteredDependencies;
1177+
dependenciesSet = filteredDependencies;
11731178
}
1179+
dependencies.assign(dependenciesSet.begin(), dependenciesSet.end());
11741180
return true;
11751181
}
11761182

1177-
bool ProjMgrWorker::ListContexts(const string& filter, set<string>& contexts) {
1183+
bool ProjMgrWorker::ListContexts(const string& filter, vector<string>& contexts) {
11781184
if (m_contexts.empty()) {
11791185
return false;
11801186
}
1187+
set<string>contextsSet;
11811188
for (auto& context : m_contexts) {
1182-
contexts.insert(context.first);
1189+
contextsSet.insert(context.first);
11831190
}
11841191
if (!filter.empty()) {
11851192
set<string> filteredContexts;
1186-
ApplyFilter(contexts, SplitArgs(filter), filteredContexts);
1193+
ApplyFilter(contextsSet, SplitArgs(filter), filteredContexts);
11871194
if (filteredContexts.empty()) {
11881195
ProjMgrLogger::Error("no context was found with filter '" + filter + "'");
11891196
return false;
11901197
}
1191-
contexts = filteredContexts;
1198+
contextsSet = filteredContexts;
11921199
}
1200+
contexts.assign(contextsSet.begin(), contextsSet.end());
11931201
return true;
11941202
}
11951203

tools/projmgr/swig/CMakeLists.txt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
find_package(SWIG REQUIRED)
2-
include(${SWIG_USE_FILE})
3-
4-
find_package(PythonLibs)
5-
include_directories(projmgr PUBLIC ${PYTHON_INCLUDE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../include ${PROJECT_BINARY_DIR})
6-
set_source_files_properties(projmgr.i PROPERTIES CPLUSPLUS ON)
7-
8-
swig_add_library(projmgr LANGUAGE python SOURCES projmgr.i)
9-
10-
swig_link_libraries(projmgr ${PYTHON_LIBRARIES} projmgrlib)
1+
add_subdirectory(python)
2+
add_subdirectory(go)

0 commit comments

Comments
 (0)