Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topology2 doxygen documentation infrastructure #8141

Merged
merged 16 commits into from
Oct 6, 2023

Conversation

jsarha
Copy link
Contributor

@jsarha jsarha commented Sep 1, 2023

Now this starts to be a little closer where it should be. There is still a lot of comments to be turned into Doxygen documentation, not to mention, documentation to be written for completely undocumented topology code. I will at least convert the existing comments as soon as the generic appearance of this exercise is accepted.

@jsarha jsarha requested a review from lgirdwood September 1, 2023 12:02
Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start and easy to follow the documentation style in the topology conf. Needs a lot more commentary in the python file and description of processing.
@ranj063 pls review

tools/topology/topology2/doc/topology2-filter.py Outdated Show resolved Hide resolved
tools/topology/topology2/doc/build/sof.doxygen Outdated Show resolved Hide resolved
@lgirdwood lgirdwood added this to the v2.8 milestone Sep 8, 2023
@jsarha jsarha marked this pull request as ready for review September 25, 2023 17:31
@jsarha jsarha requested a review from ranj063 as a code owner September 25, 2023 17:31
@jsarha jsarha changed the title Topology2 doxygen documentation infrastructure [DNM yet] Topology2 doxygen documentation infrastructure Sep 25, 2023
@jsarha
Copy link
Contributor Author

jsarha commented Sep 25, 2023

Turned this ready for review to gather more attention, but I still intent to turn at least the most relevant pieces of existing comments into Doxygen documentation before this is ready to merge (in any case it hardly is that yet).

If one wants to generate the documentation do following steps:

  1. cd tools/topology/topology2/doc
  2. mkdir build
  3. cd build
  4. cmake ..
  5. make
    After the last command you should find the html documentation under: sof/tools/topology/topology2/doc/build/doxygen/html

@ranj063
Copy link
Collaborator

ranj063 commented Sep 25, 2023

Now this starts to be a little closer where it should be. There is still a lot of comments to be turned into Doxygen documentation, not to mention, documentation to be written for completely undocumented topology code. I will at least convert the existing comments as soon as the generic appearance of this exercise is accepted.

@jsarha thank you for starting this. Looks good to me. Just a few typos to fix

@jsarha
Copy link
Contributor Author

jsarha commented Sep 26, 2023

  • rebased on top of latest main
  • mainpage.dox
    • add copyright
  • topology2-filter.py
    • fix typos in topology2-filter.py comments
    • fix attribute definitions in topology2 snippets
    • Add IncludeByKey contents into topology2 snippets and create basic #if #include structures
    • add copyright
  • Turn comments to doxygen documentation in some common files

@jsarha jsarha requested a review from marc-hb as a code owner September 27, 2023 16:33
@jsarha
Copy link
Contributor Author

jsarha commented Sep 27, 2023

Some more comments changed to doxygen. Updated the contents page. Its now autogenerated, but unfortunately I could not get cmake to generate it automatically. Any idea how to do it?

@jsarha jsarha changed the title [DNM yet] Topology2 doxygen documentation infrastructure Topology2 doxygen documentation infrastructure Sep 27, 2023
USES_TERMINAL
)

