ognibuild 0.2.12

Detect and run any build system
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
use clap::{Parser, Subcommand};
#[cfg(feature = "breezy")]
use breezyshim::branch::Branch;
use ognibuild::analyze::AnalyzedError;
use ognibuild::buildsystem::{
    detect_buildsystems, supported_buildsystem_names, BuildSystem, DependencyCategory, Error,
};
use ognibuild::dependency::Dependency;
use ognibuild::fix_build::BuildFixer;
use ognibuild::installer::{
    auto_installer, select_installers, Error as InstallerError, Explanation, InstallationScope,
    Installer,
};
use ognibuild::session::Session;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;
#[cfg(feature = "breezy")]
use url::Url;

/// Check if network access is disabled via the OGNIBUILD_DISABLE_NET environment variable.
///
/// Network access is disabled if OGNIBUILD_DISABLE_NET is set to "1", "true", "yes", or "on" (case-insensitive).
///
/// # Arguments
/// * `env_getter` - Function to get environment variable value
///
/// # Returns
/// `true` if network access should be disabled, `false` otherwise
fn is_network_disabled_with<F>(env_getter: F) -> bool
where
    F: Fn(&str) -> Option<String>,
{
    match env_getter("OGNIBUILD_DISABLE_NET") {
        Some(val) => {
            let val = val.to_lowercase();
            val == "1" || val == "true" || val == "yes" || val == "on"
        }
        None => false,
    }
}

/// Check if network access is disabled via the OGNIBUILD_DISABLE_NET environment variable.
///
/// Network access is disabled if OGNIBUILD_DISABLE_NET is set to "1", "true", "yes", or "on" (case-insensitive).
///
/// # Returns
/// `true` if network access should be disabled, `false` otherwise
fn is_network_disabled() -> bool {
    is_network_disabled_with(|key| std::env::var(key).ok())
}

#[derive(Parser)]
struct ExecArgs {
    #[clap(name = "subargv", trailing_var_arg = true)]
    subargv: Vec<String>,
}

#[derive(Parser)]
struct InstallArgs {
    #[clap(long)]
    prefix: Option<PathBuf>,
}

#[derive(Parser)]
struct CacheEnvArgs {
    /// Debian suite to cache (e.g., "sid", "bookworm", "stable")
    #[clap(default_value = "sid")]
    suite: String,

    /// Force re-download even if cached
    #[clap(long)]
    force: bool,
}

#[derive(Subcommand)]
enum Command {
    #[clap(name = "dist")]
    /// Create a distribution package/tarball
    Dist,
    #[clap(name = "build")]
    /// Build the project
    Build,
    #[clap(name = "clean")]
    /// Clean build artifacts
    Clean,
    #[clap(name = "test")]
    /// Run tests
    Test,
    #[clap(name = "info")]
    /// Display build system information and dependencies
    Info,
    #[clap(name = "verify")]
    /// Build and run tests
    Verify,
    #[clap(name = "exec")]
    /// Execute a command with automatic dependency resolution
    Exec(ExecArgs),
    #[clap(name = "install")]
    /// Install the project
    Install(InstallArgs),
    #[clap(name = "cache-env")]
    /// Cache a Debian cloud image for use with UnshareSession
    CacheEnv(CacheEnvArgs),
}

#[derive(Parser)]
struct Args {
    #[clap(subcommand)]
    command: Option<Command>,

    #[clap(long, short, default_value = ".")]
    directory: String,

    #[cfg(target_os = "linux")]
    #[clap(long)]
    schroot: Option<String>,

    #[clap(long, short, default_value = "auto", use_value_delimiter = true)]
    installer: Vec<String>,

    #[clap(long, hide = true)]
    apt: bool,

    #[clap(long, hide = true)]
    native: bool,

    #[clap(long)]
    /// Explain what needs to be done rather than making changes
    explain: bool,

    #[clap(long)]
    /// Ignore declared dependencies, follow build errors only
    ignore_declared_dependencies: bool,

    #[clap(long)]
    /// Scope to install in
    installation_scope: Option<InstallationScope>,

    #[clap(long, env = "OGNIBUILD_DEPS")]
    /// ognibuild dep server to use
    dep_server_url: Option<url::Url>,

    #[clap(long)]
    /// Print more verbose output
    debug: bool,

    #[clap(long)]
    /// List all supported build systems
    supported_buildsystems: bool,
}

fn explain_missing_deps(
    session: &dyn Session,
    installer: &dyn Installer,
    scope: InstallationScope,
    deps: &[&dyn Dependency],
) -> Result<Vec<Explanation>, Error> {
    if deps.is_empty() {
        return Ok(vec![]);
    }
    let missing = deps
        .iter()
        .filter(|dep| !dep.present(session))
        .collect::<Vec<_>>();
    if missing.is_empty() {
        return Ok(vec![]);
    }
    Ok(missing
        .into_iter()
        .map(|dep| installer.explain(*dep, scope))
        .collect::<Result<_, _>>()?)
}

fn explain_necessary_declared_dependencies(
    session: &dyn Session,
    installer: &dyn Installer,
    fixers: &[&dyn BuildFixer<InstallerError>],
    buildsystems: &[&dyn BuildSystem],
    categories: &[DependencyCategory],
    scope: InstallationScope,
) -> Result<Vec<Explanation>, Error> {
    let mut relevant: Vec<Box<dyn Dependency>> = vec![];
    for buildsystem in buildsystems {
        let declared_deps = buildsystem.get_declared_dependencies(session, Some(fixers))?;
        for (category, dep) in declared_deps {
            if categories.contains(&category) {
                relevant.push(dep);
            }
        }
    }
    explain_missing_deps(
        session,
        installer,
        scope,
        relevant
            .iter()
            .map(|d| d.as_ref())
            .collect::<Vec<_>>()
            .as_slice(),
    )
}

fn install_necessary_declared_dependencies(
    session: &dyn Session,
    installer: &dyn Installer,
    scopes: &[InstallationScope],
    fixers: &[&dyn BuildFixer<InstallerError>],
    buildsystems: &[&dyn BuildSystem],
    categories: &[DependencyCategory],
) -> Result<(), Error> {
    for buildsystem in buildsystems {
        buildsystem.install_declared_dependencies(
            categories,
            scopes,
            session,
            installer,
            Some(fixers),
        )?;
    }
    Ok(())
}

fn run_action(
    session: &dyn Session,
    scope: InstallationScope,
    external_dir: &Path,
    installer: &dyn Installer,
    fixers: &[&dyn BuildFixer<InstallerError>],
    args: &Args,
) -> Result<(), Error> {
    if let Some(Command::Exec(ExecArgs { subargv })) = &args.command {
        ognibuild::fix_build::run_fixing_problems::<_, Error>(
            fixers,
            None,
            session,
            subargv
                .iter()
                .map(|s| s.as_str())
                .collect::<Vec<_>>()
                .as_slice(),
            false,
            None,
            None,
            None,
        )?;
        return Ok(());
    }
    let mut log_manager = ognibuild::logs::NoLogManager;
    let bss = detect_buildsystems(external_dir);
    if !args.ignore_declared_dependencies {
        let categories = match args.command.as_ref().unwrap() {
            Command::Dist => vec![],
            Command::Build => vec![DependencyCategory::Universal, DependencyCategory::Build],
            Command::Clean => vec![],
            Command::Install(_) => vec![DependencyCategory::Universal, DependencyCategory::Build],
            Command::Test => vec![
                DependencyCategory::Universal,
                DependencyCategory::Build,
                DependencyCategory::Test,
            ],
            Command::Info => vec![],
            Command::Verify => vec![
                DependencyCategory::Universal,
                DependencyCategory::Build,
                DependencyCategory::Test,
            ],
            Command::Exec(_) => vec![],
            Command::CacheEnv(_) => return Ok(()), // No dependencies needed
        };
        if !categories.is_empty() {
            log::info!("Checking that declared dependencies are present");
            if !args.explain {
                match install_necessary_declared_dependencies(
                    session,
                    installer,
                    &[scope, InstallationScope::Vendor],
                    fixers,
                    bss.iter()
                        .map(|bs| bs.as_ref())
                        .collect::<Vec<_>>()
                        .as_slice(),
                    &categories,
                ) {
                    Ok(_) => {}
                    Err(e) => {
                        log::info!("Unable to install declared dependencies: {}", e);
                        return Err(e);
                    }
                }
            } else {
                match explain_necessary_declared_dependencies(
                    session,
                    installer,
                    fixers,
                    bss.iter()
                        .map(|bs| bs.as_ref())
                        .collect::<Vec<_>>()
                        .as_slice(),
                    &categories,
                    scope,
                ) {
                    Ok(explanations) => {
                        for explanation in explanations {
                            log::info!("{}", explanation);
                        }
                    }
                    Err(e) => {
                        log::info!("Unable to explain declared dependencies",);
                        return Err(e);
                    }
                }
            }
        }
    }

    match args.command.as_ref().unwrap() {
        Command::Exec(..) => unreachable!(),
        Command::CacheEnv(..) => unreachable!(),
        Command::Dist => {
            ognibuild::actions::dist::run_dist(
                session,
                bss.iter()
                    .map(|bs| bs.as_ref())
                    .collect::<Vec<_>>()
                    .as_slice(),
                installer,
                fixers,
                Path::new("."),
                false,
                &mut log_manager,
            )?;
        }
        Command::Build => {
            ognibuild::actions::build::run_build(
                session,
                bss.iter()
                    .map(|bs| bs.as_ref())
                    .collect::<Vec<_>>()
                    .as_slice(),
                installer,
                fixers,
                &mut log_manager,
            )?;
        }
        Command::Clean => {
            ognibuild::actions::clean::run_clean(
                session,
                bss.iter()
                    .map(|bs| bs.as_ref())
                    .collect::<Vec<_>>()
                    .as_slice(),
                installer,
                fixers,
                &mut log_manager,
            )?;
        }
        Command::Install(install_args) => {
            ognibuild::actions::install::run_install(
                session,
                bss.iter()
                    .map(|bs| bs.as_ref())
                    .collect::<Vec<_>>()
                    .as_slice(),
                installer,
                fixers,
                &mut log_manager,
                scope,
                install_args.prefix.as_deref(),
            )?;
        }
        Command::Test => {
            ognibuild::actions::test::run_test(
                session,
                bss.iter()
                    .map(|bs| bs.as_ref())
                    .collect::<Vec<_>>()
                    .as_slice(),
                installer,
                fixers,
                &mut log_manager,
            )?;
        }
        Command::Info => {
            ognibuild::actions::info::run_info(
                session,
                bss.iter()
                    .map(|bs| bs.as_ref())
                    .collect::<Vec<_>>()
                    .as_slice(),
                Some(fixers),
            )?;
        }
        Command::Verify => {
            ognibuild::actions::build::run_build(
                session,
                bss.iter()
                    .map(|bs| bs.as_ref())
                    .collect::<Vec<_>>()
                    .as_slice(),
                installer,
                fixers,
                &mut log_manager,
            )?;
            ognibuild::actions::test::run_test(
                session,
                bss.iter()
                    .map(|bs| bs.as_ref())
                    .collect::<Vec<_>>()
                    .as_slice(),
                installer,
                fixers,
                &mut log_manager,
            )?;
        }
    }
    Ok(())
}

fn main() -> Result<(), i32> {
    let mut args = Args::parse();

    if args.supported_buildsystems {
        for bs in supported_buildsystem_names() {
            println!("{}", bs);
        }
        return Ok(());
    }

    // Check if command is provided
    let command = match args.command {
        Some(cmd) => cmd,
        None => {
            eprintln!("Error: No command provided");
            return Err(1);
        }
    };
    args.command = Some(command);

    env_logger::builder()
        .format(|buf, record| writeln!(buf, "{}", record.args()))
        .filter(
            None,
            if args.debug {
                log::LevelFilter::Debug
            } else {
                log::LevelFilter::Info
            },
        )
        .init();

    // Handle cache-env command separately as it doesn't need a session
    if let Some(Command::CacheEnv(ref cache_args)) = args.command {
        return cache_debian_image(&cache_args.suite, cache_args.force);
    }

    #[cfg(target_os = "linux")]
    let mut session: Box<dyn Session> = if let Some(schroot) = args.schroot.as_ref() {
        Box::new(ognibuild::session::schroot::SchrootSession::new(schroot, None).unwrap())
    } else {
        Box::new(ognibuild::session::plain::PlainSession::new())
    };

    #[cfg(not(target_os = "linux"))]
    let mut session: Box<dyn Session> = Box::new(ognibuild::session::plain::PlainSession::new());

    #[cfg(feature = "breezy")]
    let url = if let Ok(url) = args.directory.parse::<url::Url>() {
        url
    } else {
        let p = Path::new(&args.directory);
        url::Url::from_directory_path(p.canonicalize().unwrap()).unwrap()
    };
    #[cfg(feature = "breezy")]
    let mut td: Option<tempfile::TempDir> = None;
    // TODO(jelmer): Get a list of supported schemes from breezy?
    #[cfg(feature = "breezy")]
    let project = if ["git", "http", "https", "ssh"].contains(&url.scheme()) {
        let b = breezyshim::branch::open_as_generic(&url).unwrap();
        log::info!("Cloning {}", args.directory);
        td = Some(tempfile::tempdir().unwrap());
        let to_dir = b
            .controldir()
            .sprout(
                Url::from_directory_path(td.as_ref().unwrap().path()).unwrap(),
                None,
                Some(true),
                None,
                None,
            )
            .unwrap();
        let wt = to_dir.open_workingtree().unwrap();
        session.project_from_vcs(&wt, None, None).unwrap()
    } else {
        let directory = if url.scheme() == "file" {
            Path::new(url.path()).to_path_buf()
        } else {
            PathBuf::from(args.directory.clone())
        };
        log::info!("Preparing directory {}", directory.display());
        session.project_from_directory(&directory, None).unwrap()
    };

    #[cfg(not(feature = "breezy"))]
    let project = {
        let directory = PathBuf::from(args.directory.clone());
        log::info!("Preparing directory {}", directory.display());
        session.project_from_directory(&directory, None).unwrap()
    };

    session.chdir(project.internal_path()).unwrap();
    std::env::set_current_dir(project.external_path()).unwrap();

    if !session.is_temporary() && matches!(args.command, Some(Command::Info)) {
        args.explain = true;
    }

    if args.apt {
        args.installer = vec!["apt".to_string()];
    }

    if args.native {
        args.installer = vec!["native".to_string()];
    }

    let scope = if let Some(scope) = args.installation_scope {
        scope
    } else if args.explain {
        InstallationScope::Global
    } else if args.installer.contains(&"apt".to_string()) {
        InstallationScope::Global
    } else {
        ognibuild::installer::auto_installation_scope(session.as_ref())
    };

    let installer: Box<dyn Installer> = if args.installer == ["auto"] {
        auto_installer(session.as_ref(), scope, args.dep_server_url.as_ref())
    } else {
        select_installers(
            session.as_ref(),
            args.installer
                .iter()
                .map(|x| x.as_str())
                .collect::<Vec<_>>()
                .as_slice(),
            args.dep_server_url.as_ref(),
        )
        .unwrap()
    };

    let fixers: Vec<Box<dyn BuildFixer<InstallerError>>> = if !args.explain {
        vec![Box::new(ognibuild::fixers::InstallFixer::new(
            installer.as_ref(),
            scope,
        ))]
    } else {
        vec![]
    };

    match run_action(
        session.as_ref(),
        scope,
        project.external_path(),
        installer.as_ref(),
        fixers
            .iter()
            .map(|f| f.as_ref())
            .collect::<Vec<_>>()
            .as_slice(),
        &args,
    ) {
        Ok(_) => {}
        Err(Error::NoBuildSystemDetected) => {
            log::info!("No build tools found.");
            return Err(1);
        }
        Err(Error::DependencyInstallError(e)) => {
            log::info!("Dependency installation failed: {}", e);
            return Err(1);
        }
        Err(Error::Unimplemented) => {
            log::info!("This command is not yet implemented.");
            return Err(1);
        }
        Err(Error::Error(AnalyzedError::Unidentified { .. })) => {
            log::info!(
                "If there is a clear indication of a problem in the build log, please consider filing a request to update the patterns in buildlog-consultant at https://github.com/jelmer/buildlog-consultant/issues/new");
            return Err(1);
        }
        Err(Error::Error(AnalyzedError::Detailed { error, .. })) => {
            log::info!("Detailed error: {}", error);
            log::info!(
                "Please consider filing a bug report at https://github.com/jelmer/ognibuild/issues/new"
            );
        }
        Err(e) => {
            log::info!("Error: {}", e);
            return Err(1);
        }
    }

    #[cfg(feature = "breezy")]
    std::mem::drop(td);
    Ok(())
}

#[cfg(target_os = "linux")]
fn cache_debian_image(suite: &str, force: bool) -> Result<(), i32> {
    if is_network_disabled() {
        eprintln!("Error: Network access is disabled (OGNIBUILD_DISABLE_NET is set)");
        eprintln!("Cannot download Debian image without network access.");
        return Err(1);
    }

    let arch = std::env::consts::ARCH;
    let arch_name = match arch {
        "x86_64" => "amd64",
        "aarch64" => "arm64",
        _ => {
            eprintln!("Unsupported architecture: {}", arch);
            return Err(1);
        }
    };

    let cache_dir = match dirs::cache_dir() {
        Some(dir) => dir.join("ognibuild").join("images"),
        None => {
            eprintln!("Cannot determine cache directory");
            return Err(1);
        }
    };

    if let Err(e) = std::fs::create_dir_all(&cache_dir) {
        eprintln!("Failed to create cache directory: {}", e);
        return Err(1);
    }

    let tarball_name = format!("debian-{}-{}.tar.gz", suite, arch_name);
    let tarball_path = cache_dir.join(&tarball_name);

    if tarball_path.exists() && !force {
        log::info!(
            "Debian {} image already cached at {}",
            suite,
            tarball_path.display()
        );
        log::info!("Use --force to re-download.");
        return Ok(());
    }

    // Bootstrap a Debian session using mmdebstrap and save it
    log::info!("Bootstrapping Debian {} image using mmdebstrap...", suite);
    match ognibuild::session::unshare::bootstrap_debian_tarball(suite, true) {
        Ok(session) => {
            // Save the bootstrapped session to the cache
            log::info!("Saving to cache: {}", tarball_path.display());
            match session.save_to_tarball(&tarball_path) {
                Ok(_) => {
                    log::info!(
                        "Successfully cached Debian {} image at {}",
                        suite,
                        tarball_path.display()
                    );
                    log::info!("");
                    log::info!("This cached image will now be used automatically by tests.");
                    log::info!("You can also explicitly use it by setting:");
                    log::info!("  OGNIBUILD_DEBIAN_TEST_TARBALL={}", tarball_path.display());
                    Ok(())
                }
                Err(e) => {
                    eprintln!("Failed to save tarball: {}", e);
                    Err(1)
                }
            }
        }
        Err(e) => {
            eprintln!("Failed to bootstrap image: {}", e);
            Err(1)
        }
    }
}

#[cfg(not(target_os = "linux"))]
fn cache_debian_image(_suite: &str, _force: bool) -> Result<(), i32> {
    eprintln!("Error: cache-env command is only available on Linux");
    Err(1)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_is_network_disabled_not_set() {
        use std::collections::HashMap;
        let env: HashMap<String, String> = HashMap::new();
        assert!(!is_network_disabled_with(|key| env.get(key).cloned()));
    }

    #[test]
    fn test_is_network_disabled_true() {
        use std::collections::HashMap;

        let mut env = HashMap::new();
        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "1".to_string());
        assert!(is_network_disabled_with(|key| env.get(key).cloned()));

        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "true".to_string());
        assert!(is_network_disabled_with(|key| env.get(key).cloned()));

        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "TRUE".to_string());
        assert!(is_network_disabled_with(|key| env.get(key).cloned()));

        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "yes".to_string());
        assert!(is_network_disabled_with(|key| env.get(key).cloned()));

        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "YES".to_string());
        assert!(is_network_disabled_with(|key| env.get(key).cloned()));

        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "on".to_string());
        assert!(is_network_disabled_with(|key| env.get(key).cloned()));

        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "ON".to_string());
        assert!(is_network_disabled_with(|key| env.get(key).cloned()));
    }

    #[test]
    fn test_is_network_disabled_false() {
        use std::collections::HashMap;

        let mut env = HashMap::new();
        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "0".to_string());
        assert!(!is_network_disabled_with(|key| env.get(key).cloned()));

        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "false".to_string());
        assert!(!is_network_disabled_with(|key| env.get(key).cloned()));

        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "no".to_string());
        assert!(!is_network_disabled_with(|key| env.get(key).cloned()));

        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "off".to_string());
        assert!(!is_network_disabled_with(|key| env.get(key).cloned()));

        env.insert("OGNIBUILD_DISABLE_NET".to_string(), "random".to_string());
        assert!(!is_network_disabled_with(|key| env.get(key).cloned()));
    }
}