From 57f3c56fe01559f21a715ea95f576fb61a44a8f1 Mon Sep 17 00:00:00 2001 From: Jonathan Steyfkens Date: Sun, 31 Jan 2021 16:35:06 +0000 Subject: [PATCH 1/4] Update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4c38c1754..6051806de 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,4 @@ Sharpmake.VC.db # Desktop Services Store on MacOS **/.DS_Store +deploy From 8250f03aee3c1b89b0e6338a09856bf6f9d73e48 Mon Sep 17 00:00:00 2001 From: Jonathan Steyfkens Date: Sun, 31 Jan 2021 17:31:48 +0000 Subject: [PATCH 2/4] Improvements to allow better dependency build order management. - Added InheritBuildSteps to control taking build steps from child projects - Allow build order only exe dependencies for lib projects. This is useful for making sure a tool is build before running the build (thinking custom build step here) --- .../VisualStudio/ProjectOptionsGenerator.cs | 4 +- Sharpmake/Project.Configuration.cs | 33 ++-- .../PreBuildStepDependency.sharpmake.cs | 142 ++++++++++++++++++ .../codebase/app/main.cpp | 12 ++ .../codebase/lib/lib.cpp | 5 + .../PreBuildStepDependency/codebase/lib/lib.h | 3 + .../codebase/tool/main.cpp | 12 ++ samples/Sharpmake.Samples.sharpmake.cs | 12 ++ 8 files changed, 211 insertions(+), 12 deletions(-) create mode 100644 samples/PreBuildStepDependency/PreBuildStepDependency.sharpmake.cs create mode 100644 samples/PreBuildStepDependency/codebase/app/main.cpp create mode 100644 samples/PreBuildStepDependency/codebase/lib/lib.cpp create mode 100644 samples/PreBuildStepDependency/codebase/lib/lib.h create mode 100644 samples/PreBuildStepDependency/codebase/tool/main.cpp diff --git a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs index 2ebf02dd0..77f472672 100644 --- a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs +++ b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs @@ -1824,7 +1824,9 @@ private void GeneratePostBuildOptions(IGenerationContext context, ProjectOptions if (!context.Configuration.IsFastBuild) { - if (context.Configuration.Output == Project.Configuration.OutputType.Exe || context.Configuration.ExecuteTargetCopy) + if ( context.Configuration.Output == Project.Configuration.OutputType.Exe + || context.Configuration.Output == Project.Configuration.OutputType.Lib + || context.Configuration.ExecuteTargetCopy) { foreach (var customEvent in context.Configuration.ResolvedEventPreBuildExe) { diff --git a/Sharpmake/Project.Configuration.cs b/Sharpmake/Project.Configuration.cs index 9d37b73f9..d2f50bc8e 100644 --- a/Sharpmake/Project.Configuration.cs +++ b/Sharpmake/Project.Configuration.cs @@ -64,6 +64,7 @@ public enum DependencySetting /// AdditionalUsingDirectories = 1 << 5, ForceUsingAssembly = 1 << 6, + InheritBuildSteps = 1 << 7, /// /// Specifies that the dependent project inherits the dependency's library files, library @@ -72,7 +73,8 @@ public enum DependencySetting Default = LibraryFiles | LibraryPaths | IncludePaths | - Defines, + Defines | + InheritBuildSteps, /// /// Specifies that the dependent project inherits the dependency's include paths and @@ -86,6 +88,11 @@ public enum DependencySetting | IncludePaths | Defines, + DefaultWithoutBuildSteps = LibraryFiles + | LibraryPaths + | IncludePaths + | Defines, + //////////////////////////////////////////////////////////////////////// // OLD AND DEPRECATED FLAGS @@ -2815,7 +2822,7 @@ internal void Link(Builder builder) dependency.Project.SharpmakeProjectType == ProjectTypeAttribute.Compile; var dependencySetting = propagationSetting._dependencySetting; - if (dependencySetting != DependencySetting.OnlyBuildOrder) + if (dependencySetting.HasFlag(DependencySetting.InheritBuildSteps)) { _resolvedEventPreBuildExe.AddRange(dependency.EventPreBuildExe); _resolvedEventPostBuildExe.AddRange(dependency.EventPostBuildExe); @@ -2962,18 +2969,22 @@ internal void Link(Builder builder) case OutputType.IosApp: case OutputType.Exe: { - if (Output != OutputType.Utility && Output != OutputType.Exe && Output != OutputType.None) - throw new Error("Project {0} cannot depend on OutputType {1} {2}", this, Output, dependency); + if(dependencySetting != DependencySetting.OnlyBuildOrder) + { + if (Output != OutputType.Utility && Output != OutputType.Exe && Output != OutputType.None) + throw new Error("Project {0} cannot depend on OutputType {1} {2}", this, Output, dependency); - if (hasPublicPathToRoot) - resolvedDotNetPublicDependencies.Add(new DotNetDependency(dependency)); - else if (isImmediate) - resolvedDotNetPrivateDependencies.Add(new DotNetDependency(dependency)); + if (hasPublicPathToRoot) + resolvedDotNetPublicDependencies.Add(new DotNetDependency(dependency)); + else if (isImmediate) + resolvedDotNetPrivateDependencies.Add(new DotNetDependency(dependency)); - if (dependencySetting == DependencySetting.OnlyBuildOrder) - BuildOrderDependencies.Add(dependency); - else ConfigurationDependencies.Add(dependency); + } + else + { + BuildOrderDependencies.Add(dependency); + } } break; case OutputType.Utility: throw new NotImplementedException(dependency.Project.Name + " " + dependency.Output); diff --git a/samples/PreBuildStepDependency/PreBuildStepDependency.sharpmake.cs b/samples/PreBuildStepDependency/PreBuildStepDependency.sharpmake.cs new file mode 100644 index 000000000..673199f98 --- /dev/null +++ b/samples/PreBuildStepDependency/PreBuildStepDependency.sharpmake.cs @@ -0,0 +1,142 @@ +// Copyright (c) 2017 Ubisoft Entertainment +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Sharpmake; + +namespace PreBuildStepDependency +{ + [Generate] + public class ToolProject : Project + { + public ToolProject() + { + Name = "Tool"; + + AddTargets(new Target( + Platform.win64, + DevEnv.vs2019, + Optimization.Debug // | Optimization.Release + )); + + SourceRootPath = @"[project.SharpmakeCsPath]\codebase\tool"; + } + + [Configure()] + public void ConfigureAll(Configuration conf, Target target) + { + conf.ProjectFileName = "[project.Name]_[target.DevEnv]_[target.Platform]"; + conf.ProjectPath = @"[project.SharpmakeCsPath]\projects"; + conf.IntermediatePath = @"[project.SharpmakeCsPath]\projects\intermediate\[project.Name]_[target.DevEnv]_[target.Platform]"; + conf.Output = Configuration.OutputType.Exe; + } + } + + [Generate] + public class AppProject : Project + { + public AppProject() + { + Name = "App"; + + + AddTargets(new Target( + Platform.win64, + DevEnv.vs2019, + Optimization.Debug // | Optimization.Release + )); + + SourceRootPath = @"[project.SharpmakeCsPath]\codebase\app"; + } + + [Configure()] + public void ConfigureAll(Configuration conf, Target target) + { + conf.ProjectFileName = "[project.Name]_[target.DevEnv]_[target.Platform]"; + conf.ProjectPath = @"[project.SharpmakeCsPath]\projects"; + conf.IntermediatePath = @"[project.SharpmakeCsPath]\projects\intermediate\[project.Name]_[target.DevEnv]_[target.Platform]"; + + conf.AddPrivateDependency(target, DependencySetting.DefaultWithoutBuildSteps); + + Configuration.BuildStepExecutable tool = new Configuration.BuildStepExecutable(@"[project.SharpmakeCsPath]\projects\output\win64\debug\tool.exe", "", "", "-Flag1 -Flag2 -DoStuff=256"); + conf.EventPreBuildExe.Add(tool); + + } + } + + [Generate] + public class LibProject : Project + { + public LibProject() + { + Name = "Lib"; + + AddTargets(new Target( + Platform.win64, + DevEnv.vs2019, + Optimization.Debug // | Optimization.Release + )); + + SourceRootPath = @"[project.SharpmakeCsPath]\codebase\lib"; + } + + [Configure()] + public void ConfigureAll(Configuration conf, Target target) + { + conf.ProjectFileName = "[project.Name]_[target.DevEnv]_[target.Platform]"; + conf.ProjectPath = @"[project.SharpmakeCsPath]\projects"; + conf.IntermediatePath = @"[project.SharpmakeCsPath]\projects\intermediate\[project.Name]_[target.DevEnv]_[target.Platform]"; + + conf.Output = Configuration.OutputType.Lib; + conf.IncludePaths.Add(conf.Project.SourceRootPath); + + // Depend on our 'tool' to be build first + conf.AddPrivateDependency(target, DependencySetting.OnlyBuildOrder); + + Configuration.BuildStepExecutable tool = new Configuration.BuildStepExecutable(@"[project.SharpmakeCsPath]\projects\output\win64\debug\tool.exe", "", "", "-Flag1 -Flag2 -DoStuff=123"); + conf.EventPreBuildExe.Add(tool); + } + } + + + [Sharpmake.Generate] + public class PreBuildStepDependencySolution : Sharpmake.Solution + { + public PreBuildStepDependencySolution() + { + Name = "PreBuildStepDependency"; + + AddTargets(new Target( + Platform.win64, + DevEnv.vs2019, + Optimization.Debug // | Optimization.Release + )); + } + + [Configure()] + public void ConfigureAll(Configuration conf, Target target) + { + conf.SolutionFileName = "[solution.Name]_[target.DevEnv]_[target.Platform]"; + conf.SolutionPath = @"[solution.SharpmakeCsPath]\projects"; + conf.AddProject(target); + conf.AddProject(target); + conf.AddProject(target); + } + + [Sharpmake.Main] + public static void SharpmakeMain(Sharpmake.Arguments arguments) + { + arguments.Generate(); + } + } +} diff --git a/samples/PreBuildStepDependency/codebase/app/main.cpp b/samples/PreBuildStepDependency/codebase/app/main.cpp new file mode 100644 index 000000000..e3d21d2ca --- /dev/null +++ b/samples/PreBuildStepDependency/codebase/app/main.cpp @@ -0,0 +1,12 @@ +#include + +#include "lib.h" + +int main(const int, char*) +{ + printf("[APP]: Executing app"); + + execute_my_fn(); + + return 0; +} diff --git a/samples/PreBuildStepDependency/codebase/lib/lib.cpp b/samples/PreBuildStepDependency/codebase/lib/lib.cpp new file mode 100644 index 000000000..4ffc22694 --- /dev/null +++ b/samples/PreBuildStepDependency/codebase/lib/lib.cpp @@ -0,0 +1,5 @@ +#include + +void execute_my_fn() { + printf("\"execute_my_fn\" has been called."); +} diff --git a/samples/PreBuildStepDependency/codebase/lib/lib.h b/samples/PreBuildStepDependency/codebase/lib/lib.h new file mode 100644 index 000000000..48ff23cde --- /dev/null +++ b/samples/PreBuildStepDependency/codebase/lib/lib.h @@ -0,0 +1,3 @@ +#pragma once + +void execute_my_fn(); diff --git a/samples/PreBuildStepDependency/codebase/tool/main.cpp b/samples/PreBuildStepDependency/codebase/tool/main.cpp new file mode 100644 index 000000000..7ec6b74a4 --- /dev/null +++ b/samples/PreBuildStepDependency/codebase/tool/main.cpp @@ -0,0 +1,12 @@ +#include +int main(const int argc, char* argvs[]) +{ + printf("[PREBUILD]: Calling prebuilt tool.\n"); + printf("[PREBUILD]: "); + for (int i = 0; i < argc; ++i) + { + printf("%s ", argvs[i]); + } + printf("\n"); + return 0; +} diff --git a/samples/Sharpmake.Samples.sharpmake.cs b/samples/Sharpmake.Samples.sharpmake.cs index 5bfb3d99b..768c515e0 100644 --- a/samples/Sharpmake.Samples.sharpmake.cs +++ b/samples/Sharpmake.Samples.sharpmake.cs @@ -117,6 +117,7 @@ public CSharpWcfProject() } } + [Generate] public class DotNetCoreFrameworkHelloWorldProject : SampleProject { @@ -234,4 +235,15 @@ public SimpleExeLibDependencyProject() Name = "SimpleExeLibDependency"; } } + + [Generate] + public class PreBuildStepDependency : SampleProject + { + public PreBuildStepDependency() + { + Name = "PreBuildStepDependency"; + SharpmakeMainFile = "PreBuildStepDependency.sharpmake.cs"; + } + } + } From e5eb558c40ea7012f955d62c5ded2e93b2c9b5d6 Mon Sep 17 00:00:00 2001 From: Jonathan Steyfkens Date: Wed, 10 Feb 2021 20:17:05 +0000 Subject: [PATCH 3/4] Reset .gitignore back to dev --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6051806de..4c38c1754 100644 --- a/.gitignore +++ b/.gitignore @@ -66,4 +66,3 @@ Sharpmake.VC.db # Desktop Services Store on MacOS **/.DS_Store -deploy From 64eb46597df926313d89df7c43762e7c1df58794 Mon Sep 17 00:00:00 2001 From: Jonathan Steyfkens Date: Sun, 6 Nov 2022 16:14:49 +0000 Subject: [PATCH 4/4] Fix builds --- samples/Sharpmake.Samples.sharpmake.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/Sharpmake.Samples.sharpmake.cs b/samples/Sharpmake.Samples.sharpmake.cs index 084fc8054..3e10faeb3 100644 --- a/samples/Sharpmake.Samples.sharpmake.cs +++ b/samples/Sharpmake.Samples.sharpmake.cs @@ -355,6 +355,7 @@ public PreBuildStepDependency() } } + [Generate] public class VcpkgProject : SampleProject { public VcpkgProject()