gwsystems / composite

A component-based OS
composite.seas.gwu.edu
185 stars 70 forks source link

Add an auto formatter to composite + auto format existing code #270

Closed Others closed 7 years ago

Others commented 7 years ago

Summary of this Pull Request (PR)

This commit adds an auto formatter script to composite format in the root directory. It is based on clang format, and uses the rules in the .clang-format file. This might need a little bikeshedding to get right, and perhaps even some style guide changes. However I think it will be super valuable to get this merged, so we can start automatically formatting our composite code.

For the purposes of reviewing this, looking at .clang-format and format are absolutely key. And it might be a good idea to scan through some code to see if anything looks weird/not stylistically correct.

Intent for your PR

Choose one (Mandatory):

Reviewers (Mandatory):

(Specify @<github.com username(s)> of the reviewers. Ex: @user1, @user2) @gparmer

Code Quality

As part of this pull request, I've considered the following:

Style:

Code Craftsmanship:

Testing

N/A. I just ran the current runscripts to verify everything still is semantically correct.

Others commented 7 years ago

Limitations:

Broken things:

gparmer commented 7 years ago

One more thing it breaks: assembly strings in macros. Perhaps we can manually surround these with /* clang-format off */ assembly bs /* clang-format */

gparmer commented 7 years ago

You should also add documentation for this. Likely:

I'm sorry this is a pain, but there isn't much reason to do all of this if we don't integrate it into the process to some degree. I agree that the build system can be later, but some documentation is required.

Also, add an issue to update the style guide with the style as determined by llvm. I can do that later.

gparmer commented 7 years ago

Possible changes:

BinPackParameters: true Cpp11BracedListStyle: true MaxEmptyLinesToKeep: 1 SpacesInSquareBrackets:false

gparmer commented 7 years ago

Last comment: format should be format.sh and should likely be in tools/

Others commented 7 years ago

@gparmer: Okay, pushed some changes, but still have a few remaining comments:

gparmer commented 7 years ago

@Others

Did you remove ck from the formatting? Doesn't look like it; not sure?

Did you add the comments to avoid formatting around assembly definitions? Looks like no? At least add documentation to the autoformatter file for how to do this, and note that it might be required around defines that include assembly.

Others commented 7 years ago

@gparmer I fixed the assembly by excluding them in the script. Is that fine or do you want them specifically excluded with comment pragmas?

I'll fix the rest of your notes ASAP

gparmer commented 7 years ago

Are we talking about the same thing. You obviously didn't apply this to assembly files.

But you did apply it to C files that have #defines that include and generate assembly. And for the assembly contents of those defines, the indentation gets messed up. I noted this in my original comments.

Others commented 7 years ago

@gparmer yes I know. I specifically excluded the .h files that had the assembly in question. But this is probably the wrong thing to do now that I think about it. I'll switch to using comment pragmas instead.

Others commented 7 years ago

(Also ck was never formatted as far as I can tell by diffing against upstream/ppos.)

gparmer commented 7 years ago

This is brilliant! Thanks @Others for automating this important aspect of our development. Very very much appreciated.