Skip to content

Commit 399a52d

Browse files
committed
8298459: Fix msys2 linking and handling out of tree build directory for source zip creation
Backport-of: d624debe23f60d778d7be43f28d06e9454057217
1 parent 60a7cdd commit 399a52d

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, 2020, 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))
@@ -45,10 +46,10 @@ ALL_MODULES := $(FindAllModules)
4546
# again to create src.zip.
4647
$(foreach m, $(ALL_MODULES), \
4748
$(foreach d, $(call FindModuleSrcDirs, $m), \
48-
$(eval $d_TARGET := $(SRC_ZIP_WORK_DIR)/$(patsubst $(TOPDIR)/%,%,$d)/$m) \
49+
$(eval $d_TARGET := $(SRC_ZIP_WORK_DIR)/$(patsubst $(TOPDIR)/%,%,$(patsubst $(SUPPORT_OUTPUTDIR)/%,%,$d))/$m) \
4950
$(if $(SRC_GENERATED), , \
5051
$(eval $$($d_TARGET): $d ; \
51-
$$(if $(filter $(TOPDIR)/%, $d), $$(link-file-relative), $$(link-file-absolute)) \
52+
$$(if $(filter $(SRC_ZIP_BASE)/%, $d), $$(link-file-relative), $$(link-file-absolute)) \
5253
) \
5354
) \
5455
$(eval SRC_ZIP_SRCS += $$($d_TARGET)) \

make/common/MakeBase.gmk

+23-4
Original file line numberDiff line numberDiff line change
@@ -307,17 +307,36 @@ endef
307307
# There are two versions, either creating a relative or an absolute link. Be
308308
# careful when using this on Windows since the symlink created is only valid in
309309
# the unix emulation environment.
310-
define link-file-relative
310+
# In msys2 we use mklink /J because its ln would perform a deep copy of the target.
311+
# This inhibits performance and can lead to issues with long paths. With mklink /J
312+
# relative linking does not work, so we handle the link as absolute path.
313+
ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys2)
314+
define link-file-relative
315+
$(call MakeTargetDir)
316+
$(RM) '$(call DecodeSpace, $@)'
317+
cmd //c "mklink /J $(call FixPath, $(call DecodeSpace, $@)) $(call FixPath, $(call DecodeSpace, $<))"
318+
endef
319+
else
320+
define link-file-relative
311321
$(call MakeTargetDir)
312322
$(RM) '$(call DecodeSpace, $@)'
313323
$(LN) -s '$(call DecodeSpace, $(call RelativePath, $<, $(@D)))' '$(call DecodeSpace, $@)'
314-
endef
324+
endef
325+
endif
315326

316-
define link-file-absolute
327+
ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys2)
328+
define link-file-absolute
329+
$(call MakeTargetDir)
330+
$(RM) '$(call DecodeSpace, $@)'
331+
cmd //c "mklink /J $(call FixPath, $(call DecodeSpace, $@)) $(call FixPath, $(call DecodeSpace, $<))"
332+
endef
333+
else
334+
define link-file-absolute
317335
$(call MakeTargetDir)
318336
$(RM) '$(call DecodeSpace, $@)'
319337
$(LN) -s '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
320-
endef
338+
endef
339+
endif
321340

322341
################################################################################
323342

0 commit comments

Comments
 (0)