Skip to content

Commit 159cb6f

Browse files
YaaZAlexey Ushakov
authored andcommitted
8268083: JDK-8267706 breaks bin/idea.sh on a Mac
Reviewed-by: erikj
1 parent 8158b82 commit 159cb6f

11 files changed

Lines changed: 172 additions & 112 deletions

File tree

bin/idea.sh

Lines changed: 73 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,51 @@
2525
# Shell script for generating an IDEA project from a given list of modules
2626

2727
usage() {
28-
echo "usage: $0 [-h|--help] [-v|--verbose] [-o|--output <path>] [modules]+"
28+
echo "Usage: $0 [-h|--help] [-q|--quiet] [-a|--absolute-paths] [-o|--output <path>] [modules...]"
29+
echo " -h | --help"
30+
echo " -q | --quiet
31+
No stdout output"
32+
echo " -a | --absolute-paths
33+
Use absolute paths to this jdk, so that generated .idea
34+
project files can be moved independently of jdk sources"
35+
echo " -o | --output <path>
36+
Where .idea directory with project files will be generated
37+
(e.g. using '-o .' will place project files in './.idea')
38+
Default: $TOPLEVEL_DIR"
39+
echo " [modules...]
40+
Generate project modules for specific java modules
41+
(e.g. 'java.base java.desktop')
42+
Default: all existing modules (java.* and jdk.*)"
2943
exit 1
3044
}
3145

3246
SCRIPT_DIR=`dirname $0`
3347
#assume TOP is the dir from which the script has been called
3448
TOP=`pwd`
3549
cd $SCRIPT_DIR; SCRIPT_DIR=`pwd`
50+
cd .. ; TOPLEVEL_DIR=`pwd`
3651
cd $TOP;
3752

38-
IDEA_OUTPUT=$TOP/.idea
39-
CUSTOM_IDEA_OUTPUT=false
40-
VERBOSE="false"
53+
IDEA_OUTPUT=$TOPLEVEL_DIR/.idea
54+
VERBOSE=true
55+
ABSOLUTE_PATHS=false
4156
while [ $# -gt 0 ]
4257
do
4358
case $1 in
4459
-h | --help )
4560
usage
4661
;;
4762

48-
-v | --vebose )
49-
VERBOSE="true"
63+
-q | --quiet )
64+
VERBOSE=false
65+
;;
66+
67+
-a | --absolute-paths )
68+
ABSOLUTE_PATHS=true
5069
;;
5170

5271
-o | --output )
5372
IDEA_OUTPUT=$2/.idea
54-
CUSTOM_IDEA_OUTPUT=true
5573
shift
5674
;;
5775

@@ -68,14 +86,9 @@ done
6886

6987
mkdir -p $IDEA_OUTPUT || exit 1
7088
cd $IDEA_OUTPUT; IDEA_OUTPUT=`pwd`
89+
cd ..; IDEA_OUTPUT_PARENT=`pwd`
7190

72-
if [ "x$TOPLEVEL_DIR" = "x" ] ; then
73-
cd $SCRIPT_DIR/..
74-
TOPLEVEL_DIR=`pwd`
75-
cd $IDEA_OUTPUT
76-
fi
77-
78-
MAKE_DIR="$SCRIPT_DIR/../make"
91+
MAKE_DIR="$TOPLEVEL_DIR/make"
7992
IDEA_MAKE="$MAKE_DIR/ide/idea/jdk"
8093
IDEA_TEMPLATE="$IDEA_MAKE/template"
8194

@@ -88,17 +101,17 @@ if [ -d "$TEMPLATES_OVERRIDE" ] ; then
88101
done
89102
fi
90103

91-
if [ "$VERBOSE" = "true" ] ; then
92-
echo "output dir: $IDEA_OUTPUT"
93-
echo "idea template dir: $IDEA_TEMPLATE"
104+
if [ "$VERBOSE" = true ] ; then
105+
echo "Will generate IDEA project files in \"$IDEA_OUTPUT\" for project \"$TOPLEVEL_DIR\""
94106
fi
95107

96-
cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I $MAKE_DIR/.. idea MAKEOVERRIDES= OUT=$IDEA_OUTPUT/env.cfg MODULES="$*" || exit 1
108+
cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I "$TOPLEVEL_DIR" idea \
109+
MAKEOVERRIDES= IDEA_OUTPUT_PARENT="$IDEA_OUTPUT_PARENT" OUT="$IDEA_OUTPUT/env.cfg" MODULES="$*" || exit 1
97110
cd $SCRIPT_DIR
98111

99112
. $IDEA_OUTPUT/env.cfg
100113

101-
# Expect MODULES, MODULE_NAMES, BOOT_JDK & SPEC to be set
114+
# Expect MODULES, MODULE_NAMES, RELATIVE_PROJECT_DIR, RELATIVE_BUILD_DIR to be set
102115
if [ "xMODULES" = "x" ] ; then
103116
echo "FATAL: MODULES is empty" >&2; exit 1
104117
fi
@@ -107,12 +120,12 @@ if [ "x$MODULE_NAMES" = "x" ] ; then
107120
echo "FATAL: MODULE_NAMES is empty" >&2; exit 1
108121
fi
109122

110-
if [ "x$BOOT_JDK" = "x" ] ; then
111-
echo "FATAL: BOOT_JDK is empty" >&2; exit 1
123+
if [ "x$RELATIVE_PROJECT_DIR" = "x" ] ; then
124+
echo "FATAL: RELATIVE_PROJECT_DIR is empty" >&2; exit 1
112125
fi
113126

114-
if [ "x$SPEC" = "x" ] ; then
115-
echo "FATAL: SPEC is empty" >&2; exit 1
127+
if [ "x$RELATIVE_BUILD_DIR" = "x" ] ; then
128+
echo "FATAL: RELATIVE_BUILD_DIR is empty" >&2; exit 1
116129
fi
117130

118131
if [ -d "$TOPLEVEL_DIR/.hg" ] ; then
@@ -123,6 +136,29 @@ if [ -d "$TOPLEVEL_DIR/.git" ] ; then
123136
VCS_TYPE="Git"
124137
fi
125138

139+
if [ "$ABSOLUTE_PATHS" = true ] ; then
140+
if [ "x$PATHTOOL" != "x" ]; then
141+
PROJECT_DIR="`$PATHTOOL -am $TOPLEVEL_DIR`"
142+
else
143+
PROJECT_DIR="$TOPLEVEL_DIR"
144+
fi
145+
MODULE_DIR="$PROJECT_DIR"
146+
cd "$TOPLEVEL_DIR" && cd "$RELATIVE_BUILD_DIR" && BUILD_DIR="`pwd`"
147+
else
148+
if [ "$RELATIVE_PROJECT_DIR" = "." ] ; then
149+
PROJECT_DIR=""
150+
else
151+
PROJECT_DIR="/$RELATIVE_PROJECT_DIR"
152+
fi
153+
MODULE_DIR="\$MODULE_DIR\$$PROJECT_DIR"
154+
PROJECT_DIR="\$PROJECT_DIR\$$PROJECT_DIR"
155+
BUILD_DIR="\$PROJECT_DIR\$/$RELATIVE_BUILD_DIR"
156+
fi
157+
if [ "$VERBOSE" = true ] ; then
158+
echo "Project root: $PROJECT_DIR"
159+
echo "Generating IDEA project files..."
160+
fi
161+
126162
### Replace template variables
127163

128164
NUM_REPLACEMENTS=0
@@ -146,18 +182,13 @@ add_replacement() {
146182
eval TO$NUM_REPLACEMENTS='$2'
147183
}
148184

185+
add_replacement "###PROJECT_DIR###" "$PROJECT_DIR"
186+
add_replacement "###MODULE_DIR###" "$MODULE_DIR"
149187
add_replacement "###MODULE_NAMES###" "$MODULE_NAMES"
150188
add_replacement "###VCS_TYPE###" "$VCS_TYPE"
151-
SPEC_DIR=`dirname $SPEC`
152-
RELATIVE_SPEC_DIR="`realpath --relative-to=\"$TOPLEVEL_DIR\" \"$SPEC_DIR\"`"
153-
add_replacement "###BUILD_DIR###" "$RELATIVE_SPEC_DIR"
154-
add_replacement "###IMAGES_DIR###" "$RELATIVE_SPEC_DIR/images/jdk"
189+
add_replacement "###BUILD_DIR###" "$BUILD_DIR"
155190
if [ "x$PATHTOOL" != "x" ]; then
156-
if [ "$CUSTOM_IDEA_OUTPUT" = true ]; then
157-
add_replacement "###BASH_RUNNER_PREFIX###" "`$PATHTOOL -am $IDEA_OUTPUT/.idea/bash.bat`"
158-
else
159-
add_replacement "###BASH_RUNNER_PREFIX###" ".idea\\\\bash.bat"
160-
fi
191+
add_replacement "###BASH_RUNNER_PREFIX###" "\$PROJECT_DIR\$/.idea/bash.bat"
161192
else
162193
add_replacement "###BASH_RUNNER_PREFIX###" ""
163194
fi
@@ -184,37 +215,32 @@ replace_template_dir "$IDEA_OUTPUT"
184215

