Skip to content

Commit

Permalink
MAJOR CHANGE to target/output names handling
Browse files Browse the repository at this point in the history
- This fixes the post build copies sharpmake generates for "Dll", they will now use the proper name
- Sharpmake now expects all of the "extension" variables to contain (or not) a leading '.' (dot) depending on the platform
- Deprecate conf.TargetFileExtension, if the user wants to change the extension, they need to change conf.OutputExtension instead
- TargetFileFullName is now read-only from the scripts, and will always be built from prefix + name + suffix
- TargetFilePrefix will be null by default, and set at resolve time if the user didn't override it in their script
  * if you want to change the prefix, for instance if you don't want "lib" on linux, set it to empty string
- Move GetOutputFileNamePrefix to the ConfigurationTasks instead of IPlatformVcxproj
- Ensure Resolve is only called once per Project
- TargetFileName will be set to the AssemblyName for CSharpProjects
- Remove the DefaultPlatformImplementation, we prefer to be explicit
  * Implement the interfaces in DotNetPlatform
- [XCode] The product_name will be the TargetFileName, not the full name
- Remove AddLibPrefix
- Use other variables holding the extensions in GetDefaultOutputExtension, as much as possible
- [Vcxproj] Convert the libs to relative before sorting them, this should fixes discrepancies
  => this would need to be made better and simpler
  • Loading branch information
belkiss committed Apr 20, 2021
1 parent eaab74c commit e4671da
Show file tree
Hide file tree
Showing 18 changed files with 241 additions and 292 deletions.
4 changes: 2 additions & 2 deletions Sharpmake.Generators/Apple/XCodeProj.Template.cs
Expand Up @@ -284,7 +284,7 @@ private static class Template
OBJROOT = ""[item.Configuration.IntermediatePath]"";
PRESERVE_DEAD_CODE_INITS_AND_TERMS = [item.Options.PreserveDeadCodeInitsAndTerms];
PRODUCT_BUNDLE_IDENTIFIER = ""[item.Options.ProductBundleIdentifier]"";
PRODUCT_NAME = ""[item.Configuration.TargetFileFullName]"";
PRODUCT_NAME = ""[item.Configuration.TargetFileName]"";
PROVISIONING_PROFILE_SPECIFIER = ""[item.Options.ProvisioningProfile]"";
VALID_ARCHS = ""[item.Options.ValidArchs]"";
SKIP_INSTALL = [item.Options.SkipInstall];
Expand Down Expand Up @@ -326,7 +326,7 @@ private static class Template
GCC_ENABLE_CPP_RTTI = [item.Options.RuntimeTypeInfo];
GCC_SYMBOLS_PRIVATE_EXTERN = [item.Options.PrivateSymbols];
INFOPLIST_FILE = ""[item.Options.InfoPListFile]"";
PRODUCT_NAME = ""[item.Configuration.TargetFileFullName]"";
PRODUCT_NAME = ""[item.Configuration.TargetFileName]"";
TEST_HOST = ""[testHost]"";
WRAPPER_EXTENSION = xctest;
};
Expand Down
34 changes: 4 additions & 30 deletions Sharpmake.Generators/Apple/XCodeProj.cs
Expand Up @@ -1260,39 +1260,13 @@ public ProjectOutputFile(string fullPath)
}

public ProjectOutputFile(Project.Configuration conf, string name = null)
: this(((conf.Output == Project.Configuration.OutputType.Lib) ? conf.TargetLibraryPath : conf.TargetPath) + FolderSeparator + GetFilePrefix(conf.Output) + conf.TargetFileFullName + GetFileExtension(conf))
: this(((conf.Output == Project.Configuration.OutputType.Lib) ? conf.TargetLibraryPath : conf.TargetPath) + FolderSeparator + conf.TargetFileFullNameWithExtension)
{
Name = name ?? conf.Project.Name + " " + conf.Name;
BuildableName = System.IO.Path.GetFileName(FullPath);
_conf = conf;
}

