From 604ddd2286d1e3bd4b08e5d43fce749b4776cb66 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Tue, 11 Nov 2025 13:29:42 +0100 Subject: [PATCH 1/4] use project-relative path --- autocodesign/projectmanager/projecthelper.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/autocodesign/projectmanager/projecthelper.go b/autocodesign/projectmanager/projecthelper.go index 7a3baa01..4690e9ce 100644 --- a/autocodesign/projectmanager/projecthelper.go +++ b/autocodesign/projectmanager/projecthelper.go @@ -247,7 +247,9 @@ func (p *ProjectHelper) fetchBuildSettings(targetName, conf string) ([]buildSett var settings serialized.Object settings, wsErr = p.XcWorkspace.SchemeBuildSettings(targetName, conf, p.additionalXcodebuildOptions...) if wsErr == nil { - settingsList = append(settingsList, buildSettings{settings: settings, basePath: p.XcWorkspace.Path}) + // Settings like INFOPLIST_FILE and CODE_SIGN_ENTITLEMENTS are project-relative + // https://developer.apple.com/documentation/xcode/build-settings-reference#Infoplist-File + settingsList = append(settingsList, buildSettings{settings: settings, basePath: p.XcProj.Path}) if !p.isCompatMode { // Fall back to project if workspace failed or compatibility mode is on return settingsList, nil } From 298a7590fc9ea9137559e51e810bd294a095053a Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Tue, 11 Nov 2025 15:21:32 +0100 Subject: [PATCH 2/4] Removed buildSettings type, as we always use project-relative base path for build settings --- autocodesign/projectmanager/projecthelper.go | 62 +++++++++----------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/autocodesign/projectmanager/projecthelper.go b/autocodesign/projectmanager/projecthelper.go index 4690e9ce..adc66fb0 100644 --- a/autocodesign/projectmanager/projecthelper.go +++ b/autocodesign/projectmanager/projecthelper.go @@ -37,11 +37,6 @@ type buildSettingsCacheKey struct { configuration string } -type buildSettings struct { - settings serialized.Object - basePath string -} - // ProjectHelper ... type ProjectHelper struct { logger log.Logger @@ -55,7 +50,7 @@ type ProjectHelper struct { isCompatMode bool // Buildsettings is an array as it can contain both workspace and project build settings in that order - buildSettingsCache map[buildSettingsCacheKey][]buildSettings + buildSettingsCache map[buildSettingsCacheKey][]serialized.Object } // NewProjectHelper checks the provided project or workspace and generate a ProjectHelper with the provided scheme and configuration @@ -240,8 +235,8 @@ func (p *ProjectHelper) targetTeamID(targetName, config string) (string, error) return devTeam, err } -func (p *ProjectHelper) fetchBuildSettings(targetName, conf string) ([]buildSettings, error) { - var settingsList []buildSettings +func (p *ProjectHelper) fetchBuildSettings(targetName, conf string) ([]serialized.Object, error) { + var settingsList []serialized.Object var wsErr error if p.XcWorkspace != nil { // workspace available var settings serialized.Object @@ -249,7 +244,7 @@ func (p *ProjectHelper) fetchBuildSettings(targetName, conf string) ([]buildSett if wsErr == nil { // Settings like INFOPLIST_FILE and CODE_SIGN_ENTITLEMENTS are project-relative // https://developer.apple.com/documentation/xcode/build-settings-reference#Infoplist-File - settingsList = append(settingsList, buildSettings{settings: settings, basePath: p.XcProj.Path}) + settingsList = append(settingsList, settings) if !p.isCompatMode { // Fall back to project if workspace failed or compatibility mode is on return settingsList, nil } @@ -263,7 +258,7 @@ func (p *ProjectHelper) fetchBuildSettings(targetName, conf string) ([]buildSett projectSettings, projectErr := p.XcProj.TargetBuildSettings(targetName, conf, p.additionalXcodebuildOptions...) if projectErr == nil { - settingsList = append(settingsList, buildSettings{settings: projectSettings, basePath: p.XcProj.Path}) + settingsList = append(settingsList, projectSettings) return settingsList, nil } @@ -277,7 +272,7 @@ func (p *ProjectHelper) fetchBuildSettings(targetName, conf string) ([]buildSett return settingsList, projectErr } -func (p *ProjectHelper) cachedBuildSettings(targetName, conf string) ([]buildSettings, error) { +func (p *ProjectHelper) cachedBuildSettings(targetName, conf string) ([]serialized.Object, error) { key := buildSettingsCacheKey{targetName: targetName, configuration: conf} settings, ok := p.buildSettingsCache[key] if ok { @@ -291,7 +286,7 @@ func (p *ProjectHelper) cachedBuildSettings(targetName, conf string) ([]buildSet } if p.buildSettingsCache == nil { - p.buildSettingsCache = map[buildSettingsCacheKey][]buildSettings{} + p.buildSettingsCache = map[buildSettingsCacheKey][]serialized.Object{} } p.buildSettingsCache[key] = settingsList @@ -305,13 +300,13 @@ func (p *ProjectHelper) targetBuildSettings(targetName, conf string) (serialized } if len(settingsList) == 1 { - return settingsList[0].settings, nil + return settingsList[0], nil } p.logger.Debugf("buildSettings: Workspace target build settings: %+v", settingsList[0]) p.logger.Debugf("buildSettings: Project target build settings: %+v", settingsList[1]) p.logger.Debugf("buildSettings: Multiple build settings found for target (%s), returning the project one", targetName) - return settingsList[1].settings, nil + return settingsList[1], nil } func (p *ProjectHelper) buildSettingForKey(targetName, conf string, key string) (string, error) { @@ -320,8 +315,8 @@ func (p *ProjectHelper) buildSettingForKey(targetName, conf string, key string) return "", err } - wsSettings := settingsList[0].settings - wsValue, err := wsSettings.String(key) + settings := settingsList[0] // workspace setting if available, project otherwise + wsValue, err := settings.String(key) if err != nil { return wsValue, err } @@ -330,7 +325,7 @@ func (p *ProjectHelper) buildSettingForKey(targetName, conf string, key string) return wsValue, nil } - projectSettings := settingsList[1].settings + projectSettings := settingsList[1] projectValue, err := projectSettings.String(key) if err != nil { p.logger.Errorf("buildSettings: Failed to fetch project build setting for key (%s): %s", key, err) @@ -355,38 +350,39 @@ func (p *ProjectHelper) buildSettingPathForKey(targetName, conf string, key stri return "", err } - wsSettings := settingsList[0] - wsValue, err := wsSettings.settings.String(key) + settings := settingsList[0] + pathValue, err := settings.String(key) if err != nil { - return wsValue, err + return pathValue, err } - if pathutil.IsRelativePath(wsValue) { - wsValue = filepath.Join(filepath.Dir(wsSettings.basePath), wsValue) + projectBasePath := p.XcProj.Path + if pathutil.IsRelativePath(pathValue) { + pathValue = filepath.Join(filepath.Dir(projectBasePath), pathValue) } if len(settingsList) == 1 { - return wsValue, nil + return pathValue, nil } projectSettings := settingsList[1] - projectValue, err := projectSettings.settings.String(key) + projectPathValue, err := projectSettings.String(key) if err != nil { - return projectValue, err + return projectPathValue, err } - if pathutil.IsRelativePath(projectValue) { - projectValue = filepath.Join(filepath.Dir(projectSettings.basePath), projectValue) + if pathutil.IsRelativePath(projectPathValue) { + projectPathValue = filepath.Join(filepath.Dir(projectBasePath), projectPathValue) } - if projectValue != wsValue { - p.logger.Errorf("buildSettings: Conflicting paths for build setting %s: '%s' (workspace) vs '%s' (project)", key, wsValue, projectValue) - p.logger.Printf("buildSettings: Returning project path for key (%s): %s", key, projectValue) - return projectValue, nil + if projectPathValue != pathValue { + p.logger.Errorf("buildSettings: Conflicting paths for build setting %s: '%s' (workspace) vs '%s' (project)", key, pathValue, projectPathValue) + p.logger.Printf("buildSettings: Returning project path for key (%s): %s", key, projectPathValue) + return projectPathValue, nil } - p.logger.Debugf("buildSettings: Matching paths for workspace and project build setting %s: '%s'", key, wsValue) - return wsValue, nil + p.logger.Debugf("buildSettings: Matching paths for workspace and project build setting %s: '%s'", key, pathValue) + return pathValue, nil } // TargetBundleID returns the target bundle ID From 90b463a2d23519852734605846f21bff4a61c771 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Tue, 11 Nov 2025 15:25:05 +0100 Subject: [PATCH 3/4] Better naming --- autocodesign/projectmanager/projecthelper.go | 54 ++++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/autocodesign/projectmanager/projecthelper.go b/autocodesign/projectmanager/projecthelper.go index adc66fb0..5bec6851 100644 --- a/autocodesign/projectmanager/projecthelper.go +++ b/autocodesign/projectmanager/projecthelper.go @@ -316,32 +316,32 @@ func (p *ProjectHelper) buildSettingForKey(targetName, conf string, key string) } settings := settingsList[0] // workspace setting if available, project otherwise - wsValue, err := settings.String(key) + settingValue, err := settings.String(key) if err != nil { - return wsValue, err + return settingValue, err } if len(settingsList) == 1 { - return wsValue, nil + return settingValue, nil } projectSettings := settingsList[1] - projectValue, err := projectSettings.String(key) + projectSettingValue, err := projectSettings.String(key) if err != nil { p.logger.Errorf("buildSettings: Failed to fetch project build setting for key (%s): %s", key, err) - p.logger.Printf("buildSettings: Returning workspace value for key (%s): %s", key, wsValue) - return wsValue, nil + p.logger.Printf("buildSettings: Returning workspace value for key (%s): %s", key, settingValue) + return settingValue, nil } - if projectValue != wsValue { - p.logger.Errorf("buildSettings: Conflicting values for build setting %s: '%s' (workspace) vs '%s' (project)", key, wsValue, projectValue) + if projectSettingValue != settingValue { + p.logger.Errorf("buildSettings: Conflicting values for build setting %s: '%s' (workspace) vs '%s' (project)", key, settingValue, projectSettingValue) // Return alternate value to be consistent with old project based target build setting fetch - p.logger.Printf("buildSettings: Returning project value for key (%s): %s", key, projectValue) - return projectValue, nil + p.logger.Printf("buildSettings: Returning project value for key (%s): %s", key, projectSettingValue) + return projectSettingValue, nil } - p.logger.Debugf("buildSettings: Matching values for workspace and project build setting %s: '%s'", key, wsValue) + p.logger.Debugf("buildSettings: Matching values for workspace and project build setting %s: '%s'", key, settingValue) - return wsValue, err + return settingValue, err } func (p *ProjectHelper) buildSettingPathForKey(targetName, conf string, key string) (string, error) { @@ -351,38 +351,38 @@ func (p *ProjectHelper) buildSettingPathForKey(targetName, conf string, key stri } settings := settingsList[0] - pathValue, err := settings.String(key) + settingValue, err := settings.String(key) if err != nil { - return pathValue, err + return settingValue, err } projectBasePath := p.XcProj.Path - if pathutil.IsRelativePath(pathValue) { - pathValue = filepath.Join(filepath.Dir(projectBasePath), pathValue) + if pathutil.IsRelativePath(settingValue) { + settingValue = filepath.Join(filepath.Dir(projectBasePath), settingValue) } if len(settingsList) == 1 { - return pathValue, nil + return settingValue, nil } projectSettings := settingsList[1] - projectPathValue, err := projectSettings.String(key) + projectSettingValue, err := projectSettings.String(key) if err != nil { - return projectPathValue, err + return projectSettingValue, err } - if pathutil.IsRelativePath(projectPathValue) { - projectPathValue = filepath.Join(filepath.Dir(projectBasePath), projectPathValue) + if pathutil.IsRelativePath(projectSettingValue) { + projectSettingValue = filepath.Join(filepath.Dir(projectBasePath), projectSettingValue) } - if projectPathValue != pathValue { - p.logger.Errorf("buildSettings: Conflicting paths for build setting %s: '%s' (workspace) vs '%s' (project)", key, pathValue, projectPathValue) - p.logger.Printf("buildSettings: Returning project path for key (%s): %s", key, projectPathValue) - return projectPathValue, nil + if projectSettingValue != settingValue { + p.logger.Errorf("buildSettings: Conflicting paths for build setting %s: '%s' (workspace) vs '%s' (project)", key, settingValue, projectSettingValue) + p.logger.Printf("buildSettings: Returning project path for key (%s): %s", key, projectSettingValue) + return projectSettingValue, nil } - p.logger.Debugf("buildSettings: Matching paths for workspace and project build setting %s: '%s'", key, pathValue) - return pathValue, nil + p.logger.Debugf("buildSettings: Matching paths for workspace and project build setting %s: '%s'", key, settingValue) + return settingValue, nil } // TargetBundleID returns the target bundle ID From 54759d644025e155d3926d09051aaa97d9136346 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Tue, 11 Nov 2025 15:26:46 +0100 Subject: [PATCH 4/4] Test fix --- autocodesign/projectmanager/projecthelper_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autocodesign/projectmanager/projecthelper_test.go b/autocodesign/projectmanager/projecthelper_test.go index 2b5bdb8c..782a8e28 100644 --- a/autocodesign/projectmanager/projecthelper_test.go +++ b/autocodesign/projectmanager/projecthelper_test.go @@ -9,6 +9,7 @@ import ( "github.com/bitrise-io/go-utils/pathutil" "github.com/bitrise-io/go-utils/v2/log" "github.com/bitrise-io/go-xcode/v2/autocodesign" + "github.com/bitrise-io/go-xcode/xcodeproject/serialized" "github.com/bitrise-io/go-xcode/xcodeproject/xcodeproj" "github.com/stretchr/testify/require" ) @@ -117,7 +118,7 @@ func TestProjectHelper_ProjectTeamID_withouthTargetAttributes(t *testing.T) { logger: logger, MainTarget: xcodeproj.Target{Name: "AppTarget"}, // bypass calling xcodebuild -showBuildSettings - buildSettingsCache: map[buildSettingsCacheKey][]buildSettings{{targetName: "AppTarget", configuration: "Debug"}: {}}, + buildSettingsCache: map[buildSettingsCacheKey][]serialized.Object{{targetName: "AppTarget", configuration: "Debug"}: {}}, // project withouth TargetAttributes XcProj: xcodeproj.XcodeProj{Proj: xcodeproj.Proj{Attributes: xcodeproj.ProjectAtributes{TargetAttributes: nil}}}, }