Skip to content

Commit 5bb1c1b

Browse files
committed
doc: developer guide for scopy
Signed-off-by: IonutMuthi <[email protected]>
1 parent 2b1c2c9 commit 5bb1c1b

File tree

3 files changed

+965
-1
lines changed

3 files changed

+965
-1
lines changed

docs/developer_guide/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ Contents
1717

1818
.. toctree::
1919
:includehidden:
20-
:maxdepth: 3
20+
:maxdepth: 1
2121

2222
style
23+
package_generator
24+
plugin_developer_guide
2325

2426

Lines changed: 379 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,379 @@
1+
.. _package_generator:
2+
3+
4+
Package Generator
5+
================================================================================
6+
7+
8+
Chapters
9+
10+
- `1. Overview <#overview>`_
11+
- `2. Platform <#platform>`_
12+
- `3. Running the Script <#running-the-script>`_
13+
- `4. Configuration Files <#configuration-files>`_
14+
- `5. Manifest File <#manifest-file>`_
15+
- `6. Packages development flow <#packages-development-flow>`_
16+
- `7. Scopy PDK <#scopy-pdk>`_
17+
- `8. Adding New Config Specifications <#adding-new-config-specifications>`_
18+
19+
20+
Overview
21+
--------------------------------------------------------------------------------
22+
The `package_generator.py` script is a utility for generating and managing packages,
23+
plugins, and related resources for the Scopy project. It provides functionality to
24+
create package structures, generate plugins, handle translations, manage styles, and more.
25+
26+
Platform
27+
--------------------------------------------------------------------------------
28+
The `package_generator.py` script is designed to work on Linux, Windows, and macOS.
29+
Below are platform-specific details and instructions:
30+
31+
**Linux**
32+
33+
- **Prerequisites**:
34+
- Ensure Python 3 is installed.
35+
- Install Git and other required tools using your package manager:
36+
37+
.. code-block:: bash
38+
39+
sudo apt update && sudo apt install git python3-pip
40+
41+
- Install the required Python dependencies:
42+
43+
.. code-block:: bash
44+
45+
pip install -r requirements.txt
46+
47+
- **Running the Script**:
48+
- Use the terminal to navigate to the `scopy/tools/packagegenerator` directory and run:
49+
50+
.. code-block:: bash
51+
52+
./package_generator.py
53+
54+
**Windows**
55+
56+
- **Prerequisites**:
57+
- Install Python 3 from https://www.python.org/.
58+
- Ensure Git is installed and added to the system `PATH`.
59+
- Install the required Python dependencies:
60+
61+
.. code-block:: bash
62+
63+
pip install -r requirements.txt
64+
65+
- **Running the Script**:
66+
- Open a Command Prompt or PowerShell, navigate to the `scopy/tools/packagegenerator` directory, and run:
67+
68+
.. code-block:: bash
69+
70+
python package_generator.py
71+
72+
- **Note**:
73+
- On Windows, the script does not use POSIX file permissions (`MODE = 0o775`), so permissions-related functionality is skipped.
74+
75+
**macOS**
76+
77+
- **Prerequisites**:
78+
- Ensure Python 3 is installed (can be installed via Homebrew: https://brew.sh/):
79+
80+
.. code-block:: bash
81+
82+
brew install python3
83+
84+
- Install Git:
85+
86+
.. code-block:: bash
87+
88+
brew install git
89+
90+
- Install the required Python dependencies:
91+
92+
.. code-block:: bash
93+
94+
pip3 install -r requirements.txt
95+
96+
- **Running the Script**:
97+
- Use the terminal to navigate to the `scopy/tools/packagegenerator` directory and run:
98+
99+
.. code-block:: bash
100+
101+
./package_generator.py
102+
103+
- **Note**:
104+
- macOS handles file permissions similarly to Linux, so no additional adjustments are needed.
105+
106+
Running the Script
107+
--------------------------------------------------------------------------------
108+
**Basic Usage**
109+
110+
1. If the script is run from the `scopy/tools/packagegenerator` directory:
111+
112+
.. code-block:: bash
113+
114+
./package_generator.py
115+
116+
2. Otherwise, specify the paths to the Scopy repository and configuration files:
117+
118+
.. code-block:: bash
119+
120+
./package_generator.py --scopy_path=path/to/scopy --config_file_path=path/to/pkg.json
121+
122+
For help, run:
123+
124+
.. code-block:: bash
125+
126+
./package_generator.py -h
127+
128+
**Example Commands**
129+
130+
1. Generate a complete package structure:
131+
132+
.. code-block:: bash
133+
134+
./package_generator.py --all
135+
136+
2. Generate a plugin using a specific configuration file:
137+
138+
.. code-block:: bash
139+
140+
./package_generator.py -p /path/to/plugin.json
141+
142+
3. Add translations to a package:
143+
144+
.. code-block:: bash
145+
146+
./package_generator.py --translation
147+
148+
4. Add style templates to a package:
149+
150+
.. code-block:: bash
151+
152+
./package_generator.py --style
153+
154+
5. Generate a Plugin Development Kit (PDK):
155+
156+
.. code-block:: bash
157+
158+
./package_generator.py --pdk
159+
160+
6. Initialize a new Git submodule and generate a package:
161+
162+
.. code-block:: bash
163+
164+
./package_generator.py --init
165+
166+
7. Add an existing Git repository as a submodule:
167+
168+
.. code-block:: bash
169+
170+
./package_generator.py --add_submodule <repository_url>
171+
172+
8. Archive all packages in a directory:
173+
174+
.. code-block:: bash
175+
176+
./package_generator.py -a --src /path/to/packages --dest /path/to/archives
177+
178+
Configuration Files
179+
--------------------------------------------------------------------------------
180+
**pkg.json**
181+
182+
The `pkg.json` file contains the configuration details for generating packages. Example:
183+
184+
.. code-block:: json
185+
186+
{
187+
"id": "newpackage",
188+
"title": "New package",
189+
"description": "A new package",
190+
"author": "Analog Devices Inc.",
191+
"license": "LGPL",
192+
"category": ["iio", "plugin"]
193+
}
194+
195+
**plugin.json**
196+
197+
The `plugin.json` file contains the configuration details for generating plugins. Example:
198+
199+
.. code-block:: json
200+
201+
{
202+
"baseplugin": false,
203+
"plugin_name": "newplugin",
204+
"plugin_display_name": "New Plugin",
205+
"plugin_description": "A new plugin",
206+
"class_name": "NEWPlugin",
207+
"namespace": "scopy::newplugin",
208+
"device_category": "iio",
209+
"tools": [
210+
{
211+
"id": "newtool1",
212+
"tool_name": "Tool1",
213+
"file_name": "tool1",
214+
"class_name": "Tool1",
215+
"namespace": "scopy::newplugin"
216+
}
217+
],
218+
"cmakelists": {
219+
"cmake_min_required": 3.9,
220+
"cxx_standard": 20,
221+
"enable_testing": "ON"
222+
},
223+
"style": {
224+
"qss": true,
225+
"json": false
226+
},
227+
"test": {
228+
"cmakelists": true,
229+
"cmake_min_required": 3.5,
230+
"tst_pluginloader": true
231+
},
232+
"resources": {
233+
"resources_qrc": true
234+
},
235+
"doc": true,
236+
"pdk": {
237+
"deps_path": "",
238+
"project_path": ""
239+
}
240+
}
241+
242+
Manifest File
243+
--------------------------------------------------------------------------------
244+
The `manifest.json.cmakein` file is generated as part of the package structure. It contains metadata about the package and is used during the build process. Example:
245+
246+
.. code-block:: json
247+
248+
{
249+
"id": "newpackage",
250+
"title": "New Package",
251+
"description": "A new package for Scopy",
252+
"author": "Analog Devices Inc.",
253+
"license": "LGPL",
254+
"category": ["iio", "plugin"]
255+
}
256+
257+
The manifest file is automatically created during the package generation process and ensures that all necessary metadata is included for proper integration with Scopy.
258+
259+
Packages development flow
260+
--------------------------------------------------------------------------------
261+
**New package**
262+
263+
1. Clone Scopy using:
264+
265+
.. code-block:: bash
266+
267+
git clone --branch <branch_or_tag> https://github.com/analogdevicesinc/scopy.git
268+
269+
2. Fill the `pkg.json` and `plugin.json` configuration files (see the pkg.json and plugin.json examples above).
270+
271+
3. Create a package repository using:
272+
273+
.. code-block:: bash
274+
275+
./package_generator.py --init
276+
277+
- To create a repository and a complete package structure:
278+
279+
.. code-block:: bash
280+
281+
./package_generator.py --init --all
282+
283+
- To generate the package structure without a Git repository:
284+
285+
.. code-block:: bash
286+
287+
./package_generator.py --all
288+
289+
- If the package contains only plugins:
290+
291+
.. code-block:: bash
292+
293+
./package_generator.py --plugin
294+
295+
4. Implement the package functionalities, build the package inside Scopy, and test it. After all the work is done, push the sources into the repository.
296+
297+
5. To export the package:
298+
299+
.. code-block:: bash
300+
301+
./package_generator.py -a --src /path/to/package/build/folder --dest /path/to/destination
302+
303+
- The "build folder" is where the package was built, and the "destination" is where the generated archive (zip file) will be saved.
304+
- The archived package can be installed in Scopy using the package manager.
305+
306+
**Existent package**
307+
308+
1. Clone Scopy using:
309+
310+
.. code-block:: bash
311+
312+
git clone --branch <branch_or_tag> https://github.com/analogdevicesinc/scopy.git
313+
314+
2. Add the package as submodule:
315+
316+
.. code-block:: bash
317+
318+
./package_generator.py --add_submodule <repository_url>
319+
320+
3. Implement the package functionalities, build the package inside Scopy, and test it. After all the work is done, push the sources into the repository.
321+
322+
4. To export the package:
323+
324+
.. code-block:: bash
325+
326+
./package_generator.py -a --src /path/to/package/build/folder --dest /path/to/destination
327+
328+
- The "build folder" is where the package was built, and the "destination" is where the generated archive (zip file) will be saved.
329+
- The archived package can be installed in Scopy using the package manager.
330+
331+
Scopy PDK
332+
--------------------------------------------------------------------------------
333+
**Adding New Modules to the PDK Package**
334+
335+
To include a new module in the PDK package, ensure that the `COMPONENT ${SCOPY_PDK}` option is added when installing libraries or directories in `CMakeLists.txt`.
336+
337+
- **Libraries**:
338+
339+
.. code-block:: cmake
340+
341+
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SCOPY_DLL_INSTALL_PATH} COMPONENT ${SCOPY_PDK} RUNTIME DESTINATION ${SCOPY_DLL_INSTALL_PATH})
342+
343+
- **Headers**:
344+
345+
.. code-block:: cmake
346+
347+
install(DIRECTORY include/ DESTINATION include/ COMPONENT ${SCOPY_PDK})
348+
349+
- **Resources**:
350+
351+
.. code-block:: cmake
352+
353+
install(DIRECTORY res/ DESTINATION resources/ COMPONENT ${SCOPY_PDK})
354+
355+
**Developing a New Plugin Using ScopyPluginRunner**
356+
357+
1. Download the PDK package from the Scopy repository.
358+
- If the package is unavailable or changes have been made to the Scopy libraries, build Scopy locally with the `--target package` option.
359+
- This will generate a `package` folder inside the Scopy build directory.
360+
361+
2. Generate the ScopyPluginRunner project using `package_generator.py`.
362+
- Fill in the `plugin.json` file.
363+
- The project will contain a `plugin` submodule where the desired plugin can be developed.
364+
365+
3. Choose an IDE and start working.
366+
- **Recommendation**: Use QtCreator.
367+
368+
Adding New Config Specifications
369+
--------------------------------------------------------------------------------
370+
To add new specifications for fields like `plugin`, `tool`, or `cmakelists`, follow these steps:
371+
372+
1. Add the new specification to the desired field in `pkg.json` or `plugin.json`.
373+
2. Use the specification in the templates. Each template contains a `config` variable to access the field's information. Use the Mako template syntax (https://docs.makotemplates.org/en/latest/) for rendering.
374+
- Changes to the `plugin` field will affect the `plugin_src` and `plugin_header` files.
375+
- Changes to the `tool` field will affect the `tool_src` and `tool_header` files.
376+
- Changes to the `cmakelists` field will affect the `cmakelists` file.
377+
3. Run the `package_generator.py` script to apply the changes.
378+
379+

0 commit comments

Comments
 (0)