185216
### Generate module project files
186217

218+
if [ "$VERBOSE" = true ] ; then
219+
echo "Generating project modules:"
220+
fi
187221
(
188222
DEFAULT_IFS="$IFS"
189223
IFS='#'
190-
if [ "x$PATHTOOL" != "x" ]; then
191-
TOPDIR_FOR_RELATIVITY_CHECKS="`echo \"$TOPLEVEL_DIR\" | tr '[:upper:]' '[:lower:]'`"
192-
else
193-
TOPDIR_FOR_RELATIVITY_CHECKS="$TOPLEVEL_DIR"
194-
fi
195224
for value in $MODULES; do
196225
(
197226
eval "$value"
198-
if [ "$VERBOSE" = "true" ] ; then
199-
echo "generating project module: $module"
227+
if [ "$VERBOSE" = true ] ; then
228+
echo " $module"
200229
fi
201-
add_replacement "###MODULE_DIR###" "src/$module"
230+
add_replacement "###MODULE_CONTENT###" "src/$module"
202231
SOURCE_DIRS=""
203232
IFS=' '
204233
for dir in $moduleSrcDirs; do
205-
if [ "x$PATHTOOL" != "x" ]; then
206-
dir="`echo \"$dir\" | tr '[:upper:]' '[:lower:]'`"
207-
fi
208-
dir="`realpath --relative-to=\"$TOPDIR_FOR_RELATIVITY_CHECKS\" \"$dir\"`"
209234
case $dir in # Exclude generated sources to avoid module-info conflicts, see https://youtrack.jetbrains.com/issue/IDEA-185108
210-
"$SPEC_DIR"*) ;;
211-
*) SOURCE_DIRS="$SOURCE_DIRS<sourceFolder url=\"file://\$MODULE_DIR\$/$dir\" isTestSource=\"false\" /> "
235+
"src/"*) SOURCE_DIRS="$SOURCE_DIRS<sourceFolder url=\"file://$MODULE_DIR/$dir\" isTestSource=\"false\" /> "
212236
esac
213237
done
214238
add_replacement "###SOURCE_DIRS###" "$SOURCE_DIRS"
215239
DEPENDENCIES=""
216240
for dep in $moduleDependencies; do
217-
DEPENDENCIES="$DEPENDENCIES<orderEntry type=\"module\" module-name=\"$dep\" /> "
241+
case $MODULE_NAMES in # Exclude skipped modules from dependencies
242+
*"$dep"*) DEPENDENCIES="$DEPENDENCIES<orderEntry type=\"module\" module-name=\"$dep\" /> "
243+
esac
218244
done
219245
add_replacement "###DEPENDENCIES###" "$DEPENDENCIES"
220246
cp "$IDEA_OUTPUT/module.iml" "$IDEA_OUTPUT/$module.iml"