private static string GetFilePrefix(Project.Configuration.OutputType outputType)
{
return (outputType == Project.Configuration.OutputType.Lib || outputType == Project.Configuration.OutputType.Dll) ? "lib" : "";
}

public static string GetFileExtension(Project.Configuration conf)
{
switch (conf.Output)
{
case Project.Configuration.OutputType.Dll:
return ".dylib";
case Project.Configuration.OutputType.Lib:
return ".a";
case Project.Configuration.OutputType.Exe:
return ""; // Mac executable
case Project.Configuration.OutputType.IosApp:
return ".app";
case Project.Configuration.OutputType.IosTestBundle:
return ".xctest";
case Project.Configuration.OutputType.None:
return "";
default:
throw new NotSupportedException($"XCode generator doesn't handle {conf.Output}");
}
}

public override SourceTreeSetting SourceTreeValue { get { return SourceTreeSetting.BUILT_PRODUCTS_DIR; } }

public Project.Configuration.OutputType OutputType { get { return _conf.Output; } }
Expand Down Expand Up @@ -1835,12 +1809,12 @@ public override void GetAdditionalResolverParameters(ProjectItem item, Resolver
{
ProjectNativeTarget testHostTarget = testHostTargetDependency.NativeTarget;

// Each ProjectNativeTarget have a list of ProjectBuildConfiguration that wrap a Project.Configuration.
// Here we look for the Project.Configuration in the ProjectBuildConfiguration list of the test host target (app)
// Each ProjectNativeTarget have a list of ProjectBuildConfiguration that wrap a Project.Configuration.
// Here we look for the Project.Configuration in the ProjectBuildConfiguration list of the test host target (app)
// that match the unit tests bundle ProjectBuildConfiguration.
Project.Configuration testConfig = testHostTarget.ConfigurationList.Configurations.First(config => config.Configuration.Name == this.Configuration.Name).Configuration;

testHostParam = String.Format("$(BUILT_PRODUCTS_DIR)/{0}{1}{2}/{0}{1}", testHostTarget.Identifier, testConfig.TargetFileSuffix, ProjectOutputFile.GetFileExtension(testConfig));
testHostParam = String.Format("$(BUILT_PRODUCTS_DIR)/{0}{1}{2}/{0}{1}", testHostTarget.Identifier, testConfig.TargetFileSuffix, testConfig.Output);
}

resolverParameters.Add("testHost", testHostParam);
Expand Down
30 changes: 6 additions & 24 deletions Sharpmake.Generators/FastBuild/Bff.cs
Expand Up @@ -790,7 +790,7 @@ List<string> skipFiles
StringBuilder builderForceUsingFiles = new StringBuilder();
foreach (var fuConfig in conf.ForceUsingDependencies)
{
builderForceUsingFiles.AppendFormat(@" /FU""{0}.dll""", GetOutputFileName(fuConfig));
builderForceUsingFiles.AppendFormat(@" /FU""{0}.dll""", fuConfig.TargetFileFullName);
}
foreach (var f in conf.ForceUsingFiles.Union(conf.DependenciesForceUsingFiles))
{
Expand Down Expand Up @@ -1520,7 +1520,7 @@ private static OrderableStrings FillLibrariesOptions(BffGenerationContext contex

Strings ignoreSpecificLibraryNames = Options.GetStrings<Options.Vc.Linker.IgnoreSpecificLibraryNames>(context.Configuration);
ignoreSpecificLibraryNames.ToLower();
ignoreSpecificLibraryNames.InsertSuffix("." + platformVcxproj.StaticLibraryFileExtension, true);
ignoreSpecificLibraryNames.InsertSuffix(platformVcxproj.StaticLibraryFileExtension, true);

context.CommandLineOptions["AdditionalDependencies"] = FileGeneratorUtilities.RemoveLineTag;
context.CommandLineOptions["AdditionalLibraryDirectories"] = FileGeneratorUtilities.RemoveLineTag;
Expand Down Expand Up @@ -1592,14 +1592,16 @@ private static void SelectAdditionalLibraryDirectoriesOption(BffGenerationContex
Strings ignoreSpecificLibraryNames
)
{
var configurationTasks = PlatformRegistry.Get<Project.Configuration.IConfigurationTasks>(context.Configuration.Platform);

// TODO: really not ideal, refactor and move the properties we need from it someplace else
var platformVcxproj = PlatformRegistry.Query<IPlatformVcxproj>(context.Configuration.Platform);

string platformLibraryExtension = string.Empty;
string platformOutputLibraryExtension = string.Empty;
string platformPrefix = string.Empty;
platformVcxproj.SetupPlatformLibraryOptions(ref platformLibraryExtension, ref platformOutputLibraryExtension, ref platformPrefix);
string libPrefix = platformVcxproj.GetOutputFileNamePrefix(context, Project.Configuration.OutputType.Lib);
string libPrefix = configurationTasks.GetOutputFileNamePrefix(Project.Configuration.OutputType.Lib);

var additionalDependencies = new OrderableStrings();

Expand All @@ -1623,15 +1625,13 @@ Strings ignoreSpecificLibraryNames
// Ex: On clang we add -l (supposedly because the exact file is named lib<library>.a)
// - With a filename with a static or shared lib extension (eg. .a/.lib/.so), we shouldn't touch it as it's already set by the script.
string extension = Path.GetExtension(libraryFile).ToLower();
if (extension.StartsWith(".", StringComparison.Ordinal))
extension = extension.Substring(1);

// here we could also verify that the path is rooted
if (extension != platformVcxproj.StaticLibraryFileExtension && extension != platformVcxproj.SharedLibraryFileExtension)
{
libraryFile = libPrefix + libraryFile;
if (!string.IsNullOrEmpty(platformVcxproj.StaticLibraryFileExtension))
libraryFile += "." + platformVcxproj.StaticLibraryFileExtension;
libraryFile += platformVcxproj.StaticLibraryFileExtension;
}
libraryFile = platformPrefix + libraryFile + platformOutputLibraryExtension;

Expand Down Expand Up @@ -1891,24 +1891,6 @@ private static string FormatListPartForTag(List<string> items, int spaceLength,
return strBuilder.ToString();
}

private static string GetOutputFileName(Project.Configuration conf)
{
string targetNamePrefix = "";

if (conf.OutputExtension == "")
{
bool addLibPrefix = false;

if (conf.Output != Project.Configuration.OutputType.Exe)
addLibPrefix = PlatformRegistry.Get<IPlatformBff>(conf.Platform).AddLibPrefix(conf);

if (addLibPrefix)
targetNamePrefix = "lib";
}
string targetName = conf.Project is CSharpProject ? conf.TargetFileName : conf.TargetFileFullName;
return targetNamePrefix + targetName;
}

private static void Write(string value, TextWriter writer, Resolver resolver)
{
string resolvedValue = resolver.Resolve(value);
Expand Down
8 changes: 0 additions & 8 deletions Sharpmake.Generators/FastBuild/IPlatformBff.cs
Expand Up @@ -52,14 +52,6 @@ public interface IPlatformBff
/// </summary>
string CppConfigName(Configuration conf);

/// <summary>
/// Gets whether a library prefix (usually `lib`) is required on that platform when
/// building libraries.
/// </summary>
/// <param name="conf">The <see cref="Configuration"/> under which the check is requested.</param>
/// <returns>`true` if a prefix is required, `false` otherwise.</returns>
bool AddLibPrefix(Configuration conf);

void SelectPreprocessorDefinitionsBff(IBffGenerationContext context);

/// <summary>
Expand Down
19 changes: 6 additions & 13 deletions Sharpmake.Generators/Generic/Makefile.cs
Expand Up @@ -415,7 +415,7 @@ private void ValidateSolutionConfigurations(Solution solution, List<Solution.Con
switch (conf.Platform)
{
case Platform.linux:
conf.GeneratorSetGeneratedInformation("elf", "elf", "so", "pdb");
conf.GeneratorSetGeneratedInformation(".elf", ".elf", ".so", ".pdb");
break;
default:
break;
Expand Down Expand Up @@ -559,18 +559,18 @@ private Options.ExplicitOptions GenerateOptions(Project.Configuration conf, File
#region Linker

// OutputFile
options["OutputFile"] = FormatOutputFileName(conf).Replace(" ", @"\ ");
options["OutputFile"] = conf.TargetFileFullNameWithExtension.Replace(" ", @"\ ");

// DependenciesLibraryFiles
OrderableStrings dependenciesLibraryFiles = new OrderableStrings(conf.DependenciesLibraryFiles);
PathMakeUnix(dependenciesLibraryFiles);
dependenciesLibraryFiles.InsertPrefix("-l");
dependenciesLibraryFiles.InsertPrefix("-l:");
dependenciesLibraryFiles.Sort();
options["DependenciesLibraryFiles"] = dependenciesLibraryFiles.JoinStrings(" ");

// LibraryFiles
OrderableStrings libraryFiles = new OrderableStrings(conf.LibraryFiles);
libraryFiles.InsertPrefix("-l");
libraryFiles.InsertPrefix("-l:");
libraryFiles.Sort();
options["LibraryFiles"] = libraryFiles.JoinStrings(" ");

Expand All @@ -593,11 +593,11 @@ private Options.ExplicitOptions GenerateOptions(Project.Configuration conf, File
case Project.Configuration.OutputType.None: continue;
case Project.Configuration.OutputType.Lib:
case Project.Configuration.OutputType.DotNetClassLibrary:
deps.Add(Path.Combine(depConf.TargetLibraryPath, FormatOutputFileName(depConf)), depConf.TargetFileOrderNumber);
deps.Add(Path.Combine(depConf.TargetLibraryPath, depConf.TargetFileFullNameWithExtension), depConf.TargetFileOrderNumber);
break;
case Project.Configuration.OutputType.Dll:
default:
deps.Add(Path.Combine(depConf.TargetPath, FormatOutputFileName(depConf)), depConf.TargetFileOrderNumber);
deps.Add(Path.Combine(depConf.TargetPath, depConf.TargetFileFullNameWithExtension), depConf.TargetFileOrderNumber);
break;
}
}
Expand Down Expand Up @@ -695,13 +695,6 @@ private string GetOutputDirectory(Project.Configuration conf, FileInfo projectFi
return Util.PathGetRelative(projectFileInfo.DirectoryName, conf.TargetPath);
}

private static string FormatOutputFileName(Project.Configuration conf)
{
string outputExtension = !string.IsNullOrEmpty(conf.OutputExtension) ? "." + conf.OutputExtension : "";
string targetNamePrefix = (conf.Output == Project.Configuration.OutputType.Lib || conf.Output == Project.Configuration.OutputType.Dll) ? "lib" : "";
return (targetNamePrefix + conf.TargetFileFullName + outputExtension);
}

#endregion

#region Utils
Expand Down
2 changes: 1 addition & 1 deletion Sharpmake.Generators/VisualStudio/Csproj.cs
Expand Up @@ -1086,7 +1086,7 @@ List<string> skipFiles
configurationNameMapping[projectUniqueName] = conf;

// set generator information
conf.GeneratorSetGeneratedInformation("exe", "exe", "dll", "pdb");
conf.GeneratorSetGeneratedInformation(".exe", ".exe", ".dll", ".pdb");
}

string outputType;
Expand Down
2 changes: 1 addition & 1 deletion Sharpmake.Generators/VisualStudio/IPlatformVcxproj.cs
Expand Up @@ -59,7 +59,7 @@ public interface IPlatformVcxproj

IEnumerable<VariableAssignment> GetEnvironmentVariables(IGenerationContext context);

string GetOutputFileNamePrefix(IGenerationContext context, Project.Configuration.OutputType outputType);
// GetOutputFileNamePrefix is now in IConfigurationTasks

void SetupDeleteExtensionsOnCleanOptions(IGenerationContext context);
void SetupSdkOptions(IGenerationContext context);
Expand Down

0 comments on commit e4671da

Please sign in to comment.