Skip to content

Commit

Permalink
Convert 'p' prefixes to 'path' in tool/ (#3472)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored Jul 26, 2023
1 parent d44c805 commit 1cf8870
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 85 deletions.
16 changes: 8 additions & 8 deletions tool/mustachio/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart'
show AnalysisContextCollectionImpl;
import 'package:dartdoc/src/mustachio/annotations.dart';
import 'package:path/path.dart' as p;
import 'package:path/path.dart' as path;

import 'codegen_aot_compiler.dart';
import 'codegen_runtime_renderer.dart';

void main() async {
await build(p.join('lib', 'src', 'generator', 'templates.dart'));
await build(path.join('lib', 'src', 'generator', 'templates.dart'));
await build(
p.join('test', 'mustachio', 'foo.dart'),
path.join('test', 'mustachio', 'foo.dart'),
rendererClassesArePublic: true,
);
}
Expand All @@ -36,7 +36,7 @@ Future<void> build(
);
var analysisContext = contextCollection.contextFor(root);
final libraryResult = await analysisContext.currentSession
.getResolvedLibrary(p.join(root, sourcePath));
.getResolvedLibrary(path.join(root, sourcePath));
if (libraryResult is! ResolvedLibraryResult) {
throw StateError(
'Expected library result to be ResolvedLibraryResult, but is '
Expand All @@ -59,8 +59,8 @@ Future<void> build(
typeSystem,
rendererClassesArePublic: rendererClassesArePublic,
);
await File(p.join(
root, '${p.withoutExtension(sourcePath)}.runtime_renderers.dart'))
var basePath = path.withoutExtension(sourcePath);
await File(path.join(root, '$basePath.runtime_renderers.dart'))
.writeAsString(runtimeRenderersContents);

for (var format in templateFormats) {
Expand All @@ -79,8 +79,8 @@ Future<void> build(
aotRenderersContents = '';
}

var basePath = p.withoutExtension(sourcePath);
await File(p.join(root, format.aotLibraryPath(basePath)))
var basePath = path.withoutExtension(sourcePath);
await File(path.join(root, format.aotLibraryPath(basePath)))
.writeAsString(aotRenderersContents);
}
}
Expand Down
28 changes: 14 additions & 14 deletions tool/mustachio/codegen_aot_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'package:dartdoc/src/mustachio/parser.dart';
import 'package:dartdoc/src/mustachio/renderer_base.dart';
import 'package:dartdoc/src/type_utils.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:path/path.dart' as path;

/// Compiles all templates specified in [specs] into a Dart library containing
/// a renderer for each template.
Expand Down Expand Up @@ -111,8 +111,8 @@ Future<Map<_AotCompiler, String>> _deduplicateRenderers(
.add(compiler);
}
var partialsToRemove = <_AotCompiler>{};
for (var path in compilersPerPartial.keys) {
var compilers = compilersPerPartial[path]!;
for (var filePath in compilersPerPartial.keys) {
var compilers = compilersPerPartial[filePath]!;
if (compilers.length < 2) {
// Nothing to deduplicate.
continue;
Expand All @@ -138,11 +138,11 @@ Future<Map<_AotCompiler, String>> _deduplicateRenderers(
// Each of the render functions generated by a compiler for this asset can
// be replaced by a more generic renderer which accepts the LUB types. The
// body of each replaced renderer can perform a simple redirect.
var rendererName = path.replaceAll('.', '_').replaceAll('/', '_');
var rendererName = filePath.replaceAll('.', '_').replaceAll('/', '_');
var lubCompiler = _AotCompiler._(
contextStackTypes.first,
'_deduplicated_$rendererName',
path,
filePath,
firstCompiler._syntaxTree,
firstCompiler._buildData,
contextStack: [
Expand All @@ -158,7 +158,7 @@ Future<Map<_AotCompiler, String>> _deduplicateRenderers(
// likely the properties accessed in the partial are not all declared on
// the LUB type.
var names = compilers.map((c) => c._rendererName);
print('Could not deduplicate $path ${names.join(', ')}');
print('Could not deduplicate $filePath ${names.join(', ')}');
continue;
}

Expand Down Expand Up @@ -281,7 +281,7 @@ class _AotCompiler {
List<_VariableLookup> contextStack = const [],
}) async {
var template =
await File(p.join(buildData._root, templatePath)).readAsString();
await File(path.join(buildData._root, templatePath)).readAsString();
var syntaxTree = MustachioParser(template, templatePath).parse();
return _AotCompiler._(
contextType, rendererName, templatePath, syntaxTree, buildData,
Expand Down Expand Up @@ -381,8 +381,8 @@ class _AotCompiler {
var libraryElement = element.library!;
var libraryUri = libraryElement.source.uri;
if (libraryUri.scheme == 'file') {
return p.relative(libraryUri.path,
from: p.absolute(p.dirname(_buildData._sourcePath)));
return path.relative(libraryUri.path,
from: path.absolute(path.dirname(_buildData._sourcePath)));
}
return libraryUri.toString();
}
Expand Down Expand Up @@ -449,11 +449,11 @@ class _BlockCompiler {
/// Compiles [node] into a renderer's Dart source.
Future<void> _compilePartial(Partial node, Set<String> referenceUris) async {
var extension = format == TemplateFormat.html ? 'html' : 'md';
var path = node.key.split('/');
var fileName = path.removeLast();
path.add('_$fileName.$extension');
var partialPath =
p.join(p.dirname(_templateCompiler._templatePath), path.join('/'));
var filePath = node.key.split('/');
var fileName = filePath.removeLast();
filePath.add('_$fileName.$extension');
var partialPath = path.join(
path.dirname(_templateCompiler._templatePath), filePath.join('/'));
var partialCompiler = _templateCompiler._partialCompilers
.firstWhereOrNull((p) => p._templatePath == partialPath);
if (partialCompiler == null) {
Expand Down
4 changes: 2 additions & 2 deletions tool/mustachio/codegen_runtime_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:analyzer/dart/element/type_system.dart';
import 'package:dart_style/dart_style.dart';
import 'package:dartdoc/src/mustachio/annotations.dart';
import 'package:dartdoc/src/type_utils.dart';
import 'package:path/path.dart' as p;
import 'package:path/path.dart' as path;

import 'utilities.dart';

Expand Down Expand Up @@ -97,7 +97,7 @@ import 'package:dartdoc/src/model/model_object_builder.dart';
import 'package:dartdoc/src/mustachio/parser.dart';
import 'package:dartdoc/src/mustachio/renderer_base.dart';
import 'package:dartdoc/src/warnings.dart';
import '${p.basename(_sourceUri.path)}';
import '${path.basename(_sourceUri.path)}';
''');

specs.forEach(_addTypesForRendererSpec);
Expand Down
32 changes: 16 additions & 16 deletions tool/src/flutter_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,44 @@ import 'dart:async';
import 'dart:io';

import 'package:dartdoc/src/io_utils.dart';
import 'package:path/path.dart' as p;
import 'package:path/path.dart' as path;

import 'io_utils.dart' as io_utils;
import 'subprocess_launcher.dart';

/// A class representing a Flutter SDK repository.
class FlutterRepo {
final String path;
final String repoPath;
final Map<String, String> env;
final String flutterCmd = p.join('bin', 'flutter');
final String flutterCmd = path.join('bin', 'flutter');

final String cacheDart;
final SubprocessLauncher launcher;

FlutterRepo._(this.path, this.env, this.cacheDart, this.launcher);
FlutterRepo._(this.repoPath, this.env, this.cacheDart, this.launcher);

Future<void> init() async {
Directory(path).createSync(recursive: true);
Directory(repoPath).createSync(recursive: true);
await launcher.runStreamed(
'git', ['clone', 'https://github.com/flutter/flutter.git', '.'],
workingDirectory: path);
workingDirectory: repoPath);
await launcher.runStreamed(
flutterCmd,
['--version'],
workingDirectory: path,
workingDirectory: repoPath,
);
await launcher.runStreamed(
flutterCmd,
['update-packages'],
workingDirectory: path,
workingDirectory: repoPath,
);
}

factory FlutterRepo.fromPath(String flutterPath, Map<String, String> env,
[String? label]) {
var cacheDart =
p.join(flutterPath, 'bin', 'cache', 'dart-sdk', 'bin', 'dart');
var flutterBinPath = p.join(p.canonicalize(flutterPath), 'bin');
path.join(flutterPath, 'bin', 'cache', 'dart-sdk', 'bin', 'dart');
var flutterBinPath = path.join(path.canonicalize(flutterPath), 'bin');
var existingPathVariable = env['PATH'] ?? Platform.environment['PATH'];
env['PATH'] = '$flutterBinPath:$existingPathVariable';
env['FLUTTER_ROOT'] = flutterPath;
Expand All @@ -56,20 +56,20 @@ class FlutterRepo {
static Future<FlutterRepo> copyFromExistingFlutterRepo(
FlutterRepo originalRepo, String flutterPath, Map<String, String> env,
[String? label]) async {
io_utils.copy(Directory(originalRepo.path), Directory(flutterPath));
io_utils.copy(Directory(originalRepo.repoPath), Directory(flutterPath));
return FlutterRepo.fromPath(flutterPath, env, label);
}

/// Doesn't actually copy the existing repo; use for read-only operations
/// only.
static Future<FlutterRepo> fromExistingFlutterRepo(FlutterRepo originalRepo,
[String? label]) async {
return FlutterRepo.fromPath(originalRepo.path, {}, label);
return FlutterRepo.fromPath(originalRepo.repoPath, {}, label);
}
}

Directory cleanFlutterDir = Directory(
p.join(p.context.resolveTildePath('~/.dartdoc_grinder'), 'cleanFlutter'));
Directory cleanFlutterDir = Directory(path.join(
path.context.resolveTildePath('~/.dartdoc_grinder'), 'cleanFlutter'));

/// Global so that the lock is retained for the life of the process.
Future<void>? _lockFuture;
Expand All @@ -93,11 +93,11 @@ Future<FlutterRepo> get cleanFlutterRepo async {
// Figure out where the repository is supposed to be and lock updates for it.
await cleanFlutterDir.parent.create(recursive: true);
assert(_lockFuture == null);
_lockFuture = File(p.join(cleanFlutterDir.parent.path, 'lock'))
_lockFuture = File(path.join(cleanFlutterDir.parent.path, 'lock'))
.openSync(mode: FileMode.write)
.lock();
await _lockFuture;
var lastSynced = File(p.join(cleanFlutterDir.parent.path, 'lastSynced'));
var lastSynced = File(path.join(cleanFlutterDir.parent.path, 'lastSynced'));
var newRepo = FlutterRepo.fromPath(cleanFlutterDir.path, {}, 'clean');

// We have a repository, but is it up to date?
Expand Down
Loading

0 comments on commit 1cf8870

Please sign in to comment.