Skip to content

Commit

Permalink
xcode : ensure only file with extension in SourceFilesCompileExtensio…
Browse files Browse the repository at this point in the history
…ns go into compile files
  • Loading branch information
yhuang-i authored and jspelletier committed Oct 26, 2023
1 parent 7ba24d2 commit b68063b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Sharpmake.Generators/Apple/XCodeProj.cs
Expand Up @@ -64,7 +64,7 @@ public XCodeGenerationContext(Builder builder, string projectPath, Project proje
}
}

private readonly HashSet<ProjectItem> _projectItems = new HashSet<ProjectItem>();
internal readonly HashSet<ProjectItem> _projectItems = new HashSet<ProjectItem>();

private ProjectFolder _mainGroup = null;
private ProjectFolder _productsGroup = null;
Expand All @@ -73,7 +73,7 @@ public XCodeGenerationContext(Builder builder, string projectPath, Project proje

private Dictionary<string, ProjectTarget> _nativeOrLegacyTargets = null;
private Dictionary<string, ProjectResourcesBuildPhase> _resourcesBuildPhases = null;
private Dictionary<string, ProjectSourcesBuildPhase> _sourcesBuildPhases = null;
internal Dictionary<string, ProjectSourcesBuildPhase> _sourcesBuildPhases = null;
private Dictionary<string, ProjectFrameworksBuildPhase> _frameworksBuildPhases = null;
private Dictionary<string, UniqueList<ProjectHeadersBuildPhase>> _headersBuildPhases = null;
private Dictionary<string, UniqueList<ProjectCopyFilesBuildPhase>> _copyFilesPreBuildPhases = null;
Expand Down Expand Up @@ -852,12 +852,12 @@ private bool IsBuildExcludedForAllConfigurations(List<Project.Configuration> con
return true;
}

private void PrepareSourceFiles(string xCodeTargetName, IEnumerable<string> sourceFiles, Project project, Project.Configuration configuration, string workspacePath = null)
internal void PrepareSourceFiles(string xCodeTargetName, IEnumerable<string> sourceFiles, Project project, Project.Configuration configuration, string workspacePath = null)
{
foreach (string file in sourceFiles)
{
bool build = !configuration.ResolvedSourceFilesBuildExclude.Contains(file);
string extension = Path.GetExtension(file);
bool build = !configuration.ResolvedSourceFilesBuildExclude.Contains(file) && project.SourceFilesCompileExtensions.Contains(extension);

bool alreadyPresent;
ProjectFileSystemItem item = AddInFileSystem(file, out alreadyPresent, workspacePath, true);
Expand Down Expand Up @@ -959,7 +959,7 @@ private void AddAllFiles(string fullPath, Strings outputFiles)
}
}

private void SetRootGroup(Project project, Project.Configuration configuration)
internal void SetRootGroup(Project project, Project.Configuration configuration)
{
_mainGroup = new ProjectFolder(project.GetType().Name, true);

Expand Down Expand Up @@ -1859,7 +1859,7 @@ public ProjectBuildFile(ProjectFileBase file, string settings = @"")
public ProjectFileBase File { get; }
}

private abstract class ProjectBuildPhase : ProjectItem
internal abstract class ProjectBuildPhase : ProjectItem
{
public ProjectBuildPhase(ItemSection section, string phaseName, uint buildActionMask)
: base(section, phaseName)
Expand Down Expand Up @@ -1902,7 +1902,7 @@ public ProjectResourcesBuildPhase(string name, uint buildActionMask)
}
}

private class ProjectSourcesBuildPhase : ProjectBuildPhase
internal class ProjectSourcesBuildPhase : ProjectBuildPhase
{
public ProjectSourcesBuildPhase(uint buildActionMask)
: base(ItemSection.PBXSourcesBuildPhase, "Sources", buildActionMask)
Expand Down
29 changes: 29 additions & 0 deletions Sharpmake.UnitTests/TestXcodeProjectGenerator.cs
@@ -1,7 +1,11 @@
// Copyright (c) Ubisoft. All Rights Reserved.
// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Sharpmake.Generators.Apple;
using static Sharpmake.Generators.Apple.XCodeProj;

namespace Sharpmake.UnitTests
Expand All @@ -21,5 +25,30 @@ public void TestProjectBuildFile()

Assert.IsFalse(projectBuildFile1.Equals(projectBuildFile2));
}

[Test]
public void TestUncompilableNotInCompileSources()
{
string xCodeTargetName = "test";
var srcRoot = Directory.GetCurrentDirectory();
List<string> sourceFiles = new List<string> { Path.Combine(srcRoot, "test.sc") };
Project project = new Project();
Project.Configuration configuration = new Project.Configuration();

configuration.ProjectFullFileNameWithExtension = "./test/test.xcodeproj";

var xcodePrj = new XCodeProj();

project.SourceRootPath = srcRoot;
xcodePrj._sourcesBuildPhases = new Dictionary<string, ProjectSourcesBuildPhase>();
var projectSourcesBuildPhase = new ProjectSourcesBuildPhase(xCodeTargetName, 2147483647);
xcodePrj._projectItems.Add(projectSourcesBuildPhase);
xcodePrj._sourcesBuildPhases.Add(xCodeTargetName, projectSourcesBuildPhase);
xcodePrj.SetRootGroup(project, configuration);
xcodePrj.PrepareSourceFiles(xCodeTargetName, sourceFiles, project, configuration);
var compileSources = xcodePrj._projectItems.Where(item => item is ProjectBuildFile);

Assert.IsTrue(compileSources.Count() == 0);
}
}
}

0 comments on commit b68063b

Please sign in to comment.