Skip to content

Conversation

@ion098
Copy link
Contributor

@ion098 ion098 commented Sep 8, 2025

Summary:

This PR adds a Python script to be ran during CI that isolates all the example code snippets in the include/pros directory and checks that they compile.
(Note: this script was partially written by Copilot) The current code doesn't contain any part of the original code which contained code from Copilot

Motivation:

Prevents issues like #760.

Test Plan:

  • CI passes

@ion098
Copy link
Contributor Author

ion098 commented Sep 9, 2025

@Rocky14683 Can you please run the pipeline?

@ion098 ion098 changed the title ci: 👷 check that example code compiles ci: 👷 check that examples in header files compile Sep 9, 2025
@Rocky14683
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Updated logging code and regex pattern for code blocks.
@ion098
Copy link
Contributor Author

ion098 commented Sep 10, 2025

@Rocky14683 can you please rerun pipeline?

@BennyBot
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@BennyBot
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@BennyBot
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ion098
Copy link
Contributor Author

ion098 commented Sep 12, 2025

@BennyBot can you please rerun the pipeline?

@BennyBot
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ion098
Copy link
Contributor Author

ion098 commented Sep 15, 2025

@BennyBot can you please rerun the pipeline?

@Rocky14683
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@djava djava left a comment

Choose a reason for hiding this comment

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

this asyncio approach is much cleaner, nice job.

Last request besides what comments i left was just - type hints?

"include/main.h",
"-std=c++23",
"-I", "include",
"-D", "_PROS_KERNEL_SUPPRESS_LLEMU_WARNING",
Copy link
Contributor

Choose a reason for hiding this comment

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

huge nitpick (like, dont bother changing this) but for the record its UB to have any identifier (including macros) that start with underscore then a capital letter lol.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually idek if you wrote that macro or not but 🤷 just having fun being an asshole by mentioning it


Args:
code_text (str): The C/C++ source code to compile.
filename (str): The name of the file.
Copy link
Contributor

Choose a reason for hiding this comment

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

was this remove a mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that shouldnt have been removed

Comment on lines +52 to +53
# Generate assembly (avoids linker errors)
"-S",
Copy link
Contributor

Choose a reason for hiding this comment

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

does the more standard -c not work? if not then probably give a longer comment to explain why youre doing -S because it took me a second for that to click

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-c would probably work, but assembling the files seems like an unnecessary step.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, maybe just a better comment - something like Just generate assembly, the further compilation steps are not necessary for this CI check maybe

Comment on lines +65 to +66
stdout, stderr = await process.communicate(input=code_text.encode("utf-8"))
success = (process.returncode == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting - where do you await the compilation being done? im not super familiar with this but im confused. does process.communicate() imply blocking to wait for a response? is there a timeout?

Copy link
Contributor Author

@ion098 ion098 Sep 16, 2025

Choose a reason for hiding this comment

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

Yes, communicate sends input via stdin and then waits for the process to finish running (no timeout though)

Copy link
Contributor

Choose a reason for hiding this comment

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

ok maybe a comment that says that because its not obvious imo

"-x", "c++" if is_cpp else "c",
"-std=c++23" if is_cpp else "-std=c2x",
# Only need precompiled headers for C++
*(("-I", precompiled_include_directory) if is_cpp else ()),
Copy link
Contributor

Choose a reason for hiding this comment

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

weird syntax trick lol maybe just do it after the list initialization

@BennyBot
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@meisZWFLZ
Copy link

Some silly notes I had while skimming the code:

  1. Perhaps you could use the compiler flags from the makefile? Likely by adding a make rule to extract the flags
    a. This could be applied to other configuration too, like the include directory
  2. Idk how azure pipelines work, but the examples check can be done in parallel to the other checks
  3. Maybe you're already doing this, but you could compile each snippet in parallel
  4. A make rule could be added to run the script
  5. Being able to specify a specific header to test would be useful for development

1 seems like it would be a lot of work, but everything else seems reasonable and justifiable

@ion098
Copy link
Contributor Author

ion098 commented Sep 24, 2025

re @meisZWFLZ

  1. Perhaps you could use the compiler flags from the makefile? Likely by adding a make rule to extract the flags
    a. This could be applied to other configuration too, like the include directory

That's probably a good idea in the long run, I didn't implement it because Makefile scares me a little.

  1. Idk how azure pipelines work, but the examples check can be done in parallel to the other checks
  2. Maybe you're already doing this, but you could compile each snippet in parallel

The code compiles everything in parallel using as many cores as possible with asyncio, so I don't think doing both checks in parallel would offer much speedup.

  1. A make rule could be added to run the script
  2. Being able to specify a specific header to test would be useful for development

That seems reasonable, but the script needs a few changes for development use---caching the example code for example, since the script always recompiles every example code snippet right now, which works for ci but makes it painful to repeatedly run during development.

@meisZWFLZ
Copy link

Do the other checks still run if the example check fails? I would think that would be ideal.

I kinda wonder whether this should be written in the makefile rather than a python script. Might make it a bit easier to implement caching with make rules.

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.

5 participants