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

Team 2 New Language Test Files #12

Draft
wants to merge 28 commits into
base: team2-homework1
Choose a base branch
from

Conversation

mayank-ramnani
Copy link

@mayank-ramnani mayank-ramnani commented Oct 16, 2024

@ Marwan AbdElhameed
@ Ricky Zhang

jhasse and others added 26 commits August 28, 2024 13:47
GitHub Actions: Prevent ctest invocation error on macOS
This adds `override` statements, and removes an un-necessary
destructor declaration from status_printer.h in order to remove
annoying compiler warnings when building Ninja tests with CMake
with recent compilers. For example, clang 16.0 complains with:

```
/path/to/ninja/src/status_printer.h:29:16: warning: 'EdgeAddedToPlan' overrides a member function but is not marked 'override' [
-Winconsistent-missing-override]
  virtual void EdgeAddedToPlan(const Edge* edge);
               ^
```

The root issue is that while libninja is compiled explicitly for C++11,
which disable the warning, the tests themselves are not, since they rely
on GTest which now requires C++14, and thus the standard being used is
determined by the compiler's default configuration.
This field is unused. This patch removes compiler warnings when
building with recent compilers (e.g. Clang 16.0)
It was declared in an anonymous namespace, and nothing
uses it anymore, removes a compiler warning.
Technically, these are not required since Ninja is built with -std=c++11,
but using these directives is good practice to clarify the code and
avoid simple human errors.
Add a new class to wrap the logic needed to implement the
`inputs` tool correctly (see Issue ninja-build#2482 for details), and
provide a unit-test for it.
This uses the InputsCollector class introduced in the
previous patch to implement the tool properly. Results
are still shell-escaped and sorted alphabetically.

Fixed ninja-build#2482
Add new options to the `inputs` tool in order to change
the format of its output:

- `--no-shell-escape` to avoid shell-escaping the results.

- `--dependency-order` to return results in dependency order,
  instead of sorting them alphabetically.

- `--print0` to use \0 as the list separator in the list,
  useful to process the target paths with `xargs -0` and
  similar tools.
Use C string macros to hold ANSI escape sequences in order
to make the test much easier to understand and follow.

NOTE: This does not change the test in any way!
Move the function to its own source file since it is
no longer trivial (and will get optimized in future
patches).

+ Add a new ElideMiddleInPlace() function that doesn't
  do anything if no elision is required + use it in
  status.cc.

+ Add a new elide_middle_perftest program to benchmark
  the performance of the function.

  On my machine, the 'avg' result is 159.9ms.
Add a fast-path for the case where there is no escape sequence
in the input, that avoids un-necessary string allocations.

Properly handle ANSI color sequences that appear in the elided
part of the input string. They *must* be preserved to ensure
that the right span is printed with the right color.

For example, consider the following input:

    |GREEN|aaaaaaaaaaaaa|RED|bbbbbbbbbbb|BLACK|

With different levels of elision:

    max_width=0   -> |GREEN|RED|BLACK| instead of ""

    max_width=5   -> |GREEN|a..|RED|b|BLACK|
      (this was |GREEN|a..b|BLACK| before this fix)

Moreoever, do not call std::regex_iterator::str() to avoid
un-necessary string allocations and concatenations.

With this patch, 'elide_middle_perftest' goes from 159.9ms
to 87.1 ms on my machine (x1.8 faster)
Get rid of std::regex and std::vector usage in ElideMiddleInPlace()
function. These are replaced with custom iterator classes that do
not perform any memory allocation at runtime.

Instead the input string will be parsed twice (once to determine the
visible width, and another time to create the elided result string).

With this patch, elide_middle_perftest goes from 87.1ms to 15.0ms
on my machine (x5.8 faster!). This also removes 65 kiB from the
stripped Linux binary for Ninja (!)
Just check for the ESC character in the `output` string,
if none is present, or if the terminal supports color,
avoid unnecessary busy work (string allocations and
parsing).
For most actions, the depfile will be in the same directory as one
of its outputs, and their  parent directory will be created by Ninja
before running the command. However, this is not always the case.

In particular, the GN build tool is changing its Ninja build plan
generation logic, switching from using stamp files to phony targets,
after issue ninja-build#478 was fixed in Ninja. For additionnal context
see https://gn-review.googlesource.com/c/gn/+/11380.

The newly generated build plans trigger this condition more frequently,
which results in flaky build failures for large GN-based projects such
as Fuchsia.

This patch ensures the depfile's parent directory is always created
before the command is launched to get rid of the issue entirely.
…directory

Ensure depfile's parent directory is created before running an action.
Fix `inputs` tool logic and add new formatting options.
- build dependencies if they dont exist
@jazwu
Copy link

jazwu commented Oct 31, 2024

For future commits, consider adopting the <type>: <summary> format (e.g., feat: add new language or fix: substitute only first input file). This structure improves readability. Also, aim to make commit messages clearer in describing what changes were made and why, which helps the team track updates more effectively


PHONY(clean, "clean_rule");
RULE(clean_rule,
shadowdash::constant("rm", 2),
Copy link

@Shihuihuang1103 Shihuihuang1103 Nov 3, 2024

Choose a reason for hiding this comment

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

It might be helpful to have a method that calculates the length of each string instead of manually counting and passing the length.

@Shihuihuang1103
Copy link

Correctness:

  • Confirming that bar.o, foo.o and baz.o can be compiled as expected.
  • Verify that phony "clean" functions as intended, effectively removing the generated .o files.

Readability:

  • The code is well-organized and naming conventions are consistently followed.
  • Clear messages are logged to the console to indicate building targets and stages.

Testing:

  • Unit testing could be beneficial for core methods like resolveVariable, defineRule, etc.

std::optional<bool> restat_{false};
std::optional<std::string_view> rspfile_;
std::optional<std::string_view> rspfile_content_;
std::optional<std::string_view> pool_;
Copy link

Choose a reason for hiding this comment

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

Will you further consider make 'pool' a separate rule, in parallel with RULE, BUILD, VAR, DEFAULT, etc.?

@dl5214
Copy link

dl5214 commented Nov 4, 2024

The overall functionality looks good, and thank you for the substantial work. I would like to make some additional comments based on Jasmine and Shihui's thorough review.

  1. Is it really necessary to add foo, bar, and baz to this project? Are they for testing purpose? If they are not related to the whole project, maybe it would be better to either remove them or put them into an archive/legacy folder. Otherwise if they are indeed necessary, please consider renaming them.
  2. Maybe there would be benefits separating 'pool' from other rules, or you can leave it as is.
  3. It might be helpful if you would consider providing some very simple example usage of your newly defined language in docString or through comments, like what you have done in the main function.
  4. As Professor suggested further, please submit only one commit in this PR and remove any inrelevant changes.

@mayank-ramnani mayank-ramnani force-pushed the team2-homework1 branch 2 times, most recently from ec109b0 to d497a69 Compare November 7, 2024 02:31
Copy link

@kyotov kyotov left a comment

Choose a reason for hiding this comment

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

please checkout https://docs.google.com/document/d/11e8zR3kcm7B-D6brAH_D4OgtYBEf94GZwQIXrnti5hM/edit?tab=t.0 and address the items that apply to you. not all of them necessarily do, but some do... the i will look again

@MarwanWalid2
Copy link

MarwanWalid2 commented Nov 27, 2024

Newest PR: PR23

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.