3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
12 from util
import build_utils
13 from util
import md5_check
15 def Jar(class_files
, classes_dir
, jar_path
):
16 jar_path
= os
.path
.abspath(jar_path
)
18 # The paths of the files in the jar will be the same as they are passed in to
19 # the command. Because of this, the command should be run in
20 # options.classes_dir so the .class file paths in the jar are correct.
22 class_files_rel
= [os
.path
.relpath(f
, jar_cwd
) for f
in class_files
]
23 jar_cmd
= ['jar', 'cf0', jar_path
] + class_files_rel
25 record_path
= '%s.md5.stamp' % jar_path
26 md5_check
.CallAndRecordIfStale(
27 lambda: build_utils
.CheckOutput(jar_cmd
, cwd
=jar_cwd
),
28 record_path
=record_path
,
29 input_paths
=class_files
,
30 input_strings
=jar_cmd
,
31 force
=not os
.path
.exists(jar_path
),
34 build_utils
.Touch(jar_path
, fail_if_missing
=True)
37 def JarDirectory(classes_dir
, excluded_classes
, jar_path
):
38 class_files
= build_utils
.FindInDirectory(classes_dir
, '*.class')
39 for exclude
in excluded_classes
:
41 lambda f
: not fnmatch
.fnmatch(f
, exclude
), class_files
)
43 Jar(class_files
, classes_dir
, jar_path
)
46 parser
= optparse
.OptionParser()
47 parser
.add_option('--classes-dir', help='Directory containing .class files.')
48 parser
.add_option('--jar-path', help='Jar output path.')
49 parser
.add_option('--excluded-classes',
50 help='List of .class file patterns to exclude from the jar.')
51 parser
.add_option('--stamp', help='Path to touch on success.')
53 options
, _
= parser
.parse_args()
55 JarDirectory(options
.classes_dir
,
56 build_utils
.ParseGypList(options
.excluded_classes
),
60 build_utils
.Touch(options
.stamp
)
63 if __name__
== '__main__':