Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: tools/generate_stubs/generate_stubs.py

Issue 10051026: avoid race between dir existence check and dir creation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Creates windows and posix stub files for a given set of signatures. 6 """Creates windows and posix stub files for a given set of signatures.
7 7
8 For libraries that need to be loaded outside of the standard executable startup 8 For libraries that need to be loaded outside of the standard executable startup
9 path mechanism, stub files need to be generated for the wanted functions. In 9 path mechanism, stub files need to be generated for the wanted functions. In
10 windows, this is done via "def" files and the delay load mechanism. On a posix 10 windows, this is done via "def" files and the delay load mechanism. On a posix
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 917
918 if options.type == FILE_TYPE_POSIX_STUB: 918 if options.type == FILE_TYPE_POSIX_STUB:
919 if options.stubfile_name is None: 919 if options.stubfile_name is None:
920 parser.error('Output file name need for %s' % FILE_TYPE_POSIX_STUB) 920 parser.error('Output file name need for %s' % FILE_TYPE_POSIX_STUB)
921 if options.path_from_source is None: 921 if options.path_from_source is None:
922 parser.error('Path from source needed for %s' % FILE_TYPE_POSIX_STUB) 922 parser.error('Path from source needed for %s' % FILE_TYPE_POSIX_STUB)
923 923
924 return options, args 924 return options, args
925 925
926 926
927 def EnsureDirExists(dir):
928 """Creates a directory. Does not use the more obvious 'if not exists: create'
929 to avoid race with other invocations of the same code, which will error out
930 on makedirs if another invocation has succeeded in creating the directory
931 since the existence check."""
932 try:
933 os.makedirs(dir)
934 except:
935 if not os.path.isdir(dir):
936 raise
937
938
927 def CreateOutputDirectories(options): 939 def CreateOutputDirectories(options):
928 """Creates the intermediate and final output directories. 940 """Creates the intermediate and final output directories.
929 941
930 Given the parsed options, create the intermediate and final output 942 Given the parsed options, create the intermediate and final output
931 directories if they do not exist. Returns the paths to both directories 943 directories if they do not exist. Returns the paths to both directories
932 as a pair. 944 as a pair.
933 945
934 Args: 946 Args:
935 options: An OptionParser.OptionValues object with the parsed options. 947 options: An OptionParser.OptionValues object with the parsed options.
936 948
937 Returns: 949 Returns:
938 The pair (out_dir, intermediate_dir), both of which are strings. 950 The pair (out_dir, intermediate_dir), both of which are strings.
939 """ 951 """
940 out_dir = os.path.normpath(options.out_dir) 952 out_dir = os.path.normpath(options.out_dir)
941 intermediate_dir = os.path.normpath(options.intermediate_dir) 953 intermediate_dir = os.path.normpath(options.intermediate_dir)
942 if intermediate_dir is None: 954 if intermediate_dir is None:
943 intermediate_dir = out_dir 955 intermediate_dir = out_dir
944 956
945 if not os.path.exists(out_dir): 957 EnsureDirExists(out_dir)
946 os.makedirs(out_dir) 958 EnsureDirExists(intermediate_dir)
947 if not os.path.exists(intermediate_dir):
948 os.makedirs(intermediate_dir)
949 959
950 return out_dir, intermediate_dir 960 return out_dir, intermediate_dir
951 961
952 962
953 def CreateWindowsLibForSigFiles(sig_files, out_dir, intermediate_dir): 963 def CreateWindowsLibForSigFiles(sig_files, out_dir, intermediate_dir):
954 """For each signature file, create a windows lib. 964 """For each signature file, create a windows lib.
955 965
956 Args: 966 Args:
957 sig_files: Array of Strings with the paths to each signature file. 967 sig_files: Array of Strings with the paths to each signature file.
958 out_dir: String holding path to directory where the generated libs go. 968 out_dir: String holding path to directory where the generated libs go.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 if options.type == FILE_TYPE_WIN: 1054 if options.type == FILE_TYPE_WIN:
1045 CreateWindowsLibForSigFiles(args, out_dir, intermediate_dir) 1055 CreateWindowsLibForSigFiles(args, out_dir, intermediate_dir)
1046 elif options.type == FILE_TYPE_POSIX_STUB: 1056 elif options.type == FILE_TYPE_POSIX_STUB:
1047 CreatePosixStubsForSigFiles(args, options.stubfile_name, out_dir, 1057 CreatePosixStubsForSigFiles(args, options.stubfile_name, out_dir,
1048 intermediate_dir, options.path_from_source, 1058 intermediate_dir, options.path_from_source,
1049 options.extra_stub_header) 1059 options.extra_stub_header)
1050 1060
1051 1061
1052 if __name__ == '__main__': 1062 if __name__ == '__main__':
1053 main() 1063 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698