Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / build / chip / java / jar_runner.py
1 #!/usr/bin/env python
2 # Copyright (c) 2020 Project CHIP Authors
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # Copyright 2015 The Chromium Authors. All rights reserved.
17 # Use of this source code is governed by a BSD-style license that can be
18 # found in the LICENSE file.
19
20 """Wrapper script to run javac command as an action with gn."""
21
22 import os
23 import subprocess
24 import sys
25
26 EXIT_SUCCESS = 0
27 EXIT_FAILURE = 1
28
29
30 def IsExecutable(path):
31   """Returns whether file at |path| exists and is executable.
32
33   Args:
34     path: absolute or relative path to test.
35
36   Returns:
37     True if the file at |path| exists, False otherwise.
38   """
39   return os.path.isfile(path) and os.access(path, os.X_OK)
40
41
42 def FindCommand(command):
43   """Looks up for |command| in PATH.
44
45   Args:
46     command: name of the command to lookup, if command is a relative or
47       absolute path (i.e. contains some path separator) then only that
48       path will be tested.
49
50   Returns:
51     Full path to command or None if the command was not found.
52
53     On Windows, this respects the PATHEXT environment variable when the
54     command name does not have an extension.
55   """
56   fpath, _ = os.path.split(command)
57   if fpath:
58     if IsExecutable(command):
59       return command
60
61   if sys.platform == 'win32':
62     # On Windows, if the command does not have an extension, cmd.exe will
63     # try all extensions from PATHEXT when resolving the full path.
64     command, ext = os.path.splitext(command)
65     if not ext:
66       exts = os.environ['PATHEXT'].split(os.path.pathsep)
67     else:
68       exts = [ext]
69   else:
70     exts = ['']
71
72   for path in os.environ['PATH'].split(os.path.pathsep):
73     for ext in exts:
74       path = os.path.join(path, command) + ext
75       if IsExecutable(path):
76         return path
77
78   return None
79
80
81 def main():
82   java_path = FindCommand('jar')
83   if not java_path:
84     sys.stderr.write('jar: command not found\n')
85     sys.exit(EXIT_FAILURE)
86
87   args = sys.argv[1:]
88   if len(args) < 1:
89     sys.stderr.write('usage: %s [jar_args]...\n' % sys.argv[0])
90     sys.exit(EXIT_FAILURE)
91
92   return subprocess.check_call([java_path] + args)
93
94
95 if __name__ == '__main__':
96   sys.exit(main())