add_custom_target("doc-clean"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately you need BOTH add_custom_target() AND add_custom_command() for each target every time. Do not put any commands in add_custom_target(), add them to add_custom_command() only.

This really sucks but it's required. Best explanation why:

https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not have time to do this yet. Will do it at some point,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't define "clean" targets:

  • CMake does this automatically when you use it right
  • For "distclean" the only reliable, official and documented CMake way is to delete the entire build directory.

print(str);
return True
return False
# Parses topology2 Define { } block and outputs C-preprocessor #define macros
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pydoc syntax for this.

Also use pylint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

# find the pieces of related Doxygen documentation. The filter also
# creates separate pages of the original code and adds links next to the
# pages in the C struct definition, instance documentation and their
# possible Doxygen documentation.
Copy link
Collaborator

@marc-hb marc-hb Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This look like implementing a new parser entirely from scratch? Have you considered using a framework?

https://tomassetti.me/parsing-in-python/
https://stackoverflow.com/questions/6571964/which-tool-to-use-to-parse-programming-languages-in-python

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I started, I did not yet know what I need. I first thought that I can just translate everything as I go through the file, with very little state information. Parts of the translation still works like that, but then there are many places where more state is needed and bigger chucks has to be processed statefully.

If I would start from scratch now, I would probably use some more advanced method, but this is now here and it pretty much does what is needed, so I leave that excercise to a later time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I would start from scratch now, I would probably use some more advanced method, but this is now here and it pretty much does what is needed, so I leave that excercise to a later time.

Please add this "technical debt" warning comment at the top of the file so this does not become a time sink for someone else.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping.

Also: please run pylint and fix at least the scariest warnings (I haven't reviewed the Python code, too long)

@jsarha jsarha force-pushed the topology2-doxygen branch 2 times, most recently from 7864b71 to a1f00e6 Compare September 28, 2023 20:01
@jsarha
Copy link
Contributor Author

jsarha commented Sep 28, 2023

  • Improve attribute C type selection code
  • Turn topology2-filter.py function comments to pydoc
  • Add README to instruct how to build the documentation
  • Add license, copyright, and brief comment on what topology2-generate-contents.sh does

@jsarha
Copy link
Contributor Author

jsarha commented Sep 29, 2023

Some minor typofixes. And dropped an idle commit of spurious change.

# find the pieces of related Doxygen documentation. The filter also
# creates separate pages of the original code and adds links next to the
# pages in the C struct definition, instance documentation and their
# possible Doxygen documentation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping.

Also: please run pylint and fix at least the scariest warnings (I haven't reviewed the Python code, too long)

tools/topology/topology2/doc/README Outdated Show resolved Hide resolved
tools/topology/topology2/doc/README Outdated Show resolved Hide resolved
@jsarha
Copy link
Contributor Author

jsarha commented Oct 2, 2023

@jsarha jsarha force-pushed the topology2-doxygen branch from 79c46d6 to d04451e Compare October 2, 2023 19:04
@marc-hb
Copy link
Collaborator

marc-hb commented Oct 4, 2023

Sure, I can spend couple of hours inventing a wheel, and writing some script that mangles the correct paths to doxygen config file,

That should be one or two lines.

then run the topology2 class index generator script,
and finally run doxygen to produce the documentation tree. I just want to know for sure that this is what you want,

and that this review process is converging to some conclusion.

CMake always tends to be a verbosity and complexity nightmare even for the simplest things and I don't see the CMake part of this PR converging quickly. That's why I'm asking to postpone it to the next PR not to hold this one back.

So should I give up on CMakeLists.txt and make another script for building the documentation?

Yes please but it does not have to be a different script, I think you can just add it to the existing one. Or it can be a different and very short one. This will be much faster because: 1. it should be short either way 2. shell scripting is less powerful but much simpler than CMake 3. Like most people, you seem comfortable with the former but not the latter.

@lgirdwood
Copy link
Member

CMake always tends to be a verbosity and complexity nightmare even for the simplest things and I don't see the CMake part of this PR converging quickly. That's why I'm asking to postpone it to the next PR not to hold this one back.

So should I give up on CMakeLists.txt and make another script for building the documentation?

Yes please but it does not have to be a different script, I think you can just add it to the existing one. Or it can be a different and very short one. This will be much faster because: 1. it should be short either way 2. shell scripting is less powerful but much simpler than CMake 3. Like most people, you seem comfortable with the former but not the latter.

Don't we have somthing that works with CMake now with the required fixes identified above (and some can even be click to merge) ?

Jyri Sarha added 2 commits October 4, 2023 19:11
This is the second version of topology2 to C Doxygen filter. Its far
from perfect, but it should get us started.

The purpose of the translated C code is not to document actual
topology2 code, but only to provide anchors for Doxygen to form a
network of links through which to navigate the topology sources and
find the pieces of related Doxygen documentation. The filter also
creates separate pages of the original code and adds links next to the
pages in the C struct definition, instance documentation and their
possible Doxygen documentation.

Signed-off-by: Jyri Sarha <[email protected]>
Includes all *.conf files under topology2 to the Doxygen documentation
and points directly to mainpage Doxygen source.

Signed-off-by: Jyri Sarha <[email protected]>
@jsarha jsarha force-pushed the topology2-doxygen branch from eec1886 to 4b392e5 Compare October 4, 2023 16:16
@jsarha
Copy link
Contributor Author

jsarha commented Oct 4, 2023

  • use python logging in topology2-filter.py
  • separate commands and targets in cmake
  • add dependencies to cmake
  • update README

Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the (tedious, painful) CMake effort! This is starting to look good, small changes requested.

)

add_custom_target("doc-clean"
COMMAND rm -rf ${PROJECT_BINARY_DIR}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This target is literally longer to type and use than the command it runs. This is not the CMake way (which already generates a "clean" target)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't call it just "clean":
CMake Error at CMakeLists.txt:49 (add_custom_target):
The target name "clean" is reserved or not valid for certain CMake
features, such as generator expressions, and may result in undefined
behavior.

I'll drop the target all together. it should not be needed for anything, now that the dependencies are handled correctly.

tools/topology/topology2/doc/CMakeLists.txt Outdated Show resolved Hide resolved
tools/topology/topology2/doc/CMakeLists.txt Outdated Show resolved Hide resolved
tools/topology/topology2/doc/CMakeLists.txt Show resolved Hide resolved
@jsarha
Copy link
Contributor Author

jsarha commented Oct 5, 2023

Can't finish the job today. I'll go to office and lab now, and I do not have time this evening, but I try to pull this together tomorrow.

@jsarha jsarha force-pushed the topology2-doxygen branch from 4b392e5 to 18b4aa7 Compare October 5, 2023 14:15
@jsarha
Copy link
Contributor Author

jsarha commented Oct 5, 2023

  • Idle double guotes dropped from cmake targets
  • doc-clean target dropped

@jsarha jsarha force-pushed the topology2-doxygen branch from 18b4aa7 to 53a9e6f Compare October 6, 2023 10:32
@jsarha
Copy link
Contributor Author

jsarha commented Oct 6, 2023

Oh, I fogot yesterday the cat << EOF change. No that is added too. I think I've now addressed all the issue pointed by @marc-hb .

Jyri Sarha added 12 commits October 6, 2023 13:47
…ntents

This commit adds topology2-generate-contents.sh the script to generate the
contents page that will be inline included to the mainpage added in the next
commit.

Signed-off-by: Jyri Sarha <[email protected]>
The initial main-page contains a short introduction into topology2
Doxygen documentation, and an inline reference to automatically
generated contents page.

The commit also adds more advanced cmake rules to track all document
dependencies.

Signed-off-by: Jyri Sarha <[email protected]>
Improve and convert comments to doxygen documentation.

Signed-off-by: Jyri Sarha <[email protected]>
Doxygenify all comments that are correctly placed near the attribute's
or objects C-translation. This is not the case for comments before
Object.Base { } definition or comment before including
pipeline-common.conf, which is inlined by the topology2 filter, does
not end up in any relevant place, so its better just leave those
comments as they are. They can anyway be read from topology2 source
snippets.

Signed-off-by: Jyri Sarha <[email protected]>
Change attribute comments to Doxygen comments.

Signed-off-by: Jyri Sarha <[email protected]>
There were couple of classes that did not have their topology2 snippets
showing. Probably the essential problem was just the class definition
starting from the first line of the file. There was nothing obviously
wrong in the output of the filter, but the way the doxygen works is
sometimes hard to anticipate. Adding \struct before the definition
fixed the problem.

Signed-off-by: Jyri Sarha <[email protected]>
@jsarha jsarha force-pushed the topology2-doxygen branch from 53a9e6f to cf09373 Compare October 6, 2023 10:48
@jsarha
Copy link
Contributor Author

jsarha commented Oct 6, 2023

Oh, and couple of other contents scripts changes too, and their dependency to CMakeLists.txt. But now, this should be good.

Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience and hard work, CMake is never fun.

@lgirdwood lgirdwood merged commit c1996e0 into thesofproject:main Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants