Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context.gitInformation is stale in incremental builds #8202

Open
1 task done
dimitribouniol opened this issue Jan 7, 2025 · 0 comments
Open
1 task done

Context.gitInformation is stale in incremental builds #8202

dimitribouniol opened this issue Jan 7, 2025 · 0 comments
Labels

Comments

@dimitribouniol
Copy link

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

When using Context.gitInformation to inject the git commit version, incremental builds will not be updated appropriately. Additionally, swift package dump-package will continue to dump a cached version of the git information, and resetting the build state using tools like swift package clean has no effect. Only modifications to Package.swift seem to have an effect, though such modifications change the git information by their very nature, so cannot be relied upon. Changing the file back to a previous state, even with an updated modification date results in a previously cached value being used.

Expected behavior

Every build will check the git state so the correct define is written to.

Actual behavior

The git information is frozen in time until Package.swift is modified.

Steps to reproduce

First, use the gitInformation to inject a define into a C module:

// Package.swift
        .target(
            name: "InternalConstants",
            cSettings: [
                .define("_GIT_VERSION", to: Constants.currentGITVersion)
            ],
            cxxSettings: [
                .define("_GIT_VERSION", to: Constants.currentGITVersion)
            ]
        ),

...
enum Constants {
    static let currentGITVersion: String = {
        if let git = Context.gitInformation {
            #""\#(git.currentTag ?? "HEAD") - \#(git.currentCommit.prefix(7))\#(git.hasUncommittedChanges ? " (modified)" : "")""#
        } else {
            #""Unknown Version""#
        }
    }()
}
// InternalConstants/include/Defines.h
#if !defined(DEFINES_H)
#define DEFINES_H

_Pragma("clang assume_nonnull begin")
extern const char *const GITVERSION;
_Pragma("clang assume_nonnull end")

#endif // DEFINES_H
#import "include/Defines.h"

const char *const GITVERSION = _GIT_VERSION;

Then, build with swift build. Only the first build of the first checkout will have valid gitInformation, making the information not-too-helpful 😔

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.0
Darwin ---- 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:14 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8103 arm64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant