Skip to content
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

remote strategy doesn't incorporate runfiles as inputs #1593

Closed
dfabulich opened this issue Aug 1, 2016 · 13 comments
Closed

remote strategy doesn't incorporate runfiles as inputs #1593

dfabulich opened this issue Aug 1, 2016 · 13 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) type: bug

Comments

@dfabulich
Copy link
Contributor

Consider this repository https://github.com/dfabulich/remote-cache-key-runfiles

The repository has an empty WORKSPACE and a trivial sh_binary, cp.sh, designed to copy its runfile (called runfile) to a parameterized destination.

cp runfile $1

The runfile is just a text file containing the number 0.

The BUILD file declares cp.sh as a sh_binary with the runfile in its data, and declares a genrule called x that runs cp.sh to generate an output file, out.txt.

sh_binary(
    name='cp',
    srcs=['cp.sh'],
    data=['runfile'],
)

genrule(
    name='x',
    tools=['cp'],
    outs=['out.txt'],
    cmd='$(location cp) $@',
)

If you run bazel build :x && more bazel-genfiles/out.txt you'll see that it has copied the runfile to bazel-genfiles/out.txt and the output is 0. If you change the runfile to contain the number 1 the out.txt file will change when you re-run the build as expected.

Now set the runfile back to 0, launch a Hazelcast server, and run the build like this:

bazel clean && bazel build --hazelcast_node=localhost:5701 \
  --genrule_strategy=remote --spawn_strategy=remote :x && more bazel-genfiles/out.txt

You'll correctly see the output is 0. Now change the runfile contents to 1 and run the build again.

Expected: When the runfile contents change, the cache should be invalidated and the output should be regenerated as 1
Actual: The old cached output is reused and the output remains 0

full console output

dfab: /tp/remote-cache-key-runfiles $ bazel clean && bazel build --hazelcast_node=localhost:5701 --genrule_strategy=remote --spawn_strategy=remote :x && more bazel-genfiles/out.txt
.
INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes.
INFO: Found 1 target...
Target //:x up-to-date:
  bazel-genfiles/out.txt
INFO: Elapsed time: 2.304s, Critical Path: 0.07s
0
dfab: /tp/remote-cache-key-runfiles $ echo 1 > runfile
dfab: /tp/remote-cache-key-runfiles $ bazel clean && bazel build --hazelcast_node=localhost:5701 --genrule_strategy=remote --spawn_strategy=remote :x && more bazel-genfiles/out.txt
INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes.
INFO: Found 1 target...
Target //:x up-to-date:
  bazel-genfiles/out.txt
INFO: Elapsed time: 1.622s, Critical Path: 0.02s
0
dfab: /tp/remote-cache-key-runfiles $ bazel version
Build label: 0.3.1
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Jul 29 09:05:18 2016 (1469783118)
Build timestamp: 1469783118
Build timestamp as int: 1469783118
@dfabulich
Copy link
Contributor Author

Inspecting in a debugger, the runfiles are attached to the action as a "middleman" artifact. RemoteSpawnStrategy dutifully calls ActionInputHelper.expandArtifacts to expand the runfiles, but the actionExecutionContext's ArtifactExpanderImpl has an empty expandedInputs map; thus the middleman's inputs are not expanded and are omitted from the cache key.

This, in turn, is happening because ActionExecutionFunction.checkInputs, which (I think) is responsible for populating the expandedInputs, doesn't know how to handle middleman artifacts. It treats middleman artifacts as ordinary FileArtifactValues.

@dfabulich
Copy link
Contributor Author

Looks like there was an incriminating TODO in 0.3.1

// TODO(bazel-team): Make sure middleman "virtual" artifact data is properly processed.

// TODO(bazel-team): Make sure middleman "virtual" artifact data is properly processed.

That TODO was eliminated but apparently not addressed in ad77f97 because this test fails on the latest master, too.

@dfabulich
Copy link
Contributor Author

