-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Start Refactor tool init specs #4915
Conversation
The init specs are wrong already, they shouldn't invoke the compiler, they should use init programmatically. I wish someone would refractor that instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why on some bin_crystal invocation an expand_path is needed but not in others? And previously there was mos expand_path.
Other than that lgtm
What asterite said is right, yet the readability improvement is good even init is not called programatically. |
Little bit of context: Previously the commands created some test projects in the compiler specs dir, and in case of failure they just stayed there. To answer the question: Because I created a temporary directory and cd into it, thus
I agree with you, I'm trying to do that, but I'm hitting a wall: The errors that was checked by the last specs (on I refactored my PR to reduce the number of helpers and simplify specs. I think we should merge this refactor as is (unless you have suggestions of course). And when we change how error handling is done for |
b557729
to
fc4386f
Compare
9a1ac56
to
0e4eb81
Compare
@bcardiff and/or others, can you review this please? |
LGTM. There is certainly room for further improvements, but this is the first step! |
# Creates a temporary directory, cd to it and run the block inside it. | ||
# The directory and its content is deleted when the block return. | ||
private def within_temporary_directory | ||
tmp_path = "/tmp/crystal_init_spec_tmp_dir-#{rand(10_000)}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could #{__DIR__}/tmp...
be used instead of /tmp...
? The local tmp is already in the .gitignore and I would rather not write something outside the working copy.
Other that that, please rebase and I would 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aah ok, I didn't thought about that, I do that soon!
0e4eb81
to
6d9c0bc
Compare
@bcardiff done! A commits squash would reduce the PR complexity, but it's still useful for review. I suppose you can do that when merging so I'll leave it like that ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @bew for the PR.
Please take a look to some of the comments related to leftovers and file locations.
Thank you.
require "spec" | ||
require "yaml" | ||
|
||
BIN_CRYSTAL = File.expand_path("bin/crystal") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes Dir.current
is Crystal's root directory, which might not be the case. I recommend adjust it so bin/crystal
can be calculated relatively to this file/directory location instead.
$ which ccr
/home/luis/bin/ccr
$ file `which ccr`
/home/luis/bin/ccr: symbolic link to /home/luis/code/crystal-lang/crystal/bin/crystal
$ cd spec/compiler/crystal/tools
$ ccr eval 'p Dir.current, File.expand_path("bin/crystal")'
Using compiled compiler at `.build/crystal'
"/mnt/c/Users/Luis/Code/crystal-lang/crystal/spec/compiler/crystal/tools"
"/mnt/c/Users/Luis/Code/crystal-lang/crystal/spec/compiler/crystal/tools/bin/crystal"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but it didn't work before too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding specs, it should be reasonable to assume they are run from the project root folder. I don't think it is worth fixing this unless there is a specific issue why this wouldn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luislavena ah ok I see what you mean, I fixed it!
# Creates a temporary directory, cd to it and run the block inside it. | ||
# The directory and its content is deleted when the block return. | ||
private def within_temporary_directory | ||
tmp_path = "#{__DIR__}/crystal_init_spec_tmp_dir-#{rand(10_000)}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now temporary directories will be created relative to the location of each spec file (__DIR__
).
In that case, will be great to ignore crystal_init_spec_tmp_dir-*
in .gitignore
to avoid a broken spec allow possible left over files be available to commit into the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a helper for this spec file only, and unless this method within_temporary_directory
crash, the ensure will automatically clean the tmp dir, so I'm not sure it's necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@straight-shoota I don't think that's what he meant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently all these specs output to /tmp
, which is in .gitignore
. The change here using __DIR__
place these temporary files relative to the spec file, inside the spec
folder, which are not ignored.
It's a helper for this spec file only, and unless this method within_temporary_directory crash, the ensure will automatically clean the tmp dir, so I'm not sure it's necessary
That is something we don't know. Perhaps Process.new
might segfault, or other part of the spec could, leaving leftovers that were never cleaned up.
I'm not suggesting radically change and refactor what you have done, but instead consider where those temporary files are stored and either A: add them to the gitignore file to avoid accidental commit, or B: adjust the location to be the one relative to the already ignored one.
Thank you.
Followup of @luislavena comment:
Not sure about that: the list of spec files that uses
So these specs uses the I'm not sure the entry According to @bcardiff:
So all these specs 'break' this rule, and uses a directory outside the working copy of the repository. Back to this PR, I think I'll just use WDYT? |
Currently the specs of This PR modifies that behavior and I'm commenting on that behavior change. I'm not suggesting go change everything outside this PR, but instead honor the existing behavior or at minimum update the
It was prior this change, all the Please note that all my comments and observations have been around this PR changes. Apologies if you thought my comments requested you introduce changes outside the context of this PR. Cheers. |
Aaaah thanks I didn't remember that specificity, so I assumed you were talking about a broader issue, sorry about that I made a change, let me know what you think! |
Why not just simply use |
Hmm It's probably just me then, but I don't like putting things outside the |
6fcb86f
to
3333648
Compare
Should be good now 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I would personally prefer to continue to use , the changes I suggested were addressed, so 👍 from me.tmp/
We should just use the system's tempdir everywhere, if it's not writable and usable the system is broken anyway. Plus it's way faster because tmpfs is in-memory. But, that's a topic for another PR and for now we should keep it the same as before. I'll review this in just a bit. |
@bew it appears CI failed due formatting error. Can you reformat code using local version of the compiler and push again? Thank you. |
Thanks @luislavena, fixed! |
6035c39
to
7c1cd99
Compare
Is there something I can do here? Or do we just wait for another review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is fine, but I'd really like not to execute bin/crystal
inside compiler specs. This should be tested programmatically (could be done in another PR, though)
Very interesting backtrace from travis:
not sure what to make of it. |
Actually given the I'll merge when CI comes back green. |
@RX14 can you restart the Travis build to see if it happens again? |
When parallelism is introduced, we'll need to add locks to every class variable and constant access, to make sure it's not initialized twice by two different threads. I wonder why that crash happened given that we don't have multiple threads right now. |
7c1cd99
to
0115d6d
Compare
This is a refactor of the
crystal tool init
specs, it is partly extracted & reworked from #4691.It fixes 2 main issues:
Use a handy
stderr_of(command)
helper instead of relying on obscure bash trick like(echo "foo" 1>&2) 2>&1 >/dev/null
to get only stderr on stdout...Provides 3 helpers to create/delete temporary directory/file, and allow to make tool tests in a directory, then delete it (on spec success or failure). Previously there were a lot of directories (created by the tool) not deleted in case of errors in the specs. (and sometime the reported errors weren't coherent between multiple runs)
The 3 temporary-stuff helpers will probably be replaced when #4096 or similar is merged.