Skip to content

Commit 7ea6313

Browse files
authored
Merge pull request #112 from ROCm-Developer-Tools/amd/dev/kzhuravl/cleanup-whitespaces
Cleanup existing double quote handling
2 parents 252055b + 5a3749f commit 7ea6313

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

amd/hipcc/bin/hipcc.pl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ BEGIN
121121

122122
use hipvars;
123123
$isWindows = $hipvars::isWindows;
124+
$doubleQuote = $hipvars::doubleQuote;
124125
$HIP_RUNTIME = $hipvars::HIP_RUNTIME;
125126
$HIP_PLATFORM = $hipvars::HIP_PLATFORM;
126127
$HIP_COMPILER = $hipvars::HIP_COMPILER;
@@ -131,6 +132,10 @@ BEGIN
131132
$HIP_VERSION = $hipvars::HIP_VERSION;
132133
$HIP_ROCCLR_HOME = $hipvars::HIP_ROCCLR_HOME;
133134

135+
sub get_normalized_path {
136+
return $doubleQuote . $_[0] . $doubleQuote;
137+
}
138+
134139
if ($HIP_PLATFORM eq "amd") {
135140
$HIP_INCLUDE_PATH = "$HIP_ROCCLR_HOME/include";
136141
if (!defined $HIP_LIB_PATH) {
@@ -155,17 +160,17 @@ BEGIN
155160
if($isWindows) {
156161
$execExtension = ".exe";
157162
}
158-
$HIPCC="\"$HIP_CLANG_PATH/clang++" . $execExtension . "\"";
163+
$HIPCC=get_normalized_path("$HIP_CLANG_PATH/clang++" . $execExtension);
159164

160165
# If $HIPCC clang++ is not compiled, use clang instead
161166
if ( ! -e $HIPCC ) {
162-
$HIPCC="\"$HIP_CLANG_PATH/clang" . $execExtension . "\"";
167+
$HIPCC=get_normalized_path("$HIP_CLANG_PATH/clang" . $execExtension);
163168
$HIPLDFLAGS = "--driver-mode=g++";
164169
}
165170
# to avoid using dk linker or MSVC linker
166171
if($isWindows) {
167172
$HIPLDFLAGS .= " -fuse-ld=lld";
168-
$HIPLDFLAGS .= " --ld-path=\"$HIP_CLANG_PATH/lld-link.exe\"";
173+
$HIPLDFLAGS .= " --ld-path=" . get_normalized_path("$HIP_CLANG_PATH/lld-link.exe");
169174
}
170175

171176
# get Clang RT Builtin path
@@ -201,21 +206,21 @@ BEGIN
201206
print ("CUDA_PATH=$CUDA_PATH\n");
202207
}
203208

204-
$HIPCC="\"$CUDA_PATH/bin/nvcc\"";
209+
$HIPCC=get_normalized_path("$CUDA_PATH/bin/nvcc");
205210
$HIPCXXFLAGS .= " -Wno-deprecated-gpu-targets ";
206-
$HIPCXXFLAGS .= " -isystem \"$CUDA_PATH/include\"";
207-
$HIPCFLAGS .= " -isystem \"$CUDA_PATH/include\"";
211+
$HIPCXXFLAGS .= " -isystem " . get_normalized_path("$CUDA_PATH/include");
212+
$HIPCFLAGS .= " -isystem " . get_normalized_path("$CUDA_PATH/include");
208213

209-
$HIPLDFLAGS = " -Wno-deprecated-gpu-targets -lcuda -lcudart -L\"$CUDA_PATH/lib64\"";
214+
$HIPLDFLAGS = " -Wno-deprecated-gpu-targets -lcuda -lcudart -L" . get_normalized_path("$CUDA_PATH/lib64");
210215
} else {
211216
printf ("error: unknown HIP_PLATFORM = '$HIP_PLATFORM'");
212217
printf (" or HIP_COMPILER = '$HIP_COMPILER'");
213218
exit (-1);
214219
}
215220

