-
-
Notifications
You must be signed in to change notification settings - Fork 631
fix: only delete first sys.path entry in the stage-2 bootstrap if PYTHONSAFEPATH is unset or unsupported #2418
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0408497
fix: only delete first sys.path entry in the stage-2 bootstrap iff PY…
chowder 3793b60
add integration tests to validate search paths of py_binary targets
chowder 988fe91
apply buildifier
chowder ffad9ba
use py_reconfig_test for no_unsafe_paths tests instead
chowder cbf9882
buildifier
chowder 6bb5050
buildifier
chowder 81e6bbf
rebase fixes
chowder c2ebbc4
clarify comment about removal of del sys.path0
rickeylev 8430043
update changelog
chowder 92df82c
Merge branch 'main' into bootstrap-fix
rickeylev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test") | ||
load("//tests/support:support.bzl", "SUPPORTS_BOOTSTRAP_SCRIPT") | ||
|
||
py_reconfig_test( | ||
name = "no_unsafe_paths_3.10_test", | ||
srcs = ["test.py"], | ||
bootstrap_impl = "script", | ||
main = "test.py", | ||
python_version = "3.10", | ||
target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, | ||
) | ||
|
||
py_reconfig_test( | ||
name = "no_unsafe_paths_3.11_test", | ||
srcs = ["test.py"], | ||
bootstrap_impl = "script", | ||
main = "test.py", | ||
python_version = "3.11", | ||
target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import sys | ||
import unittest | ||
|
||
|
||
class NoUnsafePathsTest(unittest.TestCase): | ||
def test_no_unsafe_paths_in_search_path(self): | ||
# Based on sys.path documentation, the first item added is the zip | ||
# archive | ||
# (see: https://docs.python.org/3/library/sys_path_init.html) | ||
# | ||
# We can use this as a marker to verify that during bootstrapping, | ||
# (1) no unexpected paths were prepended, and (2) no paths were | ||
# accidentally dropped. | ||
# | ||
major, minor, *_ = sys.version_info | ||
archive = f"python{major}{minor}.zip" | ||
|
||
# < Python 3.11 behaviour | ||
if (major, minor) < (3, 11): | ||
# Because of https://github.com/bazelbuild/rules_python/blob/0.39.0/python/private/stage2_bootstrap_template.py#L415-L436 | ||
self.assertEqual(os.path.dirname(sys.argv[0]), sys.path[0]) | ||
self.assertEqual(os.path.basename(sys.path[1]), archive) | ||
# >= Python 3.11 behaviour | ||
else: | ||
self.assertEqual(os.path.basename(sys.path[0]), archive) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.