@@ -16,10 +16,9 @@ use std::{
16
16
cell:: OnceCell ,
17
17
collections:: BTreeSet ,
18
18
env,
19
- fs:: { create_dir , create_dir_all, read_dir, write} ,
19
+ fs:: { create_dir_all, read_dir, write} ,
20
20
os:: unix:: fs:: symlink,
21
21
path:: Path ,
22
- process:: Command ,
23
22
} ;
24
23
25
24
use anyhow:: { anyhow, bail, Context , Result } ;
@@ -32,7 +31,6 @@ use repo_config::RepoConfig;
32
31
use rooted_path:: RootedPath ;
33
32
use semver:: { Version , VersionReq } ;
34
33
use serde:: Serialize ;
35
- use spdx:: Licensee ;
36
34
37
35
use crate :: {
38
36
android_bp:: cargo_embargo_autoconfig,
@@ -268,52 +266,6 @@ impl ManagedRepo {
268
266
println ! ( " Finding license files" ) ;
269
267
let licenses = find_licenses ( krate. path ( ) . abs ( ) , krate. name ( ) , krate. license ( ) ) ?;
270
268
271
- if !licenses. unsatisfied . is_empty ( ) && licenses. satisfied . is_empty ( ) {
272
- let mut satisfied = false ;
273
- // Sometimes multiple crates live in a single GitHub repo. A common case
274
- // is a crate with an associated proc_macro crate. In such cases, the individual
275
- // crates are in subdirectories with license files at root of the repo, and
276
- // the license files don't get distributed with the crates.
277
- // So, if we didn't find a license file, try to guess the URL of the appropriate
278
- // license file and download it. This is incredibly hacky, and only supports
279
- // the most common case, which is LICENSE-APACHE.
280
- if licenses. unsatisfied . len ( ) == 1 {
281
- let req = licenses. unsatisfied . first ( ) . unwrap ( ) ;
282
- if let Some ( repository) = krate. repository ( ) {
283
- if * req == Licensee :: parse ( "Apache-2.0" ) . unwrap ( ) . into_req ( ) {
284
- let url = format ! ( "{}/master/LICENSE-APACHE" , repository) ;
285
- let body = reqwest:: blocking:: get (
286
- url. replace ( "github.com" , "raw.githubusercontent.com" ) ,
287
- ) ?
288
- . text ( ) ?;
289
- write ( krate. path ( ) . abs ( ) . join ( "LICENSE" ) , body) ?;
290
- let patch_dir = krate. path ( ) . abs ( ) . join ( "patches" ) ;
291
- create_dir ( & patch_dir) ?;
292
- let output = Command :: new ( "diff" )
293
- . args ( [ "-u" , "/dev/null" , "LICENSE" ] )
294
- . current_dir ( krate. path ( ) . abs ( ) )
295
- . output ( ) ?;
296
- write ( patch_dir. join ( "LICENSE.patch" ) , output. stdout ) ?;
297
- satisfied = true ;
298
- }
299
- }
300
- }
301
- if !satisfied {
302
- return Err ( anyhow ! (
303
- "Could not find license files for all licenses. Missing {}" ,
304
- licenses. unsatisfied. iter( ) . join( ", " )
305
- ) ) ;
306
- }
307
- }
308
-
309
- // If there's a single applicable license file, symlink it to LICENSE.
310
- if licenses. satisfied . len ( ) == 1 && licenses. unsatisfied . is_empty ( ) {
311
- let license_file = krate. path ( ) . join ( "LICENSE" ) ?;
312
- if !license_file. abs ( ) . exists ( ) {
313
- symlink ( licenses. satisfied . iter ( ) . next ( ) . unwrap ( ) . 1 , license_file) ?;
314
- }
315
- }
316
-
317
269
update_module_license_files ( & krate. path ( ) . abs ( ) , & licenses) ?;
318
270
319
271
println ! ( " Creating METADATA" ) ;
@@ -335,12 +287,45 @@ impl ManagedRepo {
335
287
} else {
336
288
write ( krate. path ( ) . abs ( ) . join ( "cargo_embargo.json" ) , "{}" ) ?;
337
289
}
338
- // Workaround. Our logic for crate health assumes the crate isn't healthy if there's
339
- // no Android.bp. So create an empty one.
340
- write ( krate. path ( ) . abs ( ) . join ( "Android.bp" ) , "" ) ?;
341
290
342
- self . regenerate ( [ & crate_name] . iter ( ) ) ?;
343
- println ! ( "Please edit {} and run 'regenerate' for this crate" , managed_dir) ;
291
+ // If there's a single applicable license file, symlink it to LICENSE.
292
+ // TODO: Move this logic into regenerate, and improve it.
293
+ if licenses. satisfied . len ( ) == 1 && licenses. unsatisfied . is_empty ( ) {
294
+ let license_file = krate. path ( ) . join ( "LICENSE" ) ?;
295
+ if !license_file. abs ( ) . exists ( ) {
296
+ symlink ( licenses. satisfied . iter ( ) . next ( ) . unwrap ( ) . 1 , license_file) ?;
297
+ }
298
+ }
299
+
300
+ if !licenses. unsatisfied . is_empty ( ) {
301
+ println ! (
302
+ r#"
303
+ Unable to find license files for the following license terms: {:?}
304
+
305
+ Please look in {managed_dir} and try to locate the license file
306
+
307
+ If you find the license file:
308
+ * That means there's a bug in our detection logic.
309
+ * Please file a bug at http://go/android-rust-crate-bug
310
+
311
+ If you can't find the license file:
312
+ * This is usually because the source repo for the crate contains several crates in
313
+ separate directories, with a license file at the root level that's not included in
314
+ each crate
315
+ * Please go to the upstream repo for the crate at {}
316
+ * Download the license file and create a patch for it. Instructions for creating patches
317
+ are at https://android.googlesource.com/platform/external/rust/android-crates-io/+/refs/heads/main/README.md#how-to-add-a-patch-file
318
+ * Run `crate_tool regenerate {}` after you have added a patch for the license file
319
+
320
+ We apologize for the inconvenience."# ,
321
+ licenses. unsatisfied. iter( ) . map( |u| u. to_string( ) ) . join( ", " ) ,
322
+ krate. repository( ) . unwrap_or( "(Crate repository URL not found in Cargo.toml)" ) ,
323
+ krate. name( )
324
+ ) ;
325
+ } else {
326
+ self . regenerate ( [ & crate_name] . iter ( ) ) ?;
327
+ println ! ( "Please edit {} and run 'regenerate' for this crate" , managed_dir) ;
328
+ }
344
329
345
330
Ok ( ( ) )
346
331
}
0 commit comments