Skip to content

Commit b3c7b28

Browse files
committed
8298459: Fix msys2 linking and handling out of tree build directory for source zip creation
Reviewed-by: mdoerr Backport-of: d624debe23f60d778d7be43f28d06e9454057217
1 parent 604dd4d commit b3c7b28

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

make/ZipSource.gmk

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,7 @@ include JavaCompilation.gmk
3131
include Modules.gmk
3232

3333
SRC_ZIP_WORK_DIR := $(SUPPORT_OUTPUTDIR)/src
34+
$(if $(filter $(TOPDIR)/%, $(SUPPORT_OUTPUTDIR)), $(eval SRC_ZIP_BASE := $(TOPDIR)), $(eval SRC_ZIP_BASE := $(SUPPORT_OUTPUTDIR)))
3435

3536
# Hook to include the corresponding custom file, if present.
3637
$(eval $(call IncludeCustomExtension, ZipSource.gmk))
@@ -51,10 +52,10 @@ ALL_MODULES := $(FindAllModules)
5152
# again to create src.zip.
5253
$(foreach m, $(ALL_MODULES), \
5354
$(foreach d, $(call FindModuleSrcDirs, $m) $(call ExtraSrcDirs, $m), \
54-
$(eval $d_TARGET := $(SRC_ZIP_WORK_DIR)/$(patsubst $(TOPDIR)/%,%,$d)/$m) \
55+
$(eval $d_TARGET := $(SRC_ZIP_WORK_DIR)/$(patsubst $(TOPDIR)/%,%,$(patsubst $(SUPPORT_OUTPUTDIR)/%,%,$d))/$m) \
5556
$(if $(SRC_GENERATED), , \
5657
$(eval $$($d_TARGET): $d ; \
57-
$$(if $(filter $(TOPDIR)/%, $d), $$(link-file-relative), $$(link-file-absolute)) \
58+
$$(if $(filter $(SRC_ZIP_BASE)/%, $d), $$(link-file-relative), $$(link-file-absolute)) \
5859
) \
5960
) \
6061
$(eval SRC_ZIP_SRCS += $$($d_TARGET)) \

make/common/MakeBase.gmk

+23-4
Original file line numberDiff line numberDiff line change
@@ -626,17 +626,36 @@ RelativePath = \
626626
# There are two versions, either creating a relative or an absolute link. Be
627627
# careful when using this on Windows since the symlink created is only valid in
628628
# the unix emulation environment.
629-
define link-file-relative
629+
# In msys2 we use mklink /J because its ln would perform a deep copy of the target.
630+
# This inhibits performance and can lead to issues with long paths. With mklink /J
631+
# relative linking does not work, so we handle the link as absolute path.
632+
ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys2)
633+
define link-file-relative
634+
$(call MakeTargetDir)
635+
$(RM) '$(call DecodeSpace, $@)'
636+
cmd //c "mklink /J $(call FixPath, $(call DecodeSpace, $@)) $(call FixPath, $(call DecodeSpace, $<))"
637+
endef
638+
else
639+
define link-file-relative
630640
$(call MakeTargetDir)
631641
$(RM) '$(call DecodeSpace, $@)'
632642
$(LN) -s '$(call DecodeSpace, $(call RelativePath, $<, $(@D)))' '$(call DecodeSpace, $@)'
633-
endef
643+
endef
644+
endif
634645

635-
define link-file-absolute
646+
ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys2)
647+
define link-file-absolute
648+
$(call MakeTargetDir)
649+
$(RM) '$(call DecodeSpace, $@)'
650+
cmd //c "mklink /J $(call FixPath, $(call DecodeSpace, $@)) $(call FixPath, $(call DecodeSpace, $<))"
651+
endef
652+
else
653+
define link-file-absolute
636654
$(call MakeTargetDir)
637655
$(RM) '$(call DecodeSpace, $@)'
638656
$(LN) -s '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
639-
endef
657+
endef
658+
endif
640659

641660
################################################################################
642661
# Filter out duplicate sub strings while preserving order. Keeps the first occurance.

0 commit comments

Comments
 (0)