Skip to content

Commit

Permalink
Fix runtime files for python library.
Browse files Browse the repository at this point in the history
  • Loading branch information
agoessling committed Aug 11, 2023
1 parent c055b75 commit 304e4bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/generate_python_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ def main():

library_str = \
f'''
import os
from bazel_tools.tools.python.runfiles import runfiles
from src import py_stuff_sack
# The location of the relative location of the runfiles depends on whether the library is run as a
# tool or standalone. We manually prepend the runfiles path to handle both cases.
workspace = os.path.basename(os.getcwd())
r = runfiles.Create()
globals().update(py_stuff_sack.get_globals(
os.path.join(os.environ['RUNFILES_DIR'], workspace, '{args.lib}'),
os.path.join(os.environ['RUNFILES_DIR'], workspace, '{args.spec}')
r.Rlocation('{args.lib}'),
r.Rlocation('{args.spec}')
))
'''

Expand Down
5 changes: 3 additions & 2 deletions tools/gen_message_def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def gen_message_def(name, message_spec, c_deps = None, **kwargs):
outs = [
name + ".py",
],
cmd = ("$(execpath @stuff_sack//src:generate_python_lib) --spec $(rootpath {}) " +
"--lib $(rootpath {}) --output $@").format(
cmd = ("$(execpath @stuff_sack//src:generate_python_lib) --spec $(rlocationpath {}) " +
"--lib $(rlocationpath {}) --output $@").format(
message_spec,
":" + name + "-c-so",
),
Expand All @@ -63,6 +63,7 @@ def gen_message_def(name, message_spec, c_deps = None, **kwargs):
srcs = [name + ".py"],
deps = [
"@stuff_sack//src:py_stuff_sack",
"@bazel_tools//tools/python/runfiles",
],
data = [
":" + name + "-c-so",
Expand Down

0 comments on commit 304e4bc

Please sign in to comment.