-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
(PUP-11597) Generate types when any module libs are updated #8928
base: 7.x
Are you sure you want to change the base?
(PUP-11597) Generate types when any module libs are updated #8928
Conversation
Can one of the admins verify this patch? |
f9be67a
to
ac6d139
Compare
10043c0
to
573fbac
Compare
I'm not sure why the spec tests are failing in jruby and windows. Anyone have an idea why? |
Since CI failed more than a month ago, I have to close and reopen to rekick the GH actions. |
@natemccurdy I think Windows tests are failing because of the way the test stubs filesystem access. Perhaps Windows mtime resolution isn't as low as Posix or the time is being truncated?
|
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.
Just noting that this needs work
573fbac
to
8559e28
Compare
822d21b
to
146ca76
Compare
I wasn't able to figure out a way to get the tests to pass on Windows by faking a passage of time, so I resorted to a I don't like that sleep, but the tests pass 🤷 . |
@joshcooper Is there anything specific here that still needs work? |
10a5790
to
048af2e
Compare
Retriggering tests |
genface.types | ||
stats_before = [Puppet::FileSystem.stat(File.join(outputdir, 'test1.pp')), Puppet::FileSystem.stat(File.join(outputdir, 'test2.pp'))] | ||
# Sorry. The sleep is needed because Puppet::FileSystem.touch(<path>, :mtime => Time.now 1000) doesn't work on Windows. | ||
sleep(1) |
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.
That is surprising because our filesystem code calls FileUtils.touch
which eventually passes the mtime
through to https://github.com/ruby/ruby/blob/536649f819ed8f2bb0f8f44b1a0ca5c6d1753b24/win32/win32.c#L7692 where SetFileTime
is documented in https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfiletime
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 tried a build just now that uses:
Puppet::FileSystem.touch(puppet_x_lib, :mtime => Time.now 1000)
It failed in the jruby spec tests: https://github.com/puppetlabs/puppet/actions/runs/6882098596/job/18719877970
From what I remember when I first made this PR, the sleep(1)
was the only way to get the tests to pass.
Though now that I look at it, the comment about "doesn't work on Windows" might be wrong... it's actually failing on Jruby and the Windows tests are being skipped because of that.
lib/puppet/generate/type.rb
Outdated
end | ||
# Check for updates to any module lib files. | ||
module_lib_files = Dir.glob(File.join(@base, "lib", "**", "*.rb")) | ||
module_lib_files.each do |lib| |
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.
Wondering if it'd be better to use the block form and break as soon as we detect a newer file?
- module_lib_files = Dir.glob(File.join(@base, "lib", "**", "*.rb"))
- module_lib_files.each do |lib|
Dir.glob(File.join(@base, "lib", "**", "*.rb")) do |lib|
Also I'd want to understand how this would affect code deployment times for a "typical" environment with hundreds of modules.
13f302a
to
37c4da9
Compare
Fixes PUP-11597
Before
Prior to this, the
puppet generate types
command would only detect resource type changes if the type file itself changed.For example, if your type was defined at
<module>/lib/puppet/type/foo.rb
, a change in it would be detected.But if your type includes libraries from separate Ruby files in
lib/puppet/*
or even in the PuppetX namespace likelib/puppet_x/*
, changes to those other files would not be detected.The consequence of that behavior is that updates to the signature of a type that come from "other" ruby files would not trigger a metadata re-creation and those types would suffer from the environment-isolation problem (SERVER-94) that
puppet generate types
was meant to solve.After
This fixes that problem by updating
puppet generate types
to scan for changed Ruby files within a module'slib/*
directory.It uses the same
Puppet::FileSystem::stat
operation to compare mtime of the Ruby files inlib/*
relative to the generated metadata file. And if the metadata is older than any of the Ruby files inlib/*
, the metadata is regenerated.The one slight-downside to my solution is that generation of type metadata will possibly happen more often than before and possibly more often than is needed. However, generating types is fast, and it's usually only done when code updates happen (e.g. via
r10k
or Code Manager), so the total added load is very close to, if not, negligible.