question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

First build fails due to missing inputs created by repository_rule

See original GitHub issue

The first build fails, but immediately building again succeeds. The setup is unusual: npm installation creates a directory in the user’s project, which we want to use as inputs to later actions.

Repro:

WORKSPACE

workspace(name = "repro")
load("//:defs.bzl", "repo")
repo(file_in_project = "//:BUILD")

defs.bzl

def _repo_rule_impl(ctx):
  # Grab a reference to the root of the users project
  project_dir = ctx.path(ctx.attr.file_in_project).dirname
  # Emulate installing npm dependencies there
  ctx.file("install.sh", """#!/bin/bash
  cd $(dirname $1)
  mkdir node_modules
  echo "hello" > node_modules/some-file.txt
  ls -R
  """)
  result = ctx.execute(["./install.sh", ctx.path(ctx.attr.file_in_project)])
  print(result.stdout)
  if result.return_code > 0:
    print(result.stderr)
  # Create a symlink so external repo can reference the installed node packages
  ctx.symlink(project_dir, "installed")

_repo_rule = repository_rule(_repo_rule_impl,
  attrs = {"file_in_project": attr.label()})

def repo(file_in_project):
  _repo_rule(name = "foo", file_in_project=file_in_project)

BUILD

filegroup(
    name = "generated",
    srcs=glob(["node_modules/**"]),
    visibility=["//visibility:public"]
)

genrule(
  name = "test",
  outs = ["out"],
  cmd = "echo works > $@",
  # This points through the symlink to the filegroup above
  srcs = ["@foo//installed:generated"]
)

On the initial build (or after rm -rf node_modules/; bazel clean --expunge) the build fails. Note that the node_modules directory doesn’t exist in the project at the start of the build, but does exist before the actions execute:

$ bazel build :test
...........
WARNING: /home/alexeagle/repro6/defs.bzl:13:3: .:
BUILD
defs.bzl
node_modules
WORKSPACE

./node_modules:
some-file.txt
.
INFO: Found 1 target...
ERROR: missing input file '@foo//installed:node_modules/some-file.txt'.
ERROR: /home/alexeagle/repro6/BUILD:2:1: //:test: missing input file '@foo//installed:node_modules/some-file.txt'.
Target //:test failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/alexeagle/repro6/BUILD:2:1 1 input file(s) do not exist.
INFO: Elapsed time: 2.505s, Critical Path: 0.01s

Now the node_modules directory exists before the build starts, and simply building again succeeds:

$ bazel build :test
WARNING: /home/alexeagle/repro6/defs.bzl:12:3: .:
BUILD
defs.bzl
node_modules
WORKSPACE

./node_modules:
some-file.txt
.
INFO: Found 1 target...
Target //:test up-to-date:
  bazel-genfiles/out
INFO: Elapsed time: 0.213s, Critical Path: 0.00s

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
archanaaracommented, Aug 23, 2018

Anyone know about @nlohmann_json_lib//:license.txt’ I am not finding any results for that. Please help

0reactions
janakdrcommented, May 12, 2020

@archanaara your issue looks unrelated. Please open a new issue if you need it. The npm issue has been fixed by extending Bazel, I think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing input files error for expanded input - Google Groups
Hi,. I am having the same issue with a rule in one of my workflows. It gives the missing input exception, but the...
Read more >
[Support Guide] Frequently encountered problems during builds
1. First steps - ruling out the obvious. In case your build fails on Netlify, first make sure it builds locally in your...
Read more >
'Build input file cannot be found' Swift 4.2, Xcode 10.0
In my case I got this error when I renamed a ViewController name using Refactor. The view controller name occurrences were ...
Read more >
"Build input file cannot be found" | Apple Developer Forums
I changed my project name in project navigator and right after I tried to simulate it. An error appeared and said "Build input...
Read more >
Command-Line Reference | Bazel
Note that repository rules see the full environment anyway, ... or Starlark rules with debugging failures due to missing input files, etc.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found