216221
# Add paths to common HIP includes:
217-
$HIPCXXFLAGS .= " -isystem \"$HIP_INCLUDE_PATH\"" ;
218-
$HIPCFLAGS .= " -isystem \"$HIP_INCLUDE_PATH\"" ;
222+
$HIPCXXFLAGS .= " -isystem " . get_normalized_path("$HIP_INCLUDE_PATH");
223+
$HIPCFLAGS .= " -isystem " . get_normalized_path("$HIP_INCLUDE_PATH");
219224

220225
my $compileOnly = 0;
221226
my $needCXXFLAGS = 0; # need to add CXX flags to compile step
@@ -294,7 +299,7 @@ BEGIN
294299

295300
if ($skipOutputFile) {
296301
# TODO: handle filename with shell metacharacters
297-
$toolArgs .= " \"$arg\"";
302+
$toolArgs .= " " . get_normalized_path("$arg");
298303
$prevArg = $arg;
299304
$skipOutputFile = 0;
300305
next;
@@ -466,7 +471,7 @@ BEGIN
466471
if (not $isWindows and $escapeArg) {
467472
$arg =~ s/[^-a-zA-Z0-9_=+,.\/]/\\$&/g;
468473
}
469-
$toolArgs .= " \"$arg\"" unless $swallowArg;
474+
$toolArgs .= " $arg" unless $swallowArg;
470475
$prevArg = $arg;
471476
}
472477

@@ -561,14 +566,14 @@ BEGIN
561566

562567
# If the HIP_PATH env var is defined, pass that path to Clang
563568
if ($ENV{'HIP_PATH'}) {
564-
my $hip_path_flag = " --hip-path=\"$HIP_PATH\"";
569+
my $hip_path_flag = " --hip-path=" . get_normalized_path("$HIP_PATH");
565570
$HIPCXXFLAGS .= $hip_path_flag;
566571
$HIPLDFLAGS .= $hip_path_flag;
567572
}
568573

569574
if ($hasHIP) {
570575
if (defined $DEVICE_LIB_PATH) {
571-
$HIPCXXFLAGS .= " --hip-device-lib-path=\"$DEVICE_LIB_PATH\"";
576+
$HIPCXXFLAGS .= " --hip-device-lib-path=" . get_normalized_path("$DEVICE_LIB_PATH");
572577
}
573578
}
574579

amd/hipcc/bin/hipvars.pm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ sub can_run {
6161
}
6262

6363
$isWindows = ($^O eq 'MSWin32' or $^O eq 'msys');
64+
$doubleQuote = "\"";
6465

6566
#
6667
# TODO: Fix rpath LDFLAGS settings
@@ -86,6 +87,10 @@ if (-e "$HIP_PATH/bin/rocm_agent_enumerator") {
8687
$ROCM_PATH=$ENV{'ROCM_PATH'} // "/opt/rocm";
8788
}
8889
$CUDA_PATH=$ENV{'CUDA_PATH'} // '/usr/local/cuda';
90+
if ($isWindows and defined $ENV{'CUDA_PATH'}) {
91+
$CUDA_PATH =~ s/^"(.*)"$/$1/;
92+
$CUDA_PATH =~ s/\\/\//g;
93+
}
8994

9095
# Windows/Distro's have a different structure, all binaries are with hipcc
9196
if ($isWindows or -e "$HIP_PATH/bin/clang") {
@@ -124,9 +129,9 @@ if (defined $HIP_RUNTIME and $HIP_RUNTIME eq "rocclr" and !defined $HIP_ROCCLR_H
124129
}
125130

126131
if (not defined $HIP_PLATFORM) {
127-
if (can_run("\"$HIP_CLANG_PATH/clang++\"") or can_run("clang++")) {
132+
if (can_run($doubleQuote . "$HIP_CLANG_PATH/clang++" . $doubleQuote) or can_run("clang++")) {
128133
$HIP_PLATFORM = "amd";
129-
} elsif (can_run("$CUDA_PATH/bin/nvcc") or can_run("nvcc")) {
134+
} elsif (can_run($doubleQuote . "$CUDA_PATH/bin/nvcc" . $doubleQuote) or can_run("nvcc")) {
130135
$HIP_PLATFORM = "nvidia";
131136
$HIP_COMPILER = "nvcc";
132137
$HIP_RUNTIME = "cuda";

0 commit comments

Comments
 (0)