[build] Add support for worktree checkouts (#19240)

Was messing around with worktrees but our repo failed to build due to
not identifying the proper git directory.

Fixes #18276
This commit is contained in:
Haritha Mohan 2023-10-19 09:22:37 -07:00 коммит произвёл GitHub
Родитель 1cbca67c84
Коммит da08b89077
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 22 добавлений и 13 удалений

Просмотреть файл

@ -68,6 +68,15 @@ CURRENT_BRANCH_SED_ESCAPED:=$(subst |,\|,$(subst &,\&,$(subst $$,\$$,$(subst /,\
# So here we replace all non-alphanumeric characters in the branch name with a dash.
CURRENT_BRANCH_ALPHANUMERIC:=$(shell export LANG=C; printf "%s" "$(CURRENT_BRANCH)" | tr -c '[a-zA-Z0-9-]' '-')
# Set proper path for git directory
# If the repo is checked out as a worktree, the default .git/ does not exist,
# instead there is a .git file containing the path to the correct .git/
GIT_DIRECTORY:=$(TOP)/.git
ALTERNATIVE_GIT:=$(shell sed -n 's/^ *gitdir: //p' $(GIT_DIRECTORY))
ifneq ($(ALTERNATIVE_GIT),)
GIT_DIRECTORY:=$(ALTERNATIVE_GIT)
endif
# Get the current hash
CURRENT_HASH:=$(shell git log -1 --pretty=%h)
CURRENT_HASH_LONG:=$(shell git log -1 --pretty=%H)

Просмотреть файл

@ -69,7 +69,7 @@ endif
all-local:: global.json
# This tells NuGet to use the exact same dotnet version we've configured in Make.config
global.json: $(TOP)/dotnet.config Makefile $(TOP)/.git/HEAD $(TOP)/.git/index
global.json: $(TOP)/dotnet.config Makefile $(GIT_DIRECTORY)/HEAD $(GIT_DIRECTORY)/index
$(Q_GEN) \
printf "{\n" > $@; \
printf " \"sdk\": {\n \"version\": \"$(DOTNET_VERSION)\"\n }\n" >> $@; \

Просмотреть файл

@ -122,7 +122,7 @@ ifneq ($(TRACKING_DOTNET_RUNTIME_SEPARATELY),)
$(Q) touch $@
endif
package-download/all-package-references.csproj: $(TOP)/.git/HEAD $(TOP)/.git/index ./create-csproj-for-all-packagereferences.sh
package-download/all-package-references.csproj: $(GIT_DIRECTORY)/HEAD $(GIT_DIRECTORY)/index ./create-csproj-for-all-packagereferences.sh
$(Q_GEN) ./create-csproj-for-all-packagereferences.sh --output "$(abspath $@.tmp)" $(if $(V),-v,)
$(Q) mv "$@.tmp" "$@"
@ -747,7 +747,7 @@ $(MAC_DESTDIR)$(MAC_FRAMEWORK_DIR)/Versions/Current: | $(MAC_DESTDIR)$(MAC_FRAME
$(MAC_DESTDIR)$(MAC_FRAMEWORK_DIR)/Commands:
$(Q_LN) ln -hfs $(MAC_TARGETDIR)/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bin $@
$(MAC_DESTDIR)/$(MAC_FRAMEWORK_CURRENT_DIR)/buildinfo: $(TOP)/Make.config.inc $(TOP)/.git/index | $(MAC_DESTDIR)/$(MAC_FRAMEWORK_CURRENT_DIR)
$(MAC_DESTDIR)/$(MAC_FRAMEWORK_CURRENT_DIR)/buildinfo: $(TOP)/Make.config.inc $(GIT_DIRECTORY)/index | $(MAC_DESTDIR)/$(MAC_FRAMEWORK_CURRENT_DIR)
$(Q_GEN) echo "Version: $(MAC_PACKAGE_VERSION)" > $@
$(Q) echo "Hash: $(shell git log --oneline -1 --pretty=%h)" >> $@
$(Q) echo "Branch: $(CURRENT_BRANCH)" >> $@
@ -849,7 +849,7 @@ IOS_COMMON_TARGETS = \
$(IOS_DESTDIR)/Library/Frameworks/Xamarin.iOS.framework/Versions/Current: | $(IOS_DESTDIR)/Library/Frameworks/Xamarin.iOS.framework/Versions
$(Q_LN) ln -hfs $(IOS_INSTALL_VERSION) $@
$(IOS_DESTDIR)/$(MONOTOUCH_PREFIX)/buildinfo: $(TOP)/Make.config.inc $(TOP)/.git/index | $(IOS_DESTDIR)/$(MONOTOUCH_PREFIX)
$(IOS_DESTDIR)/$(MONOTOUCH_PREFIX)/buildinfo: $(TOP)/Make.config.inc $(GIT_DIRECTORY)/index | $(IOS_DESTDIR)/$(MONOTOUCH_PREFIX)
$(Q_GEN) echo "Version: $(IOS_PACKAGE_VERSION)" > $@
$(Q) echo "Hash: $(shell git log --oneline -1 --pretty=%h)" >> $@
$(Q) echo "Branch: $(CURRENT_BRANCH)" >> $@

Просмотреть файл

@ -107,7 +107,7 @@ endef
$(foreach platform,$(DOTNET_WINDOWS_PLATFORMS),$(eval $(call CopyTargetsWindows,$(platform))))
define VersionsTemplate
targets/Microsoft.$(1).Sdk.Versions.props: targets/Microsoft.Sdk.Versions.template.props Makefile $(TOP)/Make.config.inc $(TOP)/.git/HEAD $(TOP)/.git/index
targets/Microsoft.$(1).Sdk.Versions.props: targets/Microsoft.Sdk.Versions.template.props Makefile $(TOP)/Make.config.inc $(GIT_DIRECTORY)/HEAD $(GIT_DIRECTORY)/index
$$(Q_GEN) sed \
-e "s/@PLATFORM@/$(1)/g" \
-e "s/@NUGET_VERSION_NO_METADATA@/$$($(2)_NUGET_VERSION_NO_METADATA)/g" \
@ -167,12 +167,12 @@ endef
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call SupportedTargetPlatforms,$(platform))))
define WorkloadTargets
Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.json: Makefile $(TOP)/Make.config.inc $(TOP)/.git/HEAD $(TOP)/.git/index Makefile generate-workloadmanifest-json.csharp | Workloads/Microsoft.NET.Sdk.$(1)
Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.json: Makefile $(TOP)/Make.config.inc $(GIT_DIRECTORY)/HEAD $(GIT_DIRECTORY)/index Makefile generate-workloadmanifest-json.csharp | Workloads/Microsoft.NET.Sdk.$(1)
$$(Q) rm -f $$@.tmp
$$(Q_GEN) ./generate-workloadmanifest-json.csharp "$(1)" "$(3)" "$(5)" "$$(DOTNET_$(4)_RUNTIME_IDENTIFIERS)" "$$@.tmp" "$$(DOTNET_WINDOWS_PLATFORMS)"
$$(Q) mv $$@.tmp $$@
Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.targets: Workloads/WorkloadManifest.$(1).template.targets Makefile $(TOP)/Make.config.inc $(TOP)/.git/HEAD $(TOP)/.git/index | Workloads/Microsoft.NET.Sdk.$(1)
Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.targets: Workloads/WorkloadManifest.$(1).template.targets Makefile $(TOP)/Make.config.inc $(GIT_DIRECTORY)/HEAD $(GIT_DIRECTORY)/index | Workloads/Microsoft.NET.Sdk.$(1)
$$(Q) rm -f $$@.tmp
$$(Q_GEN) sed \
-e "s/@NUGET_VERSION_NO_METADATA@/$3/g" \

Просмотреть файл

@ -52,7 +52,7 @@ else
endif
print-$(1)::
@printf "*** %-16s %-45s %s (%s)\n" "$(1)" "$(shell git config submodule.external/$(1).url)" "$(NEEDED_$(2)_VERSION)" "$(shell git config -f $(abspath $(TOP)/.gitmodules) submodule.external/$(1).branch)"
@printf "*** %-16s %-45s %s (%s)\n" "$(1)" "$(shell git config submodule.external/$(1).url)" "$(NEEDED_$(2)_VERSION)" "$(shell git config -f $(abspath $(GIT_DIRECTORY)modules) submodule.external/$(1).branch)"
.PHONY: check-$(1) reset-$(1) print-$(1)

Просмотреть файл

@ -71,7 +71,7 @@ bindings-generated.m: bindings-generator.exe
app-main.m watchextension-main.m tvextension-main.m: extension-main.m
$(Q_LN) ln -fs $< $@
product.h: product.in.h Makefile $(TOP)/.git/index
product.h: product.in.h Makefile $(GIT_DIRECTORY)/index
$(Q) sed -e 's/@PRODUCT_HASH@/$(CURRENT_HASH_LONG)/' $< > $@.tmp
$(Q) mv $@.tmp $@
#

Просмотреть файл

@ -730,7 +730,7 @@ $(WATCH_BUILD_DIR)/Constants.cs: $(TOP)/src/Constants.watch.cs.in Makefile $(TOP
-e "s/@WATCH_SDK_VERSION@/$(WATCH_SDK_VERSION)/g" \
$< > $@
$(WATCH_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/Make.config $(TOP)/.git/HEAD | $(WATCH_BUILD_DIR)
$(WATCH_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/Make.config $(GIT_DIRECTORY)/HEAD | $(WATCH_BUILD_DIR)
$(call Q_PROF_GEN,watch) sed \
-e 's|@PRODUCT_NAME@|Xamarin.WatchOS|g' \
-e 's|@PACKAGE_HEAD_REV@|$(PACKAGE_HEAD_REV)|g' \
@ -933,7 +933,7 @@ $(TVOS_BUILD_DIR)/Constants.cs: $(TOP)/src/Constants.tvos.cs.in Makefile $(TOP)/
-e "s/@TVOS_SDK_VERSION@/$(TVOS_SDK_VERSION)/g" \
$< > $@
$(TVOS_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/Make.config $(TOP)/.git/HEAD | $(TVOS_BUILD_DIR)
$(TVOS_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/Make.config $(GIT_DIRECTORY)/HEAD | $(TVOS_BUILD_DIR)
$(call Q_PROF_GEN,tvos) sed \
-e 's|@PRODUCT_NAME@|Xamarin.TVOS|g' \
-e 's|@PACKAGE_HEAD_REV@|$(PACKAGE_HEAD_REV)|g' \
@ -1099,7 +1099,7 @@ $(MACCATALYST_BUILD_DIR)/Constants.cs: $(TOP)/src/Constants.maccatalyst.cs.in Ma
-e "s/@MACCATALYST_SDK_VERSION@/$(MACCATALYST_SDK_VERSION)/g" \
$< > $@
$(MACCATALYST_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/Make.config $(TOP)/.git/HEAD | $(MACCATALYST_BUILD_DIR)
$(MACCATALYST_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/Make.config $(GIT_DIRECTORY)/HEAD | $(MACCATALYST_BUILD_DIR)
$(call Q_PROF_GEN,maccatalyst) sed \
-e 's|@PRODUCT_NAME@|Xamarin.MacCatalyst|g' \
-e 's|@PACKAGE_HEAD_REV@|$(PACKAGE_HEAD_REV)|g' \

Просмотреть файл

@ -60,7 +60,7 @@
$(Q) if ! diff $@ $@.tmp >/dev/null; then $(CP) $@.tmp $@; git diff "$@"; echo "The file $(TOP)/tools/common/SdkVersions.cs has been automatically re-generated; please commit the changes."; exit 1; fi
$(Q) touch $@
../common/ProductConstants.cs: ../common/ProductConstants.in.cs Makefile $(TOP)/Make.config $(TOP)/.git/index
../common/ProductConstants.cs: ../common/ProductConstants.in.cs Makefile $(TOP)/Make.config $(GIT_DIRECTORY)/index
$(Q_GEN) sed \
-e "s/@IOS_VERSION@/$(IOS_PACKAGE_VERSION_MAJOR).$(IOS_PACKAGE_VERSION_MINOR).$(IOS_PACKAGE_VERSION_REV)/g" \
-e "s/@TVOS_VERSION@/$(IOS_PACKAGE_VERSION_MAJOR).$(IOS_PACKAGE_VERSION_MINOR).$(IOS_PACKAGE_VERSION_REV)/g" \