Skip to content

Commit

Permalink
add symbols path config & enumarate known build dir paths
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Nov 4, 2024
1 parent 716995e commit 41ed7e8
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sentry:
dist: ...
build_path: ...
web_build_path: ...
symbols_path: ...
commits: auto
ignore_missing: true
```
Expand Down Expand Up @@ -91,6 +92,7 @@ release=...
dist=...
build_path: ...
web_build_path=...
symbols_path=...
commits=auto
ignore_missing=true
```
Expand All @@ -113,6 +115,7 @@ ignore_missing=true
| dist | The dist/build number for source maps, it should match the dist set by the SDK | the number after the '+' char from 'version' pubspec (string) | no | SENTRY_DIST |
| build_path | The build folder of debug files for upload | `build` (string) | no | - |
| web_build_path | The web build folder of debug files for upload relative to build_path | `web` (string) | no | - |
| symbols_path | The directory containing debug symbols (i.e. the `--split-debug-info=` parameter value you pass to `flutter build`) | `.` (string) | no | - |
| commits | Release commits integration | auto (string) | no | - |
| ignore_missing | Ignore missing commits previously used in the release | false (boolean) | no | - |
| bin_dir | The folder where the plugin downloads the sentry-cli binary | .dart_tool/pub/bin/sentry_dart_plugin (string) | no | - |
Expand Down
3 changes: 3 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ sentry:
# default 'web'
#web_build_path: ...

# default '.'
#symbols_path: ...

