-
Notifications
You must be signed in to change notification settings - Fork 959
bazel: stub InitRunFiles, fix RUNFILES_* env leak in tcl_library_init #10100
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fd7246a
bazel: stub InitRunFiles, fix RUNFILES_* env leak in tcl_library_init
oharboe d8a3199
bazel: use portable env clearing for Windows compatibility
oharboe df99178
bazel: add test proving unsetenv(RUNFILES_DIR) fix is needed
oharboe a583628
Merge branch 'pr-10100' into HEAD
oharboe 016548b
bazel: fix runfiles_env_test to actually exercise Tcl init path
oharboe 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,86 +1,3 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // Copyright (c) 2026, The OpenROAD Authors | ||
|
|
||
| // This file to go away as soon as we use the tcl_library_init initialization | ||
| // in OpenSTA. | ||
|
|
||
| #include <unistd.h> // readlink() | ||
|
|
||
| #include <climits> | ||
| #include <cstdlib> | ||
| #include <filesystem> | ||
| #include <iostream> | ||
| #include <memory> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <system_error> | ||
|
|
||
| #if defined(__APPLE__) | ||
| #include <mach-o/dyld.h> | ||
| #include <sys/param.h> | ||
| #endif | ||
|
|
||
| #include "rules_cc/cc/runfiles/runfiles.h" | ||
|
|
||
| namespace { | ||
| // Avoid adding any dependencies like boost.filesystem | ||
| // Returns path to running binary if possible, otherwise nullopt. | ||
| static std::optional<std::string> GetProgramLocation() | ||
| { | ||
| #if defined(_WIN32) | ||
| char result[MAX_PATH + 1] = {'\0'}; | ||
| auto path_len = GetModuleFileNameA(NULL, result, MAX_PATH); | ||
| #elif defined(__APPLE__) | ||
| char result[MAXPATHLEN + 1] = {'\0'}; | ||
| uint32_t path_len = MAXPATHLEN; | ||
| if (_NSGetExecutablePath(result, &path_len) != 0) { | ||
| path_len = readlink(result, result, MAXPATHLEN); | ||
| } | ||
| #else | ||
| char result[PATH_MAX + 1] = {'\0'}; | ||
| ssize_t path_len = readlink("/proc/self/exe", result, PATH_MAX); | ||
| #endif | ||
| if (path_len > 0) { | ||
| return result; | ||
| } | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| std::string GetTclLibraryBaseLocation() | ||
| { | ||
| using rules_cc::cc::runfiles::Runfiles; | ||
| std::string error; | ||
| std::unique_ptr<Runfiles> runfiles(Runfiles::Create( | ||
| *GetProgramLocation(), BAZEL_CURRENT_REPOSITORY, &error)); | ||
| if (!runfiles) { | ||
| std::cerr << "[Warning] Failed to create bazel runfiles: " << error << "\n"; | ||
| return ""; | ||
| } | ||
|
|
||
| std::error_code ec; | ||
| for (const std::string loc : {"openroad", "opensta", "_main"}) { | ||
| const std::string check_loc = loc + "/bazel/tcl_resources_dir"; | ||
| const std::string path = runfiles->Rlocation(check_loc); | ||
| if (!path.empty() && std::filesystem::exists(path, ec)) { | ||
| return path; | ||
| } | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| class BazelInitializer | ||
| { | ||
| public: | ||
| BazelInitializer() | ||
| { | ||
| const std::string lib_mount_point = GetTclLibraryBaseLocation(); | ||
| if (!lib_mount_point.empty()) { | ||
| const std::string tcl_path = lib_mount_point + "/library"; | ||
| setenv("TCL_LIBRARY", tcl_path.c_str(), true); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Provide via global constructor. | ||
| static BazelInitializer bazel_initializer; | ||
| } // namespace | ||
| // Intentionally empty: tcl_library_init now handles Tcl setup. | ||
| // This file is kept because src/sta:opensta still references | ||
| // //bazel:runfiles in its srcs. |
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
Oops, something went wrong.
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.
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.
Is there a test that can show that this is necessary ?