deplinenoise / tundra

Tundra is a code build system that tries to be accurate and fast for incremental builds
MIT License
438 stars 74 forks source link

Precompiled headers get generated multiple times when using DefRule #317

Open trixnz opened 5 years ago

trixnz commented 5 years ago

When adding a DefRule to my Sources list, precompiled headers seem to be created N times for each Variant declared, resulting in the same file being the output target and failing to build.

The following tundra.lua demonstrates this using the latest v2.08 build:

Build {
    Units = function()
        DefRule {
            Name = "ExampleGenerator",
            Pass = "ExamplePass",
            Command = "echo Building $(<) $(@) > $(@)",
            ConfigInvariant = false,
            Blueprint = {
                Source = {Required = true, Type = "string", Help = "Input filename"},
                OutName = {Required = true, Type = "string", Help = "Output filename"}
            },
            Setup = function(env, data)
                return {
                    InputFiles = {data.Source},
                    OutputFiles = {"$(OBJECTDIR)/_generated/" .. data.OutName}
                }
            end
        }

        local App = Program
        {
            Name = "App",
            PrecompiledHeader = {
                Source = "stdafx.cpp",
                Header = "stdafx.h",
                Pass = "PchGen"
            },
            Sources = {
                ExampleGenerator {
                    Source = "example.txt",
                    OutName = "example.h"
                }
            }
        }

        Default(App)
    end,

    Passes = {
        ExamplePass = {Name = "Example Pass", BuildOrder = 1},
        PchGen = {Name = "Precompiled Header Generation", BuildOrder = 2}
    },

    Configs = {
        Config {
            Name = "win32-msvc",
            SupportedHosts = {"windows"},
            DefaultOnHost = "windows",
            Tools = {
                {"msvc-vs2017", TargetArch = "x86"}
            }
        }
    },

    Variants = {"debug", "release", "production"}
}

Logging the source_files var from x_source_list shows this clearly:

Generating DAG for win32-msvc-release-default
Source list
{
  [1] =     {
      DagCache= <nested table>
      __index= <nested table>
      Decl= <nested table>
    },
  [2] = "stdafx.cpp",
}
Generating DAG for win32-msvc-debug-default
Source list
{
  [1] =     {
      DagCache= <nested table>
      __index= <nested table>
      Decl= <nested table>
    },
  [2] = "stdafx.cpp",
  [3] = "stdafx.cpp",
}
Generating DAG for win32-msvc-production-default
Source list
{
  [1] =     {
      DagCache= <nested table>
      __index= <nested table>
      Decl= <nested table>
    },
  [2] = "stdafx.cpp",
  [3] = "stdafx.cpp",
  [4] = "stdafx.cpp",
}
save_dag_data: 3 bindings, 26 accessed files