Progmasoft Git

tazel

A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.

Clonegit clone https://git.progmasoft.com/tazel

Let IncludeDirectories name the package's own directory with "."

IncludeDirectories = ["."], Bazel's includes = ["."], was refused as a
path with a "." part. "." alone now names the package's directory, for
the target and what depends on it; any other path with a "." or ".."
part is still refused. Found by the smoke test of the next release.
Commit
0d04d28734d205f8e3fb3d898358a2ec4e1e470e
Author
Leitwolf11 ·
Parents
da1e7fed33d9

Files · Download .tar.gz

Changes

 CHANGELOG.md                                       |  2 ++
 docs/project-files.md                              |  2 +-
 .../Build/Prelude/CCSettings.cs                    |  5 +++-
 src/Progmasoft.Tazel/Driver/CCPlanner.cs           |  5 +++-
 tests/Progmasoft.Tazel.Tests/BuildCommandTests.cs  | 29 ++++++++++++++++++++++
 5 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d0f8308..9640294 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@
 
 ## Unreleased
 
+- `IncludeDirectories = ["."]` names the package's own directory, as `includes = ["."]` does in Bazel; it was refused.
+
 - `--message-format rich-stdio|script-friendly-stdio|jsonl|xml`: the rich terminal output as before, plain lines that
   start with a fixed word for scripts and logs, one JSON object per message per line, or one XML document. Errors of
   the command line come in the format it asks for.
diff --git a/docs/project-files.md b/docs/project-files.md
index 692cfc1..5493c12 100644
--- a/docs/project-files.md
+++ b/docs/project-files.md
@@ -125,7 +125,7 @@ CC.Test("math_test", new()
   `Tags = ["manual"]` keeps a target out of `//...` as well.
 - **Conditions** are C#: `Build.Mode` (`BuildMode.Debug`, `Release`), `Build.Platform`, `Build.OS`, `Build.Arch`.
 - **Headers** of a target are found below the root of its module and below its `IncludeDirectories`, by it and by
-  what depends on it.
+  what depends on it. An entry is a path below the package, or `"."` for the package's own directory.
 
 ### Objective-C
 
diff --git a/src/Progmasoft.Tazel.Dsl/Build/Prelude/CCSettings.cs b/src/Progmasoft.Tazel.Dsl/Build/Prelude/CCSettings.cs
index 788e57d..5369597 100644
--- a/src/Progmasoft.Tazel.Dsl/Build/Prelude/CCSettings.cs
+++ b/src/Progmasoft.Tazel.Dsl/Build/Prelude/CCSettings.cs
@@ -66,7 +66,10 @@ public abstract class CCSettings : TargetSettings
     /// <summary>Headers that are included but never compiled alone.</summary>
     public Files TextualHeaders { get; init; } = Files.None;
 
-    /// <summary>Directories of this target's headers, for it and its dependents.</summary>
+    /// <summary>
+    /// Directories of this target's headers, for it and its dependents: paths below the package, or <c>"."</c> for
+    /// the package's own directory.
+    /// </summary>
     public IReadOnlyList<string> IncludeDirectories { get; init; } = [];
 
     /// <summary>Options for every file.</summary>
diff --git a/src/Progmasoft.Tazel/Driver/CCPlanner.cs b/src/Progmasoft.Tazel/Driver/CCPlanner.cs
index 3810044..8622acd 100644
--- a/src/Progmasoft.Tazel/Driver/CCPlanner.cs
+++ b/src/Progmasoft.Tazel/Driver/CCPlanner.cs
@@ -91,8 +91,11 @@ internal sealed partial class Planner
             .Concat(FileSets.Resolve(settings.TextualHeaders, target.PackageDirectory, Layout.MainRoot, target.Place))
             .ToList();
         products.PublicIncludes.Add(FileSets.ToRoot(target.Module.Root, Layout.MainRoot));
+        // "." is the package's own directory, as Bazel's includes = ["."]; every other entry is a path below it.
         products.PublicIncludes.AddRange(settings.IncludeDirectories
-            .Select(directory => FileSets.PathIn(directory, target.PackageDirectory, Layout.MainRoot, target.Place, mustExist: true)));
+            .Select(directory => directory == "."
+                ? FileSets.ToRoot(target.PackageDirectory, Layout.MainRoot)
+                : FileSets.PathIn(directory, target.PackageDirectory, Layout.MainRoot, target.Place, mustExist: true)));
         products.PublicDefines.AddRange(settings.PreprocessorDefinitions);
         products.PublicHeaders.AddRange(headers);
         var includes = new List<string>(products.PublicIncludes);
diff --git a/tests/Progmasoft.Tazel.Tests/BuildCommandTests.cs b/tests/Progmasoft.Tazel.Tests/BuildCommandTests.cs
index 0b427fa..061c82b 100644
--- a/tests/Progmasoft.Tazel.Tests/BuildCommandTests.cs
+++ b/tests/Progmasoft.Tazel.Tests/BuildCommandTests.cs
@@ -113,6 +113,35 @@ public sealed class BuildCommandTests
         Assert.Contains("and not builds, tests or plugins, so nothing ran", output, StringComparison.Ordinal);
     }
 
+    [Fact]
+    public async Task ADotIncludesThePackagesOwnDirectory()
+    {
+        Assert.SkipWhen(Host.Which("clang++") is null && Host.Which("g++") is null, "no C++ compiler on PATH");
+        Assert.SkipWhen(OperatingSystem.IsWindows() && Environment.GetEnvironmentVariable("INCLUDE") is null,
+            "no MSVC environment for clang on Windows");
+        using var module = new TemporaryModule()
+            .Write("MODULE.csx", TemporaryModule.ModuleFile)
+            .Write("lib/BUILD.csx", """
+                using Progmasoft.Tazel.Dsl.Build.Prelude;
+                CC.StaticLibrary("greet", new()
+                {
+                    Sources = ["greet.cpp"], Headers = ["greet.hpp"], IncludeDirectories = ["."], Visibility = Visibility.Public,
+                });
+                """)
+            .Write("lib/greet.hpp", "#pragma once\nint greet();\n")
+            .Write("lib/greet.cpp", "#include \"greet.hpp\"\nint greet() { return 3; }\n")
+            .Write("BUILD.csx", "using Progmasoft.Tazel.Dsl.Build.Prelude;\nCC.Executable(\"app\", new() { Sources = [\"main.cpp\"], Depends = [\"//lib:greet\"] });\n")
+            .Write("main.cpp", "#include \"greet.hpp\"\nint main() { return greet() == 3 ? 0 : 1; }\n");
+        var (status, output) = await module.TazelAsync(".", "run", "//:app");
+        Assert.True(status == 0, output);
+
+        // Only "." alone: a path with a "." part still is no path below the package.
+        module.Write("lib/BUILD.csx", "using Progmasoft.Tazel.Dsl.Build.Prelude;\nCC.StaticLibrary(\"greet\", new() { IncludeDirectories = [\"./sub\"], Visibility = Visibility.Public });\n");
+        (status, output) = await module.TazelAsync(".", "build", "//lib:greet");
+        Assert.Equal(1, status);
+        Assert.True(output.Contains("has no . or .. parts", StringComparison.Ordinal), output);
+    }
+
     [Fact]
     public async Task BuildsAZigProgramThatImportsAModule()
     {