|
| 1 | +#!/usr/bin/env perl |
| 2 | +# Copyright (c) 2015 - 2021 Advanced Micro Devices, Inc. All rights reserved. |
| 3 | +# |
| 4 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +# of this software and associated documentation files (the "Software"), to deal |
| 6 | +# in the Software without restriction, including without limitation the rights |
| 7 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +# copies of the Software, and to permit persons to whom the Software is |
| 9 | +# furnished to do so, subject to the following conditions: |
| 10 | +# |
| 11 | +# The above copyright notice and this permission notice shall be included in |
| 12 | +# all copies or substantial portions of the Software. |
| 13 | +# |
| 14 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | +# THE SOFTWARE. |
| 21 | + |
| 22 | +# Need perl > 5.10 to use logic-defined or |
| 23 | +use 5.006; use v5.10.1; |
| 24 | + |
| 25 | +use warnings; |
| 26 | + |
| 27 | +use File::Basename; |
| 28 | +use File::Spec::Functions 'catfile'; |
| 29 | + |
| 30 | +# TODO: By default select perl script until change incorporated in HIP build script. |
| 31 | +my $USE_PERL_SCRIPT = $ENV{'HIP_USE_PERL_SCRIPTS'}; |
| 32 | +$USE_PERL_SCRIPT //= 1; # use defined-or assignment operator. Use env var, but if not defined default to 1. |
| 33 | + |
| 34 | +my $isWindows = ($^O eq 'MSWin32' or $^O eq 'msys'); |
| 35 | +# escapes args with quotes SWDEV-341955 |
| 36 | +foreach $arg (@ARGV) { |
| 37 | + if ($isWindows) { |
| 38 | + $arg =~ s/[^-a-zA-Z0-9_=+,.:\/\\ ]/\\$&/g; |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +my $SCRIPT_DIR=dirname(__FILE__); |
| 43 | +if ($USE_PERL_SCRIPT) { |
| 44 | + #Invoke hipcc.pl |
| 45 | + my $HIPCC_PERL=catfile($SCRIPT_DIR, '/hipcc.pl'); |
| 46 | + system($^X, $HIPCC_PERL, @ARGV); |
| 47 | +} else { |
| 48 | + $BIN_NAME="/hipcc.bin"; |
| 49 | + if ($isWindows) { |
| 50 | + $BIN_NAME="/hipcc.bin.exe"; |
| 51 | + } |
| 52 | + my $HIPCC_BIN=catfile($SCRIPT_DIR, $BIN_NAME); |
| 53 | + if ( -e $HIPCC_BIN ) { |
| 54 | + #Invoke hipcc.bin |
| 55 | + system($HIPCC_BIN, @ARGV); |
| 56 | + } else { |
| 57 | + print "hipcc.bin not present; Install HIPCC binaries before proceeding"; |
| 58 | + exit(-1); |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +# Because of this wrapper we need to check |
| 63 | +# the output of the system command for perl and bin |
| 64 | +# else the failures are ignored and build fails silently |
| 65 | +if ($? == -1) { |
| 66 | + exit($?); |
| 67 | +} |
| 68 | +elsif ($? & 127) { |
| 69 | + exit($?); |
| 70 | +} |
| 71 | +else { |
| 72 | + $CMD_EXIT_CODE = $? >> 8; |
| 73 | +} |
| 74 | +exit($CMD_EXIT_CODE); |
0 commit comments