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

Use ENV variables to set conf paths #222

Merged
merged 2 commits into from Aug 1, 2023
Merged

Conversation

ggmichaelgo
Copy link
Contributor

@ggmichaelgo ggmichaelgo commented Jul 27, 2023

closes: #202

Instead of creating .rake-compiler-siteconf.rb to override RbConfig::MAKEFILE_CONFIG and RbConfig::CONFIG, set environment variables to make install command. Since RbConfig is suppose to be readonly, we shouldn't overwrite its values.

Additionally, this update addresses a bug caused by .rake-compiler-siteconf.rb. The file's hardcoded destination path causes rake-compiler to consistently create files in that location, even if the project is renamed or moved. Consequently, changes to the gem project's path do not trigger the file task to update the file. This fix resolves this issue.

@ggmichaelgo ggmichaelgo marked this pull request as ready for review July 27, 2023 20:16
@kou
Copy link
Member

kou commented Jul 28, 2023

Hmm... I think that users should run rake clean when they rename the project's folder.
If we always recreate .rake-compiler-siteconf.rb, we also always need to recreate all depended files such as Makefile. It will slow down rake compile.

@ggmichaelgo
Copy link
Contributor Author

Hello @kou !
I have found out about the issue #202, and I have read your #202 (comment)

I have updated the PR, and this will also solve my original issue :)

# copy binary from temporary location to final lib
# tmp/extension_name/extension_name.{so,bundle} => lib/
task "copy:#{@name}:#{platf}:#{ruby_ver}" => [lib_path, tmp_binary_path, "#{tmp_path}/Makefile"] do
# install in lib for native platform only
unless for_platform
sh "#{make} install target_prefix=", chdir: tmp_path
expaned_lib_path = mkintpath(File.expand_path(lib_path))
Copy link
Member

Choose a reason for hiding this comment

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

Can we use relative path instead like RubyGems did rubygems/rubygems#5626 ?

Suggested change
expaned_lib_path = mkintpath(File.expand_path(lib_path))
relative_lib_path = Pathname(lib_path).relative_path_from(tmp_path)

I don't want to require mkmf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have update the sitearchdir and sitelibdir to use the expanded path to be more debuggable :)

expaned_lib_path = File.expand_path(lib_path)

ps. Thank you for reviewing the PR @kou !

"target_prefix=",
]

sh(*make_command, chdir: tmp_path)
Copy link
Member

Choose a reason for hiding this comment

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

We can't use this because make may have multiple shell components such as make -j4.

@ggmichaelgo ggmichaelgo requested a review from kou July 29, 2023 01:00
# copy binary from temporary location to final lib
# tmp/extension_name/extension_name.{so,bundle} => lib/
task "copy:#{@name}:#{platf}:#{ruby_ver}" => [lib_path, tmp_binary_path, "#{tmp_path}/Makefile"] do
# install in lib for native platform only
unless for_platform
sh "#{make} install target_prefix=", chdir: tmp_path
expaned_lib_path = File.expand_path(lib_path)
Copy link
Member

Choose a reason for hiding this comment

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

If we use absolute path, we need a special conversion on Windows that did by mkintpath:

https://github.com/ruby/ruby/blob/b5c74d548872388921402ff2db36be15e924a89b/lib/mkmf.rb#L1944-L1958

We don't need it when we use relative path.

Copy link
Member

Choose a reason for hiding this comment

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

We also need to escape this path because this path may include a special character such as .

Hmm. We may want to use sh(*make_command_line, chdir: tmp_path) with Shellwords.shellsplit:

relative_lib_path = Pathname(lib_path).relative_path_from(tmp_path) 
make_command_line = Shellwords.shellsplit(make)
make_command_line << "install"
make_command_line << "sitearchdir=#{relative_lib_path}"
make_command_line << "sitelibdir=#{relative_lib_path}"
make_command_line << "target_prefix="
sh(*make_command_line, chdir: tmp_path)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My initial thought of using relative path is that it would be easier to debug. However, the relative path is still debuggable and it will be better to avoid requiring mkmkf. (I just checked the mkmkf's file size 😅 )

Also, thank you for pointing out the Shellwords.shellsplit, and it will be much more safer to use it!

@kou
Copy link
Member

kou commented Aug 1, 2023

Could you update the PR title and description before we merge this?
(We use the PR title and description for commit message. Could you also include fix GH-202 to close #202 automatically when we merge this?)

@ggmichaelgo ggmichaelgo changed the title prevent exporting library to old library paths Fix GH-202 use Env variables to set conf paths Aug 1, 2023
@ggmichaelgo ggmichaelgo changed the title Fix GH-202 use Env variables to set conf paths Fix GH-202 use ENV variables to set conf paths Aug 1, 2023
@kou kou changed the title Fix GH-202 use ENV variables to set conf paths Use ENV variables to set conf paths Aug 1, 2023
@kou kou merged commit 0d93b08 into rake-compiler:master Aug 1, 2023
12 checks passed
@kou
Copy link
Member

kou commented Aug 1, 2023

Thanks!

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.

Compile task modifies RbConfig values
2 participants