diff --git a/.bazelrc b/.bazelrc index 24676574e6..205c04c5ce 100644 --- a/.bazelrc +++ b/.bazelrc @@ -41,3 +41,8 @@ common --incompatible_python_disallow_native_rules common --incompatible_no_implicit_file_export build --lockfile_mode=update + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false +startup --windows_enable_symlinks diff --git a/.bcr/gazelle/presubmit.yml b/.bcr/gazelle/presubmit.yml index 99647cac6f..40226c606d 100644 --- a/.bcr/gazelle/presubmit.yml +++ b/.bcr/gazelle/presubmit.yml @@ -27,10 +27,14 @@ bcr_test_module: platform: ${{ platform }} bazel: ${{ bazel }} shell_commands: + # Add an empty line in case the bazelrc is missing a trailing newline + - "echo '' >> .bazelrc" - "echo 'common --override_module=rules_python=' >> .bazelrc" - "bazel run //:gazelle_python_manifest.update" - "bazel run //:gazelle -- update" batch_commands: + # Add an empty line in case the bazelrc is missing a trailing newline + - "echo '' >> .bazelrc" - "echo common --override_module=rules_python= >> .bazelrc" - "bazel run //:gazelle_python_manifest.update" - "bazel run //:gazelle -- update" diff --git a/examples/build_file_generation/.bazelrc b/examples/build_file_generation/.bazelrc index f1ae44fac8..e14ed7c9f6 100644 --- a/examples/build_file_generation/.bazelrc +++ b/examples/build_file_generation/.bazelrc @@ -8,3 +8,7 @@ build --enable_runfiles common --noenable_bzlmod common --enable_workspace common --incompatible_python_disallow_native_rules + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false \ No newline at end of file diff --git a/examples/bzlmod/.bazelrc b/examples/bzlmod/.bazelrc index 28a44a7523..3dd26531f9 100644 --- a/examples/bzlmod/.bazelrc +++ b/examples/bzlmod/.bazelrc @@ -24,3 +24,7 @@ test --test_output=errors --enable_runfiles # Windows requires these for multi-python support: build --enable_runfiles common:bazel7.x --incompatible_python_disallow_native_rules + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false diff --git a/examples/multi_python_versions/.bazelrc b/examples/multi_python_versions/.bazelrc index 97a973bd85..39ed55aff4 100644 --- a/examples/multi_python_versions/.bazelrc +++ b/examples/multi_python_versions/.bazelrc @@ -5,3 +5,7 @@ build --enable_runfiles coverage --java_runtime_version=remotejdk_11 common:bazel7.x --incompatible_python_disallow_native_rules + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false \ No newline at end of file diff --git a/examples/pip_parse/.bazelrc b/examples/pip_parse/.bazelrc index f263a1744d..0df6cdc90b 100644 --- a/examples/pip_parse/.bazelrc +++ b/examples/pip_parse/.bazelrc @@ -1,3 +1,7 @@ # https://docs.bazel.build/versions/main/best-practices.html#using-the-bazelrc-file try-import %workspace%/user.bazelrc common --incompatible_python_disallow_native_rules + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false diff --git a/examples/pip_parse_vendored/.bazelrc b/examples/pip_parse_vendored/.bazelrc index a6ea2d9138..e846b1ac11 100644 --- a/examples/pip_parse_vendored/.bazelrc +++ b/examples/pip_parse_vendored/.bazelrc @@ -8,3 +8,7 @@ build --enable_runfiles common --noenable_bzlmod common --enable_workspace common --incompatible_python_disallow_native_rules + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false \ No newline at end of file diff --git a/examples/pip_repository_annotations/.bazelrc b/examples/pip_repository_annotations/.bazelrc index 9397bd31b8..82c7a1dbd2 100644 --- a/examples/pip_repository_annotations/.bazelrc +++ b/examples/pip_repository_annotations/.bazelrc @@ -7,3 +7,7 @@ common --noenable_bzlmod common --enable_workspace common --legacy_external_runfiles=false common --incompatible_python_disallow_native_rules + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false \ No newline at end of file diff --git a/gazelle/.bazelrc b/gazelle/.bazelrc index 9a38133e9d..a4cbf2dbfe 100644 --- a/gazelle/.bazelrc +++ b/gazelle/.bazelrc @@ -16,3 +16,7 @@ build --@rules_python//python/config_settings:incompatible_default_to_explicit_i build --enable_runfiles common:bazel7.x --incompatible_python_disallow_native_rules + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false diff --git a/gazelle/examples/bzlmod_build_file_generation/.bazelrc b/gazelle/examples/bzlmod_build_file_generation/.bazelrc index 31097b41de..f9e43556f7 100644 --- a/gazelle/examples/bzlmod_build_file_generation/.bazelrc +++ b/gazelle/examples/bzlmod_build_file_generation/.bazelrc @@ -14,3 +14,7 @@ common:bazel7.x --incompatible_python_disallow_native_rules # rules_python code. In the BCR presubmits, this override is removed # and the bazel_dep version of rules_python is used. common --override_module=rules_python=../../../ + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false diff --git a/gazelle/examples/bzlmod_build_file_generation/MODULE.bazel b/gazelle/examples/bzlmod_build_file_generation/MODULE.bazel index 1f92ea3826..7db658fcec 100644 --- a/gazelle/examples/bzlmod_build_file_generation/MODULE.bazel +++ b/gazelle/examples/bzlmod_build_file_generation/MODULE.bazel @@ -13,7 +13,7 @@ module( # For typical setups you set the version. # See the releases page for available versions. # https://github.com/bazel-contrib/rules_python/releases -bazel_dep(name = "rules_python", version = "1.4.0") +bazel_dep(name = "rules_python", version = "1.7.0") # The following stanza defines the dependency rules_python_gazelle_plugin. # For typical setups you set the version. diff --git a/python/private/build_data_writer.ps1 b/python/private/build_data_writer.ps1 index 846399f194..32fb7240f1 100644 --- a/python/private/build_data_writer.ps1 +++ b/python/private/build_data_writer.ps1 @@ -18,8 +18,10 @@ if (-not [string]::IsNullOrEmpty($InfoFilePath) -and (Test-Path $InfoFilePath)) # Use .NET to write file to avoid PowerShell encoding/locking quirks # We use UTF8 without BOM for compatibility with how the bash script writes (and # what consumers expect). +# We join with `n to ensure Unix-style line endings are used even on Windows. $Utf8NoBom = New-Object System.Text.UTF8Encoding $False -[System.IO.File]::WriteAllLines($OutputPath, $Lines, $Utf8NoBom) +$Content = [string]::Join("`n", $Lines) + "`n" +[System.IO.File]::WriteAllText($OutputPath, $Content, $Utf8NoBom) $Acl = Get-Acl $OutputPath $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("Everyone", "Read", "Allow") diff --git a/python/private/stage2_bootstrap_template.py b/python/private/stage2_bootstrap_template.py index c03a4a2e62..e20a049279 100644 --- a/python/private/stage2_bootstrap_template.py +++ b/python/private/stage2_bootstrap_template.py @@ -70,15 +70,39 @@ def get_build_data(self): if is_windows(): path = os.path.normpath(path) try: + path = os.path.dirname(__file__) + path = os.path.join(path, "print_build_data.build_data.txt") # Use utf-8-sig to handle Windows BOM - with open(path, encoding="utf-8-sig") as fp: - return fp.read() + with open(path, 'rb') as fp: + data = fp.read() + return data.decode('utf-8-sig') except Exception as exc: if hasattr(exc, "add_note"): + exc.add_note(f"version: {sys.version}") + exc.add_note(f"path: {path}") exc.add_note(f"runfiles lookup path: {rlocation_path}") exc.add_note(f"exists: {os.path.exists(path)}") + exc.add_note(f"lexists: {os.path.lexists(path)}") + exc.add_note(f"islink: {os.path.islink(path)}") + exc.add_note(f"isfile: {os.path.isfile(path)}") + if hasattr(os.path, "isjunction"): + exc.add_note(f"isjunction: {os.path.isjunction(path)}") can_read = os.access(path, os.R_OK) exc.add_note(f"readable: {can_read}") + try: + exc.add_note(f"stat: {os.stat(path)}") + except Exception as e: + exc.add_note(f"stat error: {e}") + try: + exc.add_note(f"lstat: {os.lstat(path)}") + except Exception as e: + exc.add_note(f"lstat error: {e}") + try: + import subprocess + out = subprocess.check_output(f'dir "{os.path.dirname(path)}"', shell=True) + exc.add_note(f"dir: {out.decode('utf-8', 'replace')}") + except Exception as e: + exc.add_note(f"dir error: {e}") raise diff --git a/tests/integration/compile_pip_requirements/.bazelrc b/tests/integration/compile_pip_requirements/.bazelrc index b85f03bcb6..be2ceedf66 100644 --- a/tests/integration/compile_pip_requirements/.bazelrc +++ b/tests/integration/compile_pip_requirements/.bazelrc @@ -3,3 +3,7 @@ test --test_output=errors # Windows requires these for multi-python support: build --enable_runfiles common:bazel7.x --incompatible_python_disallow_native_rules + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false \ No newline at end of file diff --git a/tests/integration/compile_pip_requirements_test_from_external_repo/.bazelrc b/tests/integration/compile_pip_requirements_test_from_external_repo/.bazelrc index ab10c8caf7..80d2b0d97d 100644 --- a/tests/integration/compile_pip_requirements_test_from_external_repo/.bazelrc +++ b/tests/integration/compile_pip_requirements_test_from_external_repo/.bazelrc @@ -1,2 +1,6 @@ test --test_output=errors common:bazel7.x --incompatible_python_disallow_native_rules + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false \ No newline at end of file diff --git a/tests/integration/local_toolchains/.bazelrc b/tests/integration/local_toolchains/.bazelrc index aed08b0790..6a920b180c 100644 --- a/tests/integration/local_toolchains/.bazelrc +++ b/tests/integration/local_toolchains/.bazelrc @@ -6,3 +6,7 @@ build --enable_runfiles common:bazel7.x --incompatible_python_disallow_native_rules build --//:py=local common --announce_rc + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false \ No newline at end of file diff --git a/tests/integration/pip_parse/.bazelrc b/tests/integration/pip_parse/.bazelrc index a74909297d..3d3d8bd67f 100644 --- a/tests/integration/pip_parse/.bazelrc +++ b/tests/integration/pip_parse/.bazelrc @@ -6,3 +6,7 @@ build --enable_runfiles try-import %workspace%/user.bazelrc common:bazel7.x --incompatible_python_disallow_native_rules + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false \ No newline at end of file diff --git a/tests/integration/py_cc_toolchain_registered/.bazelrc b/tests/integration/py_cc_toolchain_registered/.bazelrc index fb31561892..e5a95490e6 100644 --- a/tests/integration/py_cc_toolchain_registered/.bazelrc +++ b/tests/integration/py_cc_toolchain_registered/.bazelrc @@ -1,3 +1,7 @@ # This aids debugging on failure build --toolchain_resolution_debug=python common:bazel7.x --incompatible_python_disallow_native_rules + +# See issue 3567. Disable implicit python zip creation. +common --build_python_zip=false +common --@rules_python//python/config_settings:build_python_zip=false \ No newline at end of file