make/common/Utils.gmk

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,40 +92,58 @@ SetIfEmpty = \
9292
# foo/bar/baz, /foo/bar -> <empty>
9393
#
9494
# The x prefix is used to preserve the presence of the initial slash
95+
# On Windows paths are treated as case-insensitive
9596
#
9697
# $1 - Path to compare
9798
# $2 - Other path to compare
9899
FindCommonPathPrefix = \
99-
$(patsubst x%,%,$(subst $(SPACE),/,$(strip \
100-
$(call FindCommonPathPrefixHelper, \
101-
$(subst /,$(SPACE),x$(strip $1)), $(subst /,$(SPACE),x$(strip $2))) \
102-
)))
103-
104-
FindCommonPathPrefixHelper = \
100+
$(call DecodeSpace,$(patsubst x%,%,$(subst $(SPACE),/,$(strip \
101+
$(call FindCommonPathPrefixHelper1, \
102+
$(subst /,$(SPACE),x$(call EncodeSpace,$(strip $1))), \
103+
$(subst /,$(SPACE),x$(call EncodeSpace,$(strip $2)))) \
104+
))))
105+
106+
FindCommonPathPrefixHelper1 = \
107+
$(if $(filter $(OPENJDK_TARGET_OS), windows), \
108+
$(call FindCommonPathPrefixHelper2,$(call uppercase,$1),$(call uppercase,$2),$1), \
109+
$(call FindCommonPathPrefixHelper2,$1,$2,$1))
110+
111+
FindCommonPathPrefixHelper2 = \
105112
$(if $(call equals, $(firstword $1), $(firstword $2)), \
106-
$(firstword $1) \
107-
$(call FindCommonPathPrefixHelper, \
108-
$(wordlist 2, $(words $1), $1), $(wordlist 2, $(words $2), $2) \
113+
$(if $(call equals, $(firstword $1),),, \
114+
$(firstword $3) \
115+
$(call FindCommonPathPrefixHelper2, \
116+
$(wordlist 2, $(words $1), $1), \
117+
$(wordlist 2, $(words $2), $2), \
118+
$(wordlist 2, $(words $3), $3) \
119+
) \
109120
) \
110121
)
111122

112-
# Convert a partial path into as many directory levels of ../, removing
113-
# leading and following /.
114-
# Ex: foo/bar/baz/ -> ../../..
115-
# foo/bar -> ../..
116-
# /foo -> ..
117-
DirToDotDot = \
118-
$(subst $(SPACE),/,$(foreach d, $(subst /,$(SPACE),$1),..))
119-
120123
# Computes the relative path from a directory to a file
121124
# $1 - File to compute the relative path to
122125
# $2 - Directory to compute the relative path from
123126
RelativePath = \
124-
$(eval $1_prefix := $(call FindCommonPathPrefix, $1, $2)) \
125-
$(eval $1_dotdots := $(call DirToDotDot, $(patsubst $($(strip $1)_prefix)%, %, $2))) \
126-
$(eval $1_dotdots := $(if $($(strip $1)_dotdots),$($(strip $1)_dotdots),.)) \
127-
$(eval $1_suffix := $(patsubst $($(strip $1)_prefix)/%, %, $1)) \
128-
$($(strip $1)_dotdots)/$($(strip $1)_suffix)
127+
$(call DecodeSpace,$(strip $(call RelativePathHelper,$(call EncodeSpace \
128+
,$(strip $1)),$(call EncodeSpace \
129+
,$(strip $2)),$(call EncodeSpace \
130+
,$(call FindCommonPathPrefix,$1,$2)))))
131+
132+
RelativePathHelper = \
133+
$(eval $3_prefix_length := $(words $(subst /,$(SPACE),$3))) \
134+
$(eval $1_words := $(subst /,$(SPACE),$1)) \
135+
$(eval $2_words := $(subst /,$(SPACE),$2)) \
136+
$(if $(call equals,$($3_prefix_length),0),, \
137+
$(eval $1_words := $(wordlist 2,$(words $($1_words)),$(wordlist \
138+
$($3_prefix_length),$(words $($1_words)),$($1_words)))) \
139+
$(eval $2_words := $(wordlist 2,$(words $($2_words)),$(wordlist \
140+
$($3_prefix_length),$(words $($2_words)),$($2_words)))) \
141+
) \
142+
$(eval $1_suffix := $(subst $(SPACE),/,$($1_words))) \
143+
$(eval $2_dotdots := $(subst $(SPACE),/,$(foreach d,$($2_words),..))) \
144+
$(if $($1_suffix), \
145+
$(if $($2_dotdots), $($2_dotdots)/$($1_suffix), $($1_suffix)), \
146+
$(if $($2_dotdots), $($2_dotdots), .))
129147

130148
################################################################################
131149
# Filter out duplicate sub strings while preserving order. Keeps the first occurance.

make/ide/idea/jdk/idea.gmk

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,15 @@ else #with SPEC
4646
endif
4747

4848
idea:
49-
$(ECHO) "SUPPORT=$(SUPPORT_OUTPUTDIR)" > $(OUT)
5049
$(ECHO) "MODULES=\"$(foreach mod, $(SEL_MODULES), \
5150
module='$(mod)' \
52-
moduleSrcDirs='$(call FindModuleSrcDirs,$(mod))' \
51+
moduleSrcDirs='$(foreach m,$(call FindModuleSrcDirs,$(mod)),$(call RelativePath,$m,$(topdir)))' \
5352
moduleDependencies='$(call FindTransitiveDepsForModule,$(mod))' \
54-
#)\"" >> $(OUT)
53+
#)\"" > $(OUT)
5554
$(ECHO) "MODULE_NAMES=\"$(strip $(foreach mod, $(SEL_MODULES), $(mod)))\"" >> $(OUT)
56-
$(ECHO) "SEL_MODULES=\"$(SEL_MODULES)\"" >> $(OUT)
57-
$(ECHO) "BOOT_JDK=\"$(BOOT_JDK)\"" >> $(OUT)
55+
$(ECHO) "RELATIVE_PROJECT_DIR=\"$(call RelativePath,$(topdir),$(IDEA_OUTPUT_PARENT))\"" >> $(OUT)
56+
$(ECHO) "RELATIVE_BUILD_DIR=\"$(call RelativePath,$(OUTPUTDIR),$(IDEA_OUTPUT_PARENT))\"" >> $(OUT)
5857
$(ECHO) "PATHTOOL=\"$(PATHTOOL)\"" >> $(OUT)
59-
$(ECHO) "SPEC=\"$(SPEC)\"" >> $(OUT)
6058
$(ECHO) "JT_HOME=\"$(JT_HOME)\"" >> $(OUT)
6159
$(ECHO) "WINENV_ROOT=\"$(WINENV_ROOT)\"" >> $(OUT)
6260

make/ide/idea/jdk/template/compiler.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<component name="CompilerConfiguration">
44
<option name="DEFAULT_COMPILER" value="Javac" />
55
<excludeFromCompile>
6-
<directory url="file://$PROJECT_DIR$/src" includeSubdirectories="true" />
7-
<directory url="file://$PROJECT_DIR$/build" includeSubdirectories="true" />
8-
<directory url="file://$PROJECT_DIR$/make" includeSubdirectories="true" />
9-
<directory url="file://$PROJECT_DIR$/test" includeSubdirectories="false" />
6+
<directory url="file://###PROJECT_DIR###/src" includeSubdirectories="true" />
7+
<directory url="file://###PROJECT_DIR###/build" includeSubdirectories="true" />
8+
<directory url="file://###PROJECT_DIR###/make" includeSubdirectories="true" />
9+
<directory url="file://###PROJECT_DIR###/test" includeSubdirectories="false" />
1010
</excludeFromCompile>
1111
<resourceExtensions />
1212
<wildcardResourcePatterns>

make/ide/idea/jdk/template/jdk.iml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<module type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" inherit-compiler-output="true">
44
<exclude-output />
5-
<content url="file://$MODULE_DIR$">
6-
<excludeFolder url="file://$MODULE_DIR$/build" />
7-
<excludeFolder url="file://$MODULE_DIR$/make" />
5+
<content url="file://###MODULE_DIR###">
6+
<excludeFolder url="file://###MODULE_DIR###/build" />
7+
<excludeFolder url="file://###MODULE_DIR###/make" />
88
</content>
99
<orderEntry type="sourceFolder" forTests="false" />
1010
<orderEntry type="inheritedJdk" />

make/ide/idea/jdk/template/misc.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55
</component>
66
<component name="JTRegService">
77
<path>###JTREG_HOME###</path>
8-
<workDir>$PROJECT_DIR$/###BUILD_DIR###</workDir>
9-
<jre alt="true" value="$PROJECT_DIR$/###IMAGES_DIR###" />
8+
<workDir>###BUILD_DIR###</workDir>
9+
<jre alt="true" value="###BUILD_DIR###/images/jdk" />
1010
<options></options>
11-
<ant>
12-
<target file="file://$PROJECT_DIR$/make/ide/idea/jdk/build.xml" name="images" />
13-
</ant>
1411
</component>
1512
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" assert-keyword="true" jdk-15="true">
16-
<output url="file://$PROJECT_DIR$/###BUILD_DIR###/idea" />
13+
<output url="file://###BUILD_DIR###/idea" />
1714
</component>
1815
</project>

make/ide/idea/jdk/template/module.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<module type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" inherit-compiler-output="true">
44
<exclude-output />
5-
<content url="file://$MODULE_DIR$/###MODULE_DIR###">
5+
<content url="file://###MODULE_DIR###/###MODULE_CONTENT###">
66
###SOURCE_DIRS###
77
</content>
88
<orderEntry type="sourceFolder" forTests="false" />

make/ide/idea/jdk/template/test.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<module type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" inherit-compiler-output="true">
44
<exclude-output />
5-
<content url="file://$MODULE_DIR$/test/jdk"></content>
5+
<content url="file://###MODULE_DIR###/test/jdk"></content>
66
<orderEntry type="sourceFolder" forTests="true" />
77
###TEST_MODULE_DEPENDENCIES###
88
<orderEntry type="inheritedJdk" />

make/ide/idea/jdk/template/vcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project version="4">
33
<component name="VcsDirectoryMappings">
4-
<mapping directory="$PROJECT_DIR$" vcs="###VCS_TYPE###" />
4+
<mapping directory="###PROJECT_DIR###" vcs="###VCS_TYPE###" />
55
</component>
66
</project>

0 commit comments

Comments
 (0)