Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions test/mason/SKIPIF
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python3
#!/usr/bin/env bash

"""
mason requires CHPL_COMM=none (local)
"""

from __future__ import print_function
from os import environ

print(environ['CHPL_COMM'] != 'none' or environ['CHPL_RE2'] == 'none' or environ['CHPL_LAUNCHER'] != 'none')
if [[ "$CHPL_COMM" != "none" || "$CHPL_RE2" == "none" || "$CHPL_LAUNCHER" != "none" ]]; then
echo "True"
else
if command -v chplcheck >/dev/null 2>&1; then
echo "False"
else
echo "True"
fi
fi
1 change: 1 addition & 0 deletions test/mason/mason-lint/COMPOPTS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-M ../../../tools/mason/
1 change: 1 addition & 0 deletions test/mason/mason-lint/EXECENV
Empty file.
3 changes: 3 additions & 0 deletions test/mason/mason-lint/Pkg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
Mason.lock
doc
9 changes: 9 additions & 0 deletions test/mason/mason-lint/Pkg/Mason.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[brick]
name = "Pkg"
version = "0.1.0"
chplVersion = "1.20.0"

[dependencies]

[tool.chplcheck]
disable-rule = ["IncorrectIndentation"]
5 changes: 5 additions & 0 deletions test/mason/mason-lint/Pkg/example/myExample.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use Pkg;
config var doit = false;
if doit == true {
foo();
}
4 changes: 4 additions & 0 deletions test/mason/mason-lint/Pkg/src/Pkg.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Documentation for Pkg */
module Pkg {
proc Foo() { }
}
8 changes: 8 additions & 0 deletions test/mason/mason-lint/Pkg/test/myTest.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use UnitTest;

proc test(test: borrowed Test) throws {
test.assertTrue(true);
test.assertFalse(false);
}

UnitTest.main();
1 change: 1 addition & 0 deletions test/mason/mason-lint/SKIPIF
22 changes: 22 additions & 0 deletions test/mason/mason-lint/lint.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use FileSystem, IO;

use MasonLint only;
use MasonUtils only;

here.chdir('Pkg');

try! {
MasonLint.masonLint(["lint"]);
writeln("Error: linting passed unexpectedly");
} catch e: MasonUtils.MasonError {
writeln("Got Lints as expected - ", e.message());
}

try! {
// TODO: passing cli args overrides whats in the config file
// https://github.com/chapel-lang/chapel/issues/28330
MasonLint.masonLint(["lint", "--", "--disable-rule=CamelCaseFunctions"]);
writeln("Error: linting passed unexpectedly");
} catch e: MasonUtils.MasonError {
writeln("Got Lints as expected - ", e.message());
}
6 changes: 6 additions & 0 deletions test/mason/mason-lint/lint.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
src/Pkg.chpl:3: node violates rule CamelCaseFunctions
example/myExample.chpl:3: node violates rule BoolComparison
Got Lints as expected - chplcheck found issues
test/myTest.chpl:5: node violates rule IncorrectIndentation
example/myExample.chpl:3: node violates rule BoolComparison
Got Lints as expected - chplcheck found issues
8 changes: 5 additions & 3 deletions tools/mason/Mason.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module Mason {
use MasonExternal;
use MasonHelp;
use MasonInit;
use MasonLint;
use MasonModify;
use MasonNew;
use MasonPublish;
Expand All @@ -84,9 +85,9 @@ module Mason {
var subCmds = new map(string, shared Argument);

// define all the supported subcommand strings here
var cmds = ["add","build","clean","doc","env","external","init","publish",
"new","rm","run","search","system","test","update",
"help","version","modules"];
const cmds = ["add","build","clean","doc","env","external","init","lint",
"publish","new","rm","run","search","system","test","update",
"help","version","modules"];
for cmd in cmds {
subCmds.add(cmd,parser.addSubCommand(cmd));
}
Expand Down Expand Up @@ -131,6 +132,7 @@ module Mason {
when "external" do masonExternal(cmdArgs);
when "help" do masonHelp();
when "init" do masonInit(cmdArgs);
when "lint" do masonLint(cmdArgs);
when "new" do masonNew(cmdArgs);
when "publish" do masonPublish(cmdArgs);
when "rm" do masonModify(cmdArgs);
Expand Down
27 changes: 27 additions & 0 deletions tools/mason/MasonHelp.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ class MasonModulesHelpHandler : HelpHandler {
}
}

class MasonLintHelpHandler: HelpHandler {
override proc printHelp() {
masonLintHelp();
}
}

proc masonHelp() {
writeln("Chapel's package manager");
writeln();
Expand Down Expand Up @@ -620,3 +626,24 @@ proc masonModulesHelp() {
writeln(' mason modules');
writeln();
}

proc masonLintHelp() {
const s = """
Check the mason package for any style or formatting issues"

Usage:
mason doc [options] [-- <chplcheck options>...]

Options:
-h, --help Display this message

Extra options can be passed to chplcheck after a double dash (`--`).
Alternatively, chplcheck can be configured in the Mason.toml file under
the [tool.chplcheck] table.

Requires that chplcheck is set up in order to work.
For instructions on setting up chplcheck, please view its documentation.
""".dedent().strip();
writeln(s);
writeln();
}
72 changes: 72 additions & 0 deletions tools/mason/MasonLint.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2020-2026 Hewlett Packard Enterprise Development LP
* Copyright 2004-2019 Cray Inc.
* Other additional copyright holders may be indicated within.
*
* The entirety of this work is licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module MasonLint {
use ArgumentParser;
use FileSystem;
use IO;
import MasonHelp;
import MasonUtils;
import MasonUtils.MasonError;
import MasonLogger;
use List only list;

private var log = new MasonLogger.logger("mason lint");

proc masonLint(args: [] string) throws {

var parser =
new argumentParser(helpHandler=new MasonHelp.MasonLintHelpHandler());
var passArgs = parser.addPassThrough();
parser.parseArgs(args);

const tomlName = 'Mason.toml';
const cwd = here.cwd();

const projectHome = MasonUtils.getProjectHome(cwd, tomlName);
here.chdir(projectHome);

if MasonUtils.runWithStatus("chplcheck --version", quiet=true) != 0 {
throw new MasonError("chplcheck is not installed or not found in PATH");
}

const cmd = new list([
"chplcheck",
"-c",
"Mason.toml",
"src/**/*.chpl",
"test/**/*.chpl",
"example/**/*.chpl",
]);
cmd.pushBack(passArgs.values());
const cmdArr = cmd.toArray();
const cmdStr = " ".join(cmdArr);
log.infoln(cmdStr);
const output =
MasonUtils.runCommand(cmdStr, quiet=true, errorOk=true).strip();

if output != "" {
// change projectHome to "" to make output paths relative
const filtered = output.replace(projectHome + "/", "");
writeln(filtered);
throw new MasonError("chplcheck found issues");
}
}
}
8 changes: 4 additions & 4 deletions tools/mason/MasonUtils.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ proc stripExt(toStrip: string, ext: string) : string {


/* Uses the Subprocess module to create a subprocess */
proc runCommand(cmd: [] string, quiet=false) : string throws {
proc runCommand(cmd: [] string, quiet=false, errorOk=false) : string throws {
var ret : string;
try {
log.debugf("runCommand: %?\n", cmd);
Expand All @@ -125,7 +125,7 @@ proc runCommand(cmd: [] string, quiet=false) : string throws {
process.wait();

log.debugf("exitCode: %i\n", process.exitCode);
if process.exitCode != 0 {
if !errorOk && process.exitCode != 0 {
var cmdStr = " ".join(cmd);
throw new owned MasonError("Command failed: '" + cmdStr + "'");
}
Expand All @@ -141,10 +141,10 @@ proc runCommand(cmd: [] string, quiet=false) : string throws {
}
return ret;
}
proc runCommand(cmd: string, quiet=false) : string throws {
proc runCommand(cmd: string, quiet=false, errorOk=false) : string throws {
// temporary is a workaround for #27504
const cmds = cmd.split();
return runCommand(cmds, quiet=quiet);
return runCommand(cmds, quiet=quiet, errorOk=errorOk);
}


Expand Down
2 changes: 1 addition & 1 deletion util/cron/test-linux64.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ source $UTIL_CRON_DIR/common-localnode-paratest.bash

export CHPL_NIGHTLY_TEST_CONFIG_NAME="linux64"

$UTIL_CRON_DIR/nightly -cron -mason -protobuf -futures ${nightly_args} $(get_nightly_paratest_args 8)
$UTIL_CRON_DIR/nightly -cron -mason -chplcheck -protobuf -futures ${nightly_args} $(get_nightly_paratest_args 8)