tazel
A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.
Clonegit clone https://git.progmasoft.com/tazel
Give project files the whole base class library, with no implicit using
- Commit
4ed05c9d5a5cd8d7c463e242a30ec3dbbc0af16c- Author
- Leitwolf11 ·
- Parents
12f2ea5f0608
Changes
CHANGELOG.md | 3 ++- docs/remote-cache.md | 2 ++ src/Progmasoft.Tazel/Project/ScriptHost.cs | 15 +++++++-------- tests/Progmasoft.Tazel.Tests/RemoteCacheTests.cs | 24 +++++++++++++++++++++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b109a41..89a0d15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ bazel-remote, and gives it the results of actions run here. Keys do not depend on where the module is; headers a compiler found are checked by digest before a result is taken, and every file by its SHA-256. A cache that cannot be reached is said once, and the build goes on. -- Project files import `System`, so `Environment.GetEnvironmentVariable` works as the examples write it. +- Project files reach the whole base class library of .NET; each namespace is named with `using`, and none is + imported for them. ## 0.1.0 - 2026-11-20 diff --git a/docs/remote-cache.md b/docs/remote-cache.md index c0472a9..ee100cc 100644 --- a/docs/remote-cache.md +++ b/docs/remote-cache.md @@ -8,6 +8,8 @@ instead of running the compiler again. Tazel speaks Bazel's HTTP caching protoco [bazel-remote](https://github.com/buchgr/bazel-remote) serves it. ```cs +using System; + cache = Cache.Define(new() { Remote = Remote.From("https://cache.example.com", new() { Read = true, // default: true diff --git a/src/Progmasoft.Tazel/Project/ScriptHost.cs b/src/Progmasoft.Tazel/Project/ScriptHost.cs index 57f556d..e46e105 100644 --- a/src/Progmasoft.Tazel/Project/ScriptHost.cs +++ b/src/Progmasoft.Tazel/Project/ScriptHost.cs @@ -83,15 +83,15 @@ internal static class ScriptHost private static ScriptOptions CreateOptions() { + // The whole base class library: every managed assembly of the .NET runtime Tazel runs on, as the host lists + // them. A project file still names what it uses with using; nothing of it is imported for it. var runtime = Path.GetDirectoryName(typeof(object).Assembly.Location)!; var references = new List<MetadataReference>(); - foreach (var name in new[] { "System.Runtime.dll", "System.Collections.dll", "System.Linq.dll", "netstandard.dll" }) + var trusted = (AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES") as string ?? "").Split(Path.PathSeparator); + foreach (var file in trusted.Where(file => file.Length > 0 && + string.Equals(Path.GetDirectoryName(file), runtime, StringComparison.Ordinal))) { - var file = Path.Combine(runtime, name); - if (File.Exists(file)) - { - references.Add(MetadataReference.CreateFromFile(file)); - } + references.Add(MetadataReference.CreateFromFile(file)); } foreach (var assembly in new[] @@ -105,8 +105,7 @@ internal static class ScriptHost return ScriptOptions.Default .WithReferences(references) - // System for what the examples of the project files use, such as Environment.GetEnvironmentVariable. - .WithImports(CommonNamespace, "System") + .WithImports(CommonNamespace) .WithLanguageVersion(LanguageVersion.Latest) .WithOptimizationLevel(OptimizationLevel.Debug) .WithEmitDebugInformation(false) diff --git a/tests/Progmasoft.Tazel.Tests/RemoteCacheTests.cs b/tests/Progmasoft.Tazel.Tests/RemoteCacheTests.cs index 2e588b5..962937d 100644 --- a/tests/Progmasoft.Tazel.Tests/RemoteCacheTests.cs +++ b/tests/Progmasoft.Tazel.Tests/RemoteCacheTests.cs @@ -46,13 +46,16 @@ public sealed class RemoteCacheTests .Write("main.c", "#include \"value.h\"\nint main(void) { return VALUE == 42 ? 0 : 1; }\n"); [Fact] - public async Task AProjectFileReadsItsTokenFromTheEnvironment() + public async Task AProjectFileUsesTheBaseClassLibraryThroughItsUsings() { - // As the examples write it: Environment without System., which project files import. + // A project file reaches the whole base class library, naming each namespace with using. using var module = new TemporaryModule() .Write("MODULE.csx", """ + using System; + using System.Text.Json; using Progmasoft.Tazel.Dsl.Module.Prelude; - module = Module.Define(new() { Group = "com.example", Name = "sample", Version = "0.1.0" }); + var parsed = JsonDocument.Parse("{\"group\": \"com.example\"}").RootElement.GetProperty("group").GetString(); + module = Module.Define(new() { Group = parsed!, Name = "sample", Version = "0.1.0" }); cache = Cache.Define(new() { Remote = Remote.From("https://cache.example.com", new() { Token = Environment.GetEnvironmentVariable("TAZEL_TEST_NO_SUCH_TOKEN") }) }); @@ -65,6 +68,21 @@ public sealed class RemoteCacheTests Assert.Null(workspace.Main.Globals.cache!.Settings.Remote!.Settings.Token); } + [Fact] + public async Task NothingIsImportedThatAProjectFileDoesNotName() + { + using var module = new TemporaryModule() + .Write("MODULE.csx", """ + using Progmasoft.Tazel.Dsl.Module.Prelude; + module = Module.Define(new() { Group = Environment.UserName, Name = "sample", Version = "0.1.0" }); + """) + .Write("BUILD.csx", "using Progmasoft.Tazel.Dsl.Build.Prelude;\n"); + + var error = await Assert.ThrowsAsync<Progmasoft.Tazel.Project.ProjectException>(() => module.LoadAsync()); + + Assert.Contains("CS0103", error.Message, StringComparison.Ordinal); + } + [Fact] public void AResultIsTheProtocolBufferOfTheRemoteExecutionApi() {