Repository navigation
fix(build): Disallow --build-dir to resolve to cwd - #1403
Conversation
| default=DEFAULT_BUILD_DIR, | ||
| type=click.Path(file_okay=False, dir_okay=True, writable=True), # Must be a directory | ||
| help="Path to a folder where the built artifacts will be stored") | ||
| help="Path to a folder where the built artifacts will be stored. If a clean build, this directory will be first removed.") |
There was a problem hiding this comment.
we always do a clean build. So the 'if' shouldn't be necessary
There was a problem hiding this comment.
The wording was future looking. I can remove. Do we even mention clean build is all we support anywhere today?
| build_path = pathlib.Path(build_dir) | ||
|
|
||
| if os.path.abspath(str(build_path)) == os.path.abspath(str(pathlib.Path.cwd())): | ||
| exception_message = "'build-dir' should not be the current workding directoy as the directory " \ |
There was a problem hiding this comment.
can we instead skip the "clean" if build-dir == cwd? It could give to a more intuitive experience
There was a problem hiding this comment.
Not sure I completely understand. My current understanding of the question is:
"Instead of always doing a "clean" build, we would not do a clean build if build-dir == cwd"?
If that is a fair rewording, then I don't think we should go down this route. Having a conditional do clean or not base upon a parameter that does not relate to a 'clean build' is not intuitive at all. This will make supporting clean builds more difficult in the future.
sam build removes the build dir before building. aws#1403 refused a build dir equal to the current working directory, but other cases slipped through: - A build dir that contains the project: `sam build --build-dir ..`, or `sam build -t proj/template.yaml --build-dir proj` run from proj's parent, deletes the template and source (and, for `..`, everything beside the project). These are now refused: the build dir must not be or contain the working directory, the template's directory or the base dir. The comparison is case-insensitive on Windows. - .aws-sam itself, or the cache or deps dir: `--build-dir .aws-sam` deletes SAM CLI's own state on every build -- the build cache and dependencies (so --cached never hits) and the committed pipeline config written by `sam pipeline bootstrap` -- and writes build.toml into the project root. Some users may pass this today, so it now logs a warning that it will not be supported in a future release, and still builds. No warning is logged for a non-clean build, which removes nothing. .aws-sam/build (the default), .aws-sam/auto-dependency-layer (used by sam sync) and directories outside the project are unaffected.
sam build removes the build dir before building. aws#1403 refused a build dir equal to the current working directory, but other cases slipped through: - A build dir that contains the project: `sam build --build-dir ..`, or `sam build -t proj/template.yaml --build-dir proj` run from proj's parent, deletes the template and source (and, for `..`, everything beside the project). These are now refused: the build dir must not be or contain the working directory, the template's directory or the base dir. The comparison is case-insensitive on Windows. - .aws-sam itself, or the cache or deps dir: `--build-dir .aws-sam` deletes SAM CLI's own state on every build -- the build cache and dependencies (so --cached never hits) and the committed pipeline config written by `sam pipeline bootstrap` -- and writes build.toml into the project root. Some users may pass this today, so it now logs a warning that it will not be supported in a future release, and still builds. No warning is logged for a non-clean build, which removes nothing. .aws-sam/build (the default), .aws-sam/auto-dependency-layer (used by sam sync) and directories outside the project are unaffected.
sam build removes the build dir before building. #1403 refused a build dir equal to the current working directory, but other cases slipped through: - A build dir that contains the project: `sam build --build-dir ..`, or `sam build -t proj/template.yaml --build-dir proj` run from proj's parent, deletes the template and source (and, for `..`, everything beside the project). These are now refused: the build dir must not be or contain the working directory, the template's directory or the base dir. The comparison is case-insensitive on Windows. - .aws-sam itself, or the cache or deps dir: `--build-dir .aws-sam` deletes SAM CLI's own state on every build -- the build cache and dependencies (so --cached never hits) and the committed pipeline config written by `sam pipeline bootstrap` -- and writes build.toml into the project root. Some users may pass this today, so it now logs a warning that it will not be supported in a future release, and still builds. No warning is logged for a non-clean build, which removes nothing. .aws-sam/build (the default), .aws-sam/auto-dependency-layer (used by sam sync) and directories outside the project are unaffected.
Issue #, if available:
#1157
Description of changes:
Checklist:
make prpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.