# default to name@version from pubspec
#release: ...
```
50 changes: 47 additions & 3 deletions lib/sentry_dart_plugin.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:convert';

import 'package:file/file.dart';
import 'package:process/process.dart';
import 'package:sentry_dart_plugin/src/utils/extensions.dart';

import 'src/configuration.dart';
import 'src/utils/injector.dart';
Expand Down Expand Up @@ -75,15 +77,57 @@ class SentryDartPlugin {
Log.info('includeSources is disabled, not uploading sources.');
}

params.add(_configuration.buildFilesFolder);

_addWait(params);

await _executeAndLog('Failed to upload symbols', params);
final buildDirs = _enumerateBuildDirectories();
final fs = injector.get<FileSystem>();
await for (final path in buildDirs) {
if (await fs.directory(path).exists()) {
await _executeAndLog('Failed to upload symbols', [...params, path]);
}
}

if (_configuration.symbolsFolder.isNotEmpty) {
final symbolsRootDir = fs.directory(_configuration.symbolsFolder);
if (await symbolsRootDir.exists()) {
final symbolFileRegexp = RegExp(r'[/\\]app[^/\\]+.*\.(dSYM|symbols)$');
await for (final entry in symbolsRootDir.find(symbolFileRegexp)) {
await _executeAndLog(
'Failed to upload symbols', [...params, entry.path]);
}
}
}

Log.taskCompleted(taskName);
}

Stream<String> _enumerateBuildDirectories() async* {
final buildDir = _configuration.buildFilesFolder;

// Android
yield '$buildDir/app/outputs';
yield '$buildDir/app/intermediates';

// Windows
for (final subdir in ['', '/x64', '/arm64']) {
yield '$buildDir/windows$subdir/runner/Release';
}

// Linux
for (final subdir in ['/x64', '/arm64']) {
yield '$buildDir/linux$subdir/release/bundle';
}

// macOS
// TODO

// iOS
// TODO

// web
// TODO
}

List<String> _releasesCliParams() {
final params = <String>[];
_setUrlAndTokenAndLog(params);
Expand Down
4 changes: 4 additions & 0 deletions lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class Configuration {
/// the Web Build folder, defaults to `web`
late String webBuildFilesFolder;

/// The directory passed to `--split-debug-info`, defaults to '.'
late String symbolsFolder;

/// The URL prefix, defaults to null
late String? urlPrefix;

Expand Down Expand Up @@ -146,6 +149,7 @@ class Configuration {
// but can be customized so making it flexible.
final webBuildPath = configValues.webBuildPath ?? 'web';
webBuildFilesFolder = _fs.path.join(buildFilesFolder, webBuildPath);
symbolsFolder = configValues.symbolsPath ?? '.';

project = configValues.project; // or env. var. SENTRY_PROJECT
org = configValues.org; // or env. var. SENTRY_ORG
Expand Down
5 changes: 5 additions & 0 deletions lib/src/configuration_values.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ConfigurationValues {
final String? dist;
final String? buildPath;
final String? webBuildPath;
final String? symbolsPath;
final String? commits;
final bool? ignoreMissing;
final String? binDir;
Expand All @@ -43,6 +44,7 @@ class ConfigurationValues {
this.dist,
this.buildPath,
this.webBuildPath,
this.symbolsPath,
this.commits,
this.ignoreMissing,
this.binDir,
Expand Down Expand Up @@ -94,6 +96,7 @@ class ConfigurationValues {
dist: sentryArguments['dist'],
buildPath: sentryArguments['build_path'],
webBuildPath: sentryArguments['web_build_path'],
symbolsPath: sentryArguments['symbols_path'],
commits: sentryArguments['commits'],
ignoreMissing: boolFromString(sentryArguments['ignore_missing']),
binDir: sentryArguments['bin_dir'],
Expand Down Expand Up @@ -127,6 +130,7 @@ class ConfigurationValues {
dist: configReader.getString('dist'),
buildPath: configReader.getString('build_path'),
webBuildPath: configReader.getString('web_build_path'),
symbolsPath: configReader.getString('symbols_path'),
commits: configReader.getString('commits'),
ignoreMissing: configReader.getBool('ignore_missing'),
binDir: configReader.getString('bin_dir'),
Expand Down Expand Up @@ -180,6 +184,7 @@ class ConfigurationValues {
dist: platformEnv.dist ?? args.dist ?? file.dist,
buildPath: args.buildPath ?? file.buildPath,
webBuildPath: args.webBuildPath ?? file.webBuildPath,
symbolsPath: args.symbolsPath ?? file.symbolsPath,
commits: args.commits ?? file.commits,
ignoreMissing: args.ignoreMissing ?? file.ignoreMissing,
binDir: args.binDir ?? file.binDir,
Expand Down
12 changes: 12 additions & 0 deletions lib/src/utils/extensions.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import 'package:file/file.dart';

/// Checks if the given String == null
extension StringValidations on String? {
bool get isNull => this == null;
}

extension DirectorySearch on Directory {
Stream<FileSystemEntity> find(RegExp regexp) async* {
await for (final entity in list(recursive: true)) {
if (regexp.hasMatch(entity.path)) {
yield entity;
}
}
}
}
5 changes: 5 additions & 0 deletions test/configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void main() {
dist: 'dist-args-config',
buildPath: 'build_path-args-config',
webBuildPath: 'web_build_path-args-config',
symbolsPath: 'symbols_path-args-config',
commits: 'commits-args-config',
ignoreMissing: true,
binDir: 'binDir-args-config',
Expand All @@ -93,6 +94,7 @@ void main() {
dist: 'dist-file-config',
buildPath: 'build_path-file-config',
webBuildPath: 'web_build_path-file-config',
symbolsPath: 'symbols_path-args-config',
commits: 'commits-file-config',
ignoreMissing: false,
binDir: 'binDir-file-config',
Expand Down Expand Up @@ -122,6 +124,7 @@ void main() {
expect(sut.release, 'release-args-config');
expect(sut.dist, 'dist-args-config');
expect(sut.buildFilesFolder, 'build_path-args-config');
expect(sut.symbolsFolder, 'symbols_path-args-config');
expect(
sut.webBuildFilesFolder,
fixture.fs.path.join(
Expand Down Expand Up @@ -157,6 +160,7 @@ void main() {
dist: 'dist-file-config',
buildPath: 'build_path-file-config',
webBuildPath: 'web_build_path-file-config',
symbolsPath: 'symbols_path-args-config',
commits: 'commits-file-config',
ignoreMissing: true,
binDir: 'binDir-file-config',
Expand Down Expand Up @@ -187,6 +191,7 @@ void main() {
expect(sut.release, 'release-file-config');
expect(sut.dist, 'dist-file-config');
expect(sut.buildFilesFolder, 'build_path-file-config');
expect(sut.symbolsFolder, 'symbols_path-args-config');
expect(
sut.webBuildFilesFolder,
fixture.fs.path
Expand Down
10 changes: 8 additions & 2 deletions test/configureation_values_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void main() {
"--sentry-define=dist=fixture-dist",
"--sentry-define=build_path=fixture-build_path",
"--sentry-define=web_build_path=fixture-web_build_path",
"--sentry-define=symbols_path=fixture-symbols_path",
"--sentry-define=commits=fixture-commits",
"--sentry-define=ignore_missing=true",
"--sentry-define=bin_dir=fixture-bin_dir",
Expand All @@ -51,6 +52,7 @@ void main() {
expect(sut.dist, 'fixture-dist');
expect(sut.buildPath, 'fixture-build_path');
expect(sut.webBuildPath, 'fixture-web_build_path');
expect(sut.symbolsPath, 'fixture-symbols_path');
expect(sut.commits, 'fixture-commits');
expect(sut.ignoreMissing, true);
expect(sut.binDir, 'fixture-bin_dir');
Expand Down Expand Up @@ -81,7 +83,7 @@ void main() {
test('from config reader as pubspec', () {
final sentryPubspec = '''
version: fixture-sentry-version
name: fixture-sentry-name
name: fixture-sentry-name
upload_debug_symbols: true
upload_source_maps: true
upload_sources: true
Expand All @@ -92,6 +94,7 @@ void main() {
dist: fixture-dist
build_path: fixture-build_path
web_build_path: fixture-web_build_path
symbols_path: fixture-symbols_path
commits: fixture-commits
ignore_missing: true
bin_dir: fixture-bin_dir
Expand Down Expand Up @@ -133,6 +136,7 @@ void main() {
expect(sut.dist, 'fixture-dist');
expect(sut.buildPath, 'fixture-build_path');
expect(sut.webBuildPath, 'fixture-web_build_path');
expect(sut.symbolsPath, 'fixture-symbols_path');
expect(sut.commits, 'fixture-commits');
expect(sut.ignoreMissing, true);
expect(sut.binDir, 'fixture-bin_dir');
Expand All @@ -142,7 +146,7 @@ void main() {
test('from config reader as properties', () {
final sentryProperties = '''
version=fixture-sentry-version
name=fixture-sentry-name
name=fixture-sentry-name
upload_debug_symbols=true
upload_source_maps=true
upload_sources=true
Expand All @@ -153,6 +157,7 @@ void main() {
dist=fixture-dist
build_path=fixture-build_path
web_build_path=fixture-web_build_path
symbols_path: fixture-symbols_path
commits=fixture-commits
ignore_missing=true
bin_dir=fixture-bin_dir
Expand Down Expand Up @@ -194,6 +199,7 @@ void main() {
expect(sut.dist, 'fixture-dist');
expect(sut.buildPath, 'fixture-build_path');
expect(sut.webBuildPath, 'fixture-web_build_path');
expect(sut.symbolsPath, 'fixture-symbols_path');
expect(sut.commits, 'fixture-commits');
expect(sut.ignoreMissing, true);
expect(sut.binDir, 'fixture-bin_dir');
Expand Down
12 changes: 6 additions & 6 deletions test/plugin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void main() {
pm = MockProcessManager();
injector.registerSingleton<ProcessManager>(() => pm, override: true);
fs = MemoryFileSystem.test();
fs.currentDirectory = fs.directory(buildDir)..createSync();
fs.directory('$buildDir/app/outputs').createSync(recursive: true);
injector.registerSingleton<FileSystem>(() => fs, override: true);
injector.registerSingleton<CLISetup>(() => MockCLI(), override: true);
configWriter = ConfigWriter(fs, name);
Expand Down Expand Up @@ -82,7 +82,7 @@ void main() {

final args = '$commonArgs --log-level debug';
expect(commandLog, [
'$cli $args debug-files upload $orgAndProject --include-sources $buildDir',
'$cli $args debug-files upload $orgAndProject --include-sources $buildDir/app/outputs',
'$cli $args releases $orgAndProject new $release',
'$cli $args releases $orgAndProject files $release upload-sourcemaps $buildDir/web --ext map --ext js',
'$cli $args releases $orgAndProject files $release upload-sourcemaps $buildDir --ext dart',
Expand All @@ -108,7 +108,7 @@ void main() {
const release = '$name@$version';

expect(commandLog, [
'$cli $commonArgs debug-files upload $orgAndProject $buildDir',
'$cli $commonArgs debug-files upload $orgAndProject $buildDir/app/outputs',
'$cli $commonArgs releases $orgAndProject new $release',
'$cli $commonArgs releases $orgAndProject set-commits $release --auto',
'$cli $commonArgs releases $orgAndProject finalize $release'
Expand All @@ -129,7 +129,7 @@ void main() {
const release = '$name@$version';

expect(commandLog, [
'$customCliPath $commonArgs debug-files upload $orgAndProject $buildDir',
'$customCliPath $commonArgs debug-files upload $orgAndProject $buildDir/app/outputs',
'$customCliPath $commonArgs releases $orgAndProject new $release',
'$customCliPath $commonArgs releases $orgAndProject set-commits $release --auto',
'$customCliPath $commonArgs releases $orgAndProject finalize $release'
Expand Down Expand Up @@ -157,7 +157,7 @@ void main() {
const release = '$name@$version';

expect(commandLog, [
'$cli $commonArgs debug-files upload $orgAndProject $buildDir',
'$cli $commonArgs debug-files upload $orgAndProject $buildDir/app/outputs',
'$cli $commonArgs releases $orgAndProject new $release',
'$cli $commonArgs releases $orgAndProject set-commits $release $expectedArgs',
'$cli $commonArgs releases $orgAndProject finalize $release'
Expand All @@ -172,7 +172,7 @@ void main() {
const release = '$name@$version';

expect(commandLog, [
'$cli $commonArgs debug-files upload $orgAndProject $buildDir',
'$cli $commonArgs debug-files upload $orgAndProject $buildDir/app/outputs',
'$cli $commonArgs releases $orgAndProject new $release',
'$cli $commonArgs releases $orgAndProject finalize $release'
]);
Expand Down

0 comments on commit 41ed7e8

Please sign in to comment.