Wait a minute. We're just computing a hash; we don't need to expand the middlemen. We can use their original value. I'll pull together a PR

@dfabulich
Copy link
Contributor Author

@meteorcloudy
Copy link
Member

//cc @dslomov Can you review this change?

@meteorcloudy meteorcloudy added type: bug P2 We'll consider working on this in future. (Assignee optional) labels Aug 2, 2016
rjaquino pushed a commit to Asana/bazel that referenced this issue Aug 31, 2016
Fixes bazelbuild#1593

Change-Id: I18b659da5abc79f7c7aa58afd10ebe565e1479e5
@ulfjack
Copy link
Contributor

ulfjack commented Dec 1, 2016

Closing because there's a commit that references this bug. Please reopen if this isn't fixed.

@ulfjack ulfjack closed this as completed Dec 1, 2016
@benjaminp
Copy link
Collaborator

I don't think this is fixed. I can't find the commit that references this bug. Moreover, the latest master still expands the input file artifacts before computing the cumulative input digest and consequently fails to consider the runfiles middleman.

@ulfjack
Copy link
Contributor

ulfjack commented Jan 17, 2017

The commit is linked just above my comment, hash 6734f43.

@benjaminp
Copy link
Collaborator

benjaminp commented Jan 17, 2017 via email

@ulfjack
Copy link
Contributor

ulfjack commented Jan 17, 2017

Doh!

@dslomov
Copy link
Contributor

dslomov commented Feb 16, 2017

@ulfjack is this the right category?

@ulfjack
Copy link
Contributor

ulfjack commented Feb 16, 2017

Let me put it under service APIs, which is marginally better.

@ulfjack
Copy link
Contributor

ulfjack commented Mar 1, 2017

I have some changes in flight to prepare for open sourcing the code we're using internally to handle runfiles.

@ulfjack ulfjack self-assigned this Mar 1, 2017
bazel-io pushed a commit that referenced this issue Mar 17, 2017
…ategies

This new class is a combination of SpawnHelper and our internal code; the
plan is to migrate all spawn strategies to the new class. The strict flag
should be enabled by default, but that's a breaking change, so we need to do
it later.

- Use it in SandboxStrategy.
- Add ActionInput.getExecPath to return a PathFragment; this avoids lots of
  back and forth between path fragments and strings.

This is a step towards #1593.

--
PiperOrigin-RevId: 150427021
MOS_MIGRATED_REVID=150427021
bazel-io pushed a commit that referenced this issue Mar 21, 2017
Add preconditions to enforce this and remove some now unnecessary code.

A small step towards #1593.

--
PiperOrigin-RevId: 150625693
MOS_MIGRATED_REVID=150625693
bazel-io pushed a commit that referenced this issue Mar 21, 2017
Update some callers to use getExecPath, which generally results in less
intermediate garbage generation (almost all callers need a PathFragment, not
a String).

Another small step towards #1593.

--
PiperOrigin-RevId: 150631279
MOS_MIGRATED_REVID=150631279
bazel-io pushed a commit that referenced this issue Mar 21, 2017
…ategies

This new class is a combination of SpawnHelper and our internal code; the
plan is to migrate all spawn strategies to the new class. The strict flag
should be enabled by default, but that's a breaking change, so we need to do
it later.

- Use it in SandboxStrategy.
- Add ActionInput.getExecPath to return a PathFragment; this avoids lots of
  back and forth between path fragments and strings.

This is a step towards #1593.

The previous attempt was missing a one-line patch in StandaloneTestStrategy,
which broke all tests with sandboxing. StandaloneTestStrategy was fixed in a
separate change, so this should be safe now.

--
PiperOrigin-RevId: 150733457
MOS_MIGRATED_REVID=150733457
markchua pushed a commit to Asana/bazel that referenced this issue Mar 24, 2017
Fixes bazelbuild#1593

Change-Id: I18b659da5abc79f7c7aa58afd10ebe565e1479e5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) type: bug
Projects
None yet
Development

No branches or pull requests

5 participants