Skip to content

runfiles, Windows: $RUNFILES should point to the actual runfiles directory #4280

Closed

Description

@laszlocsomor

Split from #4261 (comment):

the PWD dir sh_binary executed in should be RUNFILES. Currently

PWD: /c/cygwin64/tmp/_bazel_wyan/zgiahg30/execroot/__main__/bazel-out/x64_windows-fastbuild/bin/shell_wrapper.exe.runfiles # Has '.exe' in last segment of path, Exist in filesystem.

RUNFILES: C:\cygwin64\tmp\_bazel_wyan\zgiahg30\execroot\__main__\bazel-out\x64_windows-fastbuild\bin\shell_wrapper.runfiles # Not exist in filesystem

I agree, $RUNFILES should point to the actual runfiles directory (with .exe in the name).

Activity

  1. added
    P3
    on Dec 12, 2017
  2. meteorcloudy commented on Dec 12, 2017

    @meteorcloudy
    Member

    @laszlocsomor @wyan-nestlabs
    Continue discussion in #4261

    Since the RUNFILES we're talking about is constructed by RUNFILES=${BASH_SOURCE[0]}.runfiles, I don't think it should contain .exe.
    Because the first argument a shell script receives will always be itself, which will never end with .exe.

    As an alternative, we can use RUNFILES_MANIFEST_FILE environment variable. It is set by the Windows native launcher, in this case, shell_wrapper.exe.
    It points to the manifest file under runfiles directory, like

    C:/tmp/_bazel_pcloudy/fcskwqoq/execroot/__main__/bazel-out/x64_windows-fastbuild/bin/A.exe.runfiles/MANIFEST
    

    This is only the useful thing under runfiles directory on Windows.
    And you can get RUNFILES directory by $(dirname ${RUNFILES_MANIFEST_FILE})

    But I do agree that we really should have a better documentation for these unique Windows behaviors.

  3. wyan-nestlabs commented on Dec 12, 2017

    @wyan-nestlabs

    Being consistent across platforms is important. My BUILD rule need be run on both Windows and Linux. RUNFILES_MANIFEST_FILE is not available on LInux. If you don't like ".exe" in the path please make the directory the execute 'bazel run' under without .exe.

    Better documentation, such as the explanation of symlink to files and why runfile dir has MANIFEST only on Windows, is definitely needed. But the discrepancy on two "RUNFILES" and confusions from it sound avoidable to me.

  4. laszlocsomor commented on Dec 14, 2017

    @laszlocsomor
    ContributorAuthor

    @wyan-nestlabs : we're working on adding libraries that'll unify runfiles handling on all platforms. In shell for example, on Linux you'll have to source this library from $RUNFILES, and on Windows it'll be automatically sourced, and once it is sourced you can use the rlocation function to retrieve runfile paths platform-independently, e.g. rlocation path/to/runfile.

    I'm planning to complete that work in Q1-2018, at least for sh_* rules. (What language we implement it for next, we haven't decided yet.) See #3865.

  5. added
    P2
    P3
    and removed
    P3
    P2
    on Dec 14, 2017
  6. flaub commented on Dec 24, 2017

    @flaub

    Personally, it'd be a lot more convenient and language-independent to simply set environment variables in a consistent way across all platforms. In my case, I use python scripts to provide platform independence. Do you plan to make a python library (and a library for each language) that provides the rlocation function? Doesn't it seem easier to just make the RUNFILES env var consistent and let each language figure out what to do with it?

  7. laszlocsomor commented on Jan 2, 2018

    @laszlocsomor
    ContributorAuthor

    @flaub --

    Personally, it'd be a lot more convenient and language-independent to simply set environment variables in a consistent way across all platforms

    The user would still have to deal with the difference that Bazel generates a symlink tree on Linux, and a manifest file on Windows.

    Do you plan to make a python library (and a library for each language) that provides the rlocation function?

    Yes, for Python, Bash, Java, and C++.

    Doesn't it seem easier to just make the RUNFILES env var consistent and let each language figure out what to do with it?

    As I said, Bazel's behavior is different on Linux and Windows. I see no point in setting this envvar on Windows. WDYT?

  8. flaub commented on Jan 2, 2018

    @flaub

    I've attempted to write such an rlocation function in python and found that if there was a consistent environment, writing that function would be a lot easier. My goal is to actually always use the manifest file on every platform to resolve paths to their original locations so that rlocation works consistently everywhere. Another very useful env var would be something equivalent to TEST_SRCDIR but under the run context.

    Something else you might want to consider, as of Windows 10 Creators Update, symlinks no longer require admin privileges when using "Developer Mode". More details here: https://blogs.windows.com/buildingapps/2016/12/02/symlinks-windows-10/

  9. laszlocsomor commented on Jan 2, 2018

    @laszlocsomor
    ContributorAuthor

    I've attempted to write such an rlocation function in python and found that if there was a consistent environment, writing that function would be a lot easier.

    I don't see how it would be a lot easier, because on Linux rlocation is simply echo $RUNFILES/$1 (in case of Bash scripts, for example). Do you mean something else?

    My goal is to actually always use the manifest file on every platform to resolve paths to their original locations so that rlocation works consistently everywhere.

    I like that idea. I'm not aware of any reason why a symlink tree would be better than using a manifest file, if one already has to use rlocation because of Windows. Migrating existing binaries and tests would be practical / economical if they all used rlocation already because we could then change the implementation of rlocation and simultaneously stop generating the symlink tree.

    Another very useful env var would be something equivalent to TEST_SRCDIR but under the run context.

    What do you mean? Can you give an example?

    Something else you might want to consider, as of Windows 10 Creators Update, symlinks no longer require admin privileges when using "Developer Mode". More details here: https://blogs.windows.com/buildingapps/2016/12/02/symlinks-windows-10/

    Thanks! Yes, we're aware of it. We decided not to use that because (a) it's opt-in and requires one-time registry editing and possibly Admin approval, and (b) it's only available in the very latest Win10 update, and Bazel supports Win7 and up. That said ideally Bazel would detect whether it can create symlinks and fall back to copying, but we didn't think it's high priority for now.

  10. laszlocsomor commented on Jan 2, 2018

    @laszlocsomor
    ContributorAuthor

    (a) it's opt-in and requires one-time registry editing and possibly Admin approval

    I meant one-time enabling in some settings menu (or maybe it is indeed registry editing; I didn't check).

  11. added
    area-Windows
    and removed on Dec 10, 2018
  12. added
    team-OSS
    on Jun 15, 2020
  13. meteorcloudy commented on Dec 22, 2021

    @meteorcloudy
    Member

    I don't see any complain about the $RUNFILES for a long time, closing this now. Feel free to reopen if the issue still exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3area-Windowsplatform: windowsteam-OSStype: feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions