Skip to content

Rule dependencies' behaviour is strange, possibly broken or poorly documented #626

@alexeymuranov

Description

@alexeymuranov

Consider this Rakefile:

require 'rake/clean'

task default: :test
task test: 'test.txt'

file 'test.txt' => 'test0.txt'

rule '.txt' => '.pre' do |t|
  sh 'cp', t.source, t.name
end

rule '.pre' do |t|
  sh 'touch', t.name
end

CLEAN.include('*.pre')
CLOBBER.include('*.txt')

This Rakefile demonstrates 2 related issues.

The implicit dependency test.pre is not built automatically

In a folder containing only this Rakefile, try:

$ rake
touch test0.pre
cp test0.pre test0.txt
cp test.pre test.txt
cp: cannot stat 'test.pre': No such file or directory
rake aborted!
Command failed with status (1): [cp test.pre test.txt...]
[...]

This creates test0.pre and test0.txt, but fails to create test.pre and test.txt.

However, the following sequence of commands works without issues:

$ rake test.pre
touch test.pre
$ rake
touch test0.pre
cp test0.pre test0.txt
cp test.pre test.txt

Thus, rake knows how to build test.pre, but skips it unless asked explicitly.

Note that despite skipping test.pre, rake builds test0.pre automatically, while both are dependencies by the same rule.

In fact, starting from a folder containing only this Rakefile,

  • rake test0.txt works,
  • rake test.txt fails.

Updating test.pre does not trigger rebuilding of test.txt

Assume that everything has been built with

$ rake test.pre
$ rake

Now, try this:

$ touch test.pre
$ rake

Nothing happens.

Now, try:

$ touch test0.pre
$ rake
cp test0.pre test0.txt
cp test.pre test.txt

This triggers rebuilding.

Rake version

rake version: 13.0.6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions