Skip to content

Commit

Permalink
[devtools] add ability to skip license files and fix helm
Browse files Browse the repository at this point in the history
* terraform requires certain files to not have a license
* x lint didn't support that, so now it does
* lint didn't like terraform/helm -> ../helm, so removing that for now
  • Loading branch information
davidiw committed Mar 1, 2022
1 parent d15fd2d commit 0e80b19
Show file tree
Hide file tree
Showing 127 changed files with 53 additions and 9 deletions.
7 changes: 5 additions & 2 deletions config/management/operational/src/network_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ impl CheckEndpoint {
self.address,
timeout,
self.no_handshake,
).await
)
.await
}
}

Expand Down Expand Up @@ -193,7 +194,9 @@ impl CheckValidatorSetEndpoints {
// Check all the addresses accordingly
for (name, peer_id, addrs) in nodes {
for addr in addrs {
match check_endpoint(upgrade_context.clone(), addr, timeout, self.no_handshake).await {
match check_endpoint(upgrade_context.clone(), addr, timeout, self.no_handshake)
.await
{
Ok(_) => println!("{} -- good", name),
Err(err) => println!("{} : {} -- bad -- {}", name, peer_id, err),
};
Expand Down
2 changes: 2 additions & 0 deletions devtools/x/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ pub struct WorkspaceConfig {
pub banned_deps: BannedDepsConfig,
/// Direct dep duplicate lint config
pub direct_dep_dups: DirectDepDupsConfig,
/// Exceptions to license linters
pub license_exceptions: Vec<String>,
/// Overlay config in this workspace
pub overlay: OverlayConfig,
/// Test-only config in this workspace
Expand Down
42 changes: 38 additions & 4 deletions devtools/x/src/lint/license.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use anyhow::Context;
use globset::{Glob, GlobSet, GlobSetBuilder};
use std::collections::HashSet;
use x_lint::prelude::*;

Expand All @@ -9,20 +11,28 @@ static LICENSE_HEADER: &str = "\
";

#[derive(Copy, Clone, Debug)]
pub(super) struct LicenseHeader;
pub(super) struct LicenseHeader<'cfg> {
exceptions: &'cfg GlobSet,
}

impl Linter for LicenseHeader {
impl<'cfg> Linter for LicenseHeader<'cfg> {
fn name(&self) -> &'static str {
"license-header"
}
}

impl ContentLinter for LicenseHeader {
impl<'cfg> LicenseHeader<'cfg> {
pub fn new(exceptions: &'cfg GlobSet) -> Self {
Self { exceptions }
}
}

impl<'cfg> ContentLinter for LicenseHeader<'cfg> {
fn pre_run<'l>(&self, file_ctx: &FilePathContext<'l>) -> Result<RunStatus<'l>> {
// TODO: Add a way to pass around state between pre_run and run, so that this computation
// only needs to be done once.
match FileType::new(file_ctx) {
Some(_) => Ok(RunStatus::Executed),
Some(_) => Ok(skip_license_checks(self.exceptions, file_ctx)),
None => Ok(RunStatus::Skipped(SkipReason::UnsupportedExtension(
file_ctx.extension(),
))),
Expand Down Expand Up @@ -96,3 +106,27 @@ impl FileType {
}
}
}

pub(super) fn build_exceptions(patterns: &[String]) -> crate::Result<GlobSet> {
let mut builder = GlobSetBuilder::new();
for pattern in patterns {
let glob = Glob::new(pattern).with_context(|| {
format!(
"error while processing license exception glob '{}'",
pattern
)
})?;
builder.add(glob);
}
builder
.build()
.with_context(|| "error while building globset for license patterns")
}

fn skip_license_checks<'l>(exceptions: &GlobSet, file: &FilePathContext<'l>) -> RunStatus<'l> {
if exceptions.is_match(file.file_path()) {
return RunStatus::Skipped(SkipReason::UnsupportedFile(file.file_path()));
}

RunStatus::Executed
}
3 changes: 2 additions & 1 deletion devtools/x/src/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ pub fn run(args: Args, xctx: XContext) -> crate::Result<()> {

let whitespace_exceptions =
whitespace::build_exceptions(&workspace_config.whitespace_exceptions)?;
let license_exceptions = license::build_exceptions(&workspace_config.license_exceptions)?;
let content_linters: &[&dyn ContentLinter] = &[
&license::LicenseHeader,
&license::LicenseHeader::new(&license_exceptions),
&toml::RootToml,
&whitespace::EofNewline::new(&whitespace_exceptions),
&whitespace::TrailingWhitespace::new(&whitespace_exceptions),
Expand Down
1 change: 0 additions & 1 deletion terraform/helm

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion x.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ whitespace-exceptions = [
"**/*.exp",
"**/*.errmap",
"**/*.abi",
"terraform/**/*",
]

license-exceptions = [
"terraform/**/*",
]

[workspace.enforced-attributes]
Expand Down Expand Up @@ -258,7 +263,7 @@ mark-changed = "all"

[[determinator.path-rule]]
# Ignore website and other ancillary files, and scripts not listed above.
globs = ["developers.diem.com/**/*", "developer-docs-site/**/*", "documentation/**/*", "docker/**/*", "helm/**/*", "language/documentation/**/*", "specifications/**/*", "scripts/**/*", "terraform/**/*"]
globs = ["developers.diem.com/**/*", "developer-docs-site/**/*", "documentation/**/*", "docker/**/*", "language/documentation/**/*", "specifications/**/*", "scripts/**/*", "terraform/**/*"]
mark-changed = []

[[determinator.path-rule]]
Expand Down

0 comments on commit 0e80b19

Please sign in to comment.