blob: de34f0e328695864433a6202d30f7ab253530e9b [file] [log] [blame]
Leopold Schabel18b4d652020-12-14 18:27:07 +01001// Copyright 2020 The Monogon Project Authors.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
Serge Bazanski216fe7b2021-05-21 18:36:16 +020017// localconfig modifies the project's IntelliJ config to include project-specific
18// settings. This is usually done by checking in the .idea directory, but we do not
19// want to do this: it conflicts with the Bazel plugin's way of conducting its
20// workspace business, lacks backwards compatibility, and is a common source of
21// spurious Git diffs, especially when the IDE/JDK/random plugins are updated and
22// team members run different versions.
Leopold Schabel18b4d652020-12-14 18:27:07 +010023//
Serge Bazanski216fe7b2021-05-21 18:36:16 +020024// Instead, we use the officially supported way of shipping IntelliJ Bazel project
25// configs - a .bazelproject file that can be imported using the Bazel project
26// import wizard, with local configs. We then use this tool to mangle the local
27// configs to add additional custom configuration beyond run configurations. This
28// avoids merge conflicts and allows us to intelligently handle schema changes.
Leopold Schabel18b4d652020-12-14 18:27:07 +010029package main
30
31import (
32 "log"
33 "os"
34 "path"
35
Serge Bazanski31370b02021-01-07 16:31:14 +010036 "source.monogon.dev/intellij/localconfig/watchers"
Leopold Schabel18b4d652020-12-14 18:27:07 +010037)
38
39func main() {
40 if len(os.Args) != 2 {
41 log.Fatal("usage: localconfig <project dir>")
42 }
43
44 projectDir := os.Args[1]
45 if _, err := os.Stat(path.Join(projectDir, ".ijwb")); err != nil {
46 log.Fatalf("invalid project dir: %v", err)
47 }
48
49 if err := watchers.RewriteConfig(projectDir); err != nil {
50 log.Fatal(err)
51 }
52}