chapel icon indicating copy to clipboard operation
chapel copied to clipboard

should `checkModule` in `masonPublish` only count files?

Open lucaferranti opened this issue 9 months ago • 3 comments

Currently checkModule does

/* Checks to make sure the package only has one main module
 */
private proc moduleCheck(projectHome : string) throws {
  const subModules = listDir(projectHome + '/src');
  if subModules.size > 1 then return false;
  else return true;
}

hence listDir will count both files and directories, hence if my file has a structure

M.chpl
M/
    L.chpl

subModules will be 2, leading the test to fail, despite it has only one submodule and one main module. Currently the function checks that the src folder has only one child. Currently I think that test will only pass if src has exactly one file and no subdirectories.

Moreover, I am a bit puzzled by the soundness of the check, the idea of the function is to check that the function has only one main module. Shouldn't the correct logic be something like

private proc moduleCheck(projectHome : string) throws {
  const mainModules = listDir(projectHome + '/src', dirs=false); // count only files, ideally filter for only .chpl ones
  if mainModules.size == 1 then return true;
  else return false;
}

This would rely on the following assumptions

  1. files in src are considered main modules
  2. files in subfolders are submodules

which I believe is more in line with what described here and here.

on the other hand the documentation also says

For packages that span multiple files, the main module is designated by the module that shares the name with the package directory and the name field in the Mason.toml file.

so one could also use this logic in the check, although not sure if the compiler is aware of this.

lucaferranti avatar May 16 '24 20:05 